[Python-checkins] r72545 - in python/branches/py3k: Lib/distutils/tests/test_config.py Lib/distutils/tests/test_dist.py Lib/distutils/tests/test_util.py

tarek.ziade python-checkins at python.org
Sun May 10 14:20:45 CEST 2009


Author: tarek.ziade
Date: Sun May 10 14:20:44 2009
New Revision: 72545
Log:
Merged revisions 72543 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk
........
 r72543 | tarek.ziade | 2009年05月10日 14:17:30 +0200 (2009年5月10日) | 1 line
 
 now using EnvironGuard everywhere
........
Modified:
 python/branches/py3k/ (props changed)
 python/branches/py3k/Lib/distutils/tests/test_config.py
 python/branches/py3k/Lib/distutils/tests/test_dist.py
 python/branches/py3k/Lib/distutils/tests/test_util.py
Modified: python/branches/py3k/Lib/distutils/tests/test_config.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_config.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_config.py	Sun May 10 14:20:44 2009
@@ -48,18 +48,14 @@
 
 class PyPIRCCommandTestCase(support.TempdirManager,
 support.LoggingSilencer,
+ support.EnvironGuard,
 unittest.TestCase):
 
 def setUp(self):
 """Patches the environment."""
 super(PyPIRCCommandTestCase, self).setUp()
-
- if 'HOME' in os.environ:
- self._old_home = os.environ['HOME']
- else:
- self._old_home = None
 self.tmp_dir = self.mkdtemp()
- os.environ['HOME'] = self.tmp_dir
+ self.environ['HOME'] = self.tmp_dir
 self.rc = os.path.join(self.tmp_dir, '.pypirc')
 self.dist = Distribution()
 
@@ -75,10 +71,6 @@
 
 def tearDown(self):
 """Removes the patch."""
- if self._old_home is None:
- del os.environ['HOME']
- else:
- os.environ['HOME'] = self._old_home
 set_threshold(self.old_threshold)
 super(PyPIRCCommandTestCase, self).tearDown()
 
@@ -88,12 +80,7 @@
 # 2. handle the old format
 
 # new format
- f = open(self.rc, 'w')
- try:
- f.write(PYPIRC)
- finally:
- f.close()
-
+ self.write_file(self.rc, PYPIRC)
 cmd = self._cmd(self.dist)
 config = cmd._read_pypirc()
 
@@ -104,10 +91,7 @@
 self.assertEquals(config, waited)
 
 # old format
- f = open(self.rc, 'w')
- f.write(PYPIRC_OLD)
- f.close()
-
+ self.write_file(self.rc, PYPIRC_OLD)
 config = cmd._read_pypirc()
 config = list(sorted(config.items()))
 waited = [('password', 'secret'), ('realm', 'pypi'),
@@ -116,19 +100,14 @@
 self.assertEquals(config, waited)
 
 def test_server_empty_registration(self):
-
 cmd = self._cmd(self.dist)
 rc = cmd._get_rc_file()
 self.assert_(not os.path.exists(rc))
-
 cmd._store_pypirc('tarek', 'xxx')
-
 self.assert_(os.path.exists(rc))
 content = open(rc).read()
-
 self.assertEquals(content, WANTED)
 
-
 def test_suite():
 return unittest.makeSuite(PyPIRCCommandTestCase)
 
Modified: python/branches/py3k/Lib/distutils/tests/test_dist.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_dist.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_dist.py	Sun May 10 14:20:44 2009
@@ -38,11 +38,13 @@
 class DistributionTestCase(unittest.TestCase):
 
 def setUp(self):
+ super(DistributionTestCase, self).setUp()
 self.argv = sys.argv[:]
 del sys.argv[1:]
 
 def tearDown(self):
 sys.argv[:] = self.argv
+ super(DistributionTestCase, self).tearDown()
 
 def create_distribution(self, configfiles=()):
 d = TestDistribution()
@@ -121,7 +123,8 @@
 
 self.assertEquals(len(warns), 0)
 
-class MetadataTestCase(support.TempdirManager, unittest.TestCase):
+class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
+ unittest.TestCase):
 
 def test_simple_metadata(self):
 attrs = {"name": "package",
@@ -208,13 +211,6 @@
 def test_custom_pydistutils(self):
 # fixes #2166
 # make sure pydistutils.cfg is found
- old = {}
- for env in ('HOME', 'HOMEPATH', 'HOMEDRIVE'):
- value = os.environ.get(env)
- old[env] = value
- if value is not None:
- del os.environ[env]
-
 if os.name == 'posix':
 user_filename = ".pydistutils.cfg"
 else:
@@ -231,22 +227,18 @@
 
 # linux-style
 if sys.platform in ('linux', 'darwin'):
- os.environ['HOME'] = temp_dir
+ self.environ['HOME'] = temp_dir
 files = dist.find_config_files()
 self.assert_(user_filename in files)
 
 # win32-style
 if sys.platform == 'win32':
 # home drive should be found
- os.environ['HOME'] = temp_dir
+ self.environ['HOME'] = temp_dir
 files = dist.find_config_files()
 self.assert_(user_filename in files,
 '%r not found in %r' % (user_filename, files))
 finally:
- for key, value in old.items():
- if value is None:
- continue
- os.environ[key] = value
 os.remove(user_filename)
 
 def test_suite():
Modified: python/branches/py3k/Lib/distutils/tests/test_util.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_util.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_util.py	Sun May 10 14:20:44 2009
@@ -8,28 +8,23 @@
 from copy import copy
 
 from distutils.errors import DistutilsPlatformError
-
-from distutils.util import get_platform
-from distutils.util import convert_path
-from distutils.util import change_root
-from distutils.util import check_environ
-from distutils.util import split_quoted
-from distutils.util import strtobool
-from distutils.util import rfc822_escape
-
+from distutils.util import (get_platform, convert_path, change_root,
+ check_environ, split_quoted, strtobool,
+ rfc822_escape)
 from distutils import util # used to patch _environ_checked
 from distutils.sysconfig import get_config_vars
 from distutils import sysconfig
+from distutils.tests import support
 
-class utilTestCase(unittest.TestCase):
+class UtilTestCase(support.EnvironGuard, unittest.TestCase):
 
 def setUp(self):
+ super(UtilTestCase, self).setUp()
 # saving the environment
 self.name = os.name
 self.platform = sys.platform
 self.version = sys.version
 self.sep = os.sep
- self.environ = dict(os.environ)
 self.join = os.path.join
 self.isabs = os.path.isabs
 self.splitdrive = os.path.splitdrive
@@ -51,10 +46,6 @@
 sys.platform = self.platform
 sys.version = self.version
 os.sep = self.sep
- for k, v in self.environ.items():
- os.environ[k] = v
- for k in set(os.environ) - set(self.environ):
- del os.environ[k]
 os.path.join = self.join
 os.path.isabs = self.isabs
 os.path.splitdrive = self.splitdrive
@@ -63,6 +54,7 @@
 else:
 del os.uname
 sysconfig._config_vars = copy(self._config_vars)
+ super(UtilTestCase, self).tearDown()
 
 def _set_uname(self, uname):
 self._uname = uname
@@ -102,7 +94,7 @@
 ('Darwin Kernel Version 8.11.1: '
 'Wed Oct 10 18:23:28 PDT 2007; '
 'root:xnu-792.25.20~1/RELEASE_I386'), 'i386'))
- os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
+ self.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
 
 get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
 '-fwrapv -O3 -Wall -Wstrict-prototypes')
@@ -110,7 +102,7 @@
 self.assertEquals(get_platform(), 'macosx-10.3-i386')
 
 # macbook with fat binaries (fat, universal or fat64)
- os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
+ self.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
 get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
 '/Developer/SDKs/MacOSX10.4u.sdk '
 '-fno-strict-aliasing -fno-common '
@@ -214,21 +206,14 @@
 
 # posix without HOME
 if os.name == 'posix': # this test won't run on windows
- old_home = os.environ.get('HOME')
- try:
- check_environ()
- import pwd
- self.assertEquals(os.environ['HOME'],
- pwd.getpwuid(os.getuid())[5])
- finally:
- if old_home is not None:
- os.environ['HOME'] = old_home
- else:
- del os.environ['HOME']
+ check_environ()
+ import pwd
+ self.assertEquals(self.environ['HOME'],
+ pwd.getpwuid(os.getuid())[5])
 else:
 check_environ()
 
- self.assertEquals(os.environ['PLAT'], get_platform())
+ self.assertEquals(self.environ['PLAT'], get_platform())
 self.assertEquals(util._environ_checked, 1)
 
 def test_split_quoted(self):
@@ -253,7 +238,7 @@
 self.assertEquals(res, wanted)
 
 def test_suite():
- return unittest.makeSuite(utilTestCase)
+ return unittest.makeSuite(UtilTestCase)
 
 if __name__ == "__main__":
 unittest.main(defaultTest="test_suite")


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /