mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	 b344dd06c8
			
		
	
	
		b344dd06c8
		
	
	
	
	
		
			
			svn+ssh://pythondev@svn.python.org/python/branches/py3k The missing NEWS entries correspond to changes that were made before 3.1.3, but I think it’s not usual to edit entries of released versions, so I put them at the top. ........ r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines Make sure each test can be run standalone (./python Lib/distutils/tests/x.py) ........ r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines Prevent ResourceWarnings in test_gettext ........ r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines Add missing NEWS entry for a fix committed by Senthil. All recent modifications to distutils should now be covered in NEWS. ........ r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines This was actually fixed for the previous alpha. ........ r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines Improve trace documentation (#9264). Patch by Eli Bendersky. ........ r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines Use nested method directives, rewrap long lines, fix whitespace. ........ r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines Fix typo in superclass method name ........
		
			
				
	
	
		
			120 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| """Tests for distutils.pypirc.pypirc."""
 | |
| import sys
 | |
| import os
 | |
| import unittest
 | |
| import tempfile
 | |
| 
 | |
| from distutils.core import PyPIRCCommand
 | |
| from distutils.core import Distribution
 | |
| from distutils.log import set_threshold
 | |
| from distutils.log import WARN
 | |
| 
 | |
| from distutils.tests import support
 | |
| from test.support import run_unittest
 | |
| 
 | |
| PYPIRC = """\
 | |
| [distutils]
 | |
| 
 | |
| index-servers =
 | |
|     server1
 | |
|     server2
 | |
| 
 | |
| [server1]
 | |
| username:me
 | |
| password:secret
 | |
| 
 | |
| [server2]
 | |
| username:meagain
 | |
| password: secret
 | |
| realm:acme
 | |
| repository:http://another.pypi/
 | |
| """
 | |
| 
 | |
| PYPIRC_OLD = """\
 | |
| [server-login]
 | |
| username:tarek
 | |
| password:secret
 | |
| """
 | |
| 
 | |
| WANTED = """\
 | |
| [distutils]
 | |
| index-servers =
 | |
|     pypi
 | |
| 
 | |
| [pypi]
 | |
| username:tarek
 | |
| password:xxx
 | |
| """
 | |
| 
 | |
| 
 | |
| class PyPIRCCommandTestCase(support.TempdirManager,
 | |
|                             support.LoggingSilencer,
 | |
|                             support.EnvironGuard,
 | |
|                             unittest.TestCase):
 | |
| 
 | |
|     def setUp(self):
 | |
|         """Patches the environment."""
 | |
|         super(PyPIRCCommandTestCase, self).setUp()
 | |
|         self.tmp_dir = self.mkdtemp()
 | |
|         os.environ['HOME'] = self.tmp_dir
 | |
|         self.rc = os.path.join(self.tmp_dir, '.pypirc')
 | |
|         self.dist = Distribution()
 | |
| 
 | |
|         class command(PyPIRCCommand):
 | |
|             def __init__(self, dist):
 | |
|                 PyPIRCCommand.__init__(self, dist)
 | |
|             def initialize_options(self):
 | |
|                 pass
 | |
|             finalize_options = initialize_options
 | |
| 
 | |
|         self._cmd = command
 | |
|         self.old_threshold = set_threshold(WARN)
 | |
| 
 | |
|     def tearDown(self):
 | |
|         """Removes the patch."""
 | |
|         set_threshold(self.old_threshold)
 | |
|         super(PyPIRCCommandTestCase, self).tearDown()
 | |
| 
 | |
|     def test_server_registration(self):
 | |
|         # This test makes sure PyPIRCCommand knows how to:
 | |
|         # 1. handle several sections in .pypirc
 | |
|         # 2. handle the old format
 | |
| 
 | |
|         # new format
 | |
|         self.write_file(self.rc, PYPIRC)
 | |
|         cmd = self._cmd(self.dist)
 | |
|         config = cmd._read_pypirc()
 | |
| 
 | |
|         config = list(sorted(config.items()))
 | |
|         waited = [('password', 'secret'), ('realm', 'pypi'),
 | |
|                   ('repository', 'http://pypi.python.org/pypi'),
 | |
|                   ('server', 'server1'), ('username', 'me')]
 | |
|         self.assertEqual(config, waited)
 | |
| 
 | |
|         # old format
 | |
|         self.write_file(self.rc, PYPIRC_OLD)
 | |
|         config = cmd._read_pypirc()
 | |
|         config = list(sorted(config.items()))
 | |
|         waited = [('password', 'secret'), ('realm', 'pypi'),
 | |
|                   ('repository', 'http://pypi.python.org/pypi'),
 | |
|                   ('server', 'server-login'), ('username', 'tarek')]
 | |
|         self.assertEqual(config, waited)
 | |
| 
 | |
|     def test_server_empty_registration(self):
 | |
|         cmd = self._cmd(self.dist)
 | |
|         rc = cmd._get_rc_file()
 | |
|         self.assertTrue(not os.path.exists(rc))
 | |
|         cmd._store_pypirc('tarek', 'xxx')
 | |
|         self.assertTrue(os.path.exists(rc))
 | |
|         f = open(rc)
 | |
|         try:
 | |
|             content = f.read()
 | |
|             self.assertEqual(content, WANTED)
 | |
|         finally:
 | |
|             f.close()
 | |
| 
 | |
| def test_suite():
 | |
|     return unittest.makeSuite(PyPIRCCommandTestCase)
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     run_unittest(test_suite())
 |