mirror of
https://github.com/python/cpython.git
synced 2025-08-16 14:50:43 +00:00
now using EnvironGuard everywhere
This commit is contained in:
parent
d35f2a33d5
commit
450ca11a58
3 changed files with 25 additions and 71 deletions
|
@ -49,18 +49,14 @@ password:xxx
|
||||||
|
|
||||||
class PyPIRCCommandTestCase(support.TempdirManager,
|
class PyPIRCCommandTestCase(support.TempdirManager,
|
||||||
support.LoggingSilencer,
|
support.LoggingSilencer,
|
||||||
|
support.EnvironGuard,
|
||||||
unittest.TestCase):
|
unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Patches the environment."""
|
"""Patches the environment."""
|
||||||
super(PyPIRCCommandTestCase, self).setUp()
|
super(PyPIRCCommandTestCase, self).setUp()
|
||||||
|
|
||||||
if os.environ.has_key('HOME'):
|
|
||||||
self._old_home = os.environ['HOME']
|
|
||||||
else:
|
|
||||||
self._old_home = None
|
|
||||||
self.tmp_dir = self.mkdtemp()
|
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.rc = os.path.join(self.tmp_dir, '.pypirc')
|
||||||
self.dist = Distribution()
|
self.dist = Distribution()
|
||||||
|
|
||||||
|
@ -76,10 +72,6 @@ class PyPIRCCommandTestCase(support.TempdirManager,
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
"""Removes the patch."""
|
"""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)
|
set_threshold(self.old_threshold)
|
||||||
super(PyPIRCCommandTestCase, self).tearDown()
|
super(PyPIRCCommandTestCase, self).tearDown()
|
||||||
|
|
||||||
|
@ -89,12 +81,7 @@ class PyPIRCCommandTestCase(support.TempdirManager,
|
||||||
# 2. handle the old format
|
# 2. handle the old format
|
||||||
|
|
||||||
# new format
|
# new format
|
||||||
f = open(self.rc, 'w')
|
self.write_file(self.rc, PYPIRC)
|
||||||
try:
|
|
||||||
f.write(PYPIRC)
|
|
||||||
finally:
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
cmd = self._cmd(self.dist)
|
cmd = self._cmd(self.dist)
|
||||||
config = cmd._read_pypirc()
|
config = cmd._read_pypirc()
|
||||||
|
|
||||||
|
@ -106,10 +93,7 @@ class PyPIRCCommandTestCase(support.TempdirManager,
|
||||||
self.assertEquals(config, waited)
|
self.assertEquals(config, waited)
|
||||||
|
|
||||||
# old format
|
# old format
|
||||||
f = open(self.rc, 'w')
|
self.write_file(self.rc, PYPIRC_OLD)
|
||||||
f.write(PYPIRC_OLD)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
config = cmd._read_pypirc()
|
config = cmd._read_pypirc()
|
||||||
config = config.items()
|
config = config.items()
|
||||||
config.sort()
|
config.sort()
|
||||||
|
@ -119,19 +103,14 @@ class PyPIRCCommandTestCase(support.TempdirManager,
|
||||||
self.assertEquals(config, waited)
|
self.assertEquals(config, waited)
|
||||||
|
|
||||||
def test_server_empty_registration(self):
|
def test_server_empty_registration(self):
|
||||||
|
|
||||||
cmd = self._cmd(self.dist)
|
cmd = self._cmd(self.dist)
|
||||||
rc = cmd._get_rc_file()
|
rc = cmd._get_rc_file()
|
||||||
self.assert_(not os.path.exists(rc))
|
self.assert_(not os.path.exists(rc))
|
||||||
|
|
||||||
cmd._store_pypirc('tarek', 'xxx')
|
cmd._store_pypirc('tarek', 'xxx')
|
||||||
|
|
||||||
self.assert_(os.path.exists(rc))
|
self.assert_(os.path.exists(rc))
|
||||||
content = open(rc).read()
|
content = open(rc).read()
|
||||||
|
|
||||||
self.assertEquals(content, WANTED)
|
self.assertEquals(content, WANTED)
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
return unittest.makeSuite(PyPIRCCommandTestCase)
|
return unittest.makeSuite(PyPIRCCommandTestCase)
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,13 @@ class TestDistribution(distutils.dist.Distribution):
|
||||||
class DistributionTestCase(support.TempdirManager, unittest.TestCase):
|
class DistributionTestCase(support.TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
support.TempdirManager.setUp(self)
|
super(DistributionTestCase, self).setUp()
|
||||||
self.argv = sys.argv[:]
|
self.argv = sys.argv[:]
|
||||||
del sys.argv[1:]
|
del sys.argv[1:]
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
sys.argv[:] = self.argv
|
sys.argv[:] = self.argv
|
||||||
support.TempdirManager.tearDown(self)
|
super(DistributionTestCase, self).tearDown()
|
||||||
|
|
||||||
def create_distribution(self, configfiles=()):
|
def create_distribution(self, configfiles=()):
|
||||||
d = TestDistribution()
|
d = TestDistribution()
|
||||||
|
@ -151,7 +151,8 @@ class DistributionTestCase(support.TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
self.assertEquals(len(warns), 0)
|
self.assertEquals(len(warns), 0)
|
||||||
|
|
||||||
class MetadataTestCase(support.TempdirManager, unittest.TestCase):
|
class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
||||||
|
unittest.TestCase):
|
||||||
|
|
||||||
def test_simple_metadata(self):
|
def test_simple_metadata(self):
|
||||||
attrs = {"name": "package",
|
attrs = {"name": "package",
|
||||||
|
@ -238,13 +239,6 @@ class MetadataTestCase(support.TempdirManager, unittest.TestCase):
|
||||||
def test_custom_pydistutils(self):
|
def test_custom_pydistutils(self):
|
||||||
# fixes #2166
|
# fixes #2166
|
||||||
# make sure pydistutils.cfg is found
|
# 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':
|
if os.name == 'posix':
|
||||||
user_filename = ".pydistutils.cfg"
|
user_filename = ".pydistutils.cfg"
|
||||||
else:
|
else:
|
||||||
|
@ -261,22 +255,18 @@ class MetadataTestCase(support.TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
# linux-style
|
# linux-style
|
||||||
if sys.platform in ('linux', 'darwin'):
|
if sys.platform in ('linux', 'darwin'):
|
||||||
os.environ['HOME'] = temp_dir
|
self.environ['HOME'] = temp_dir
|
||||||
files = dist.find_config_files()
|
files = dist.find_config_files()
|
||||||
self.assert_(user_filename in files)
|
self.assert_(user_filename in files)
|
||||||
|
|
||||||
# win32-style
|
# win32-style
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
# home drive should be found
|
# home drive should be found
|
||||||
os.environ['HOME'] = temp_dir
|
self.environ['HOME'] = temp_dir
|
||||||
files = dist.find_config_files()
|
files = dist.find_config_files()
|
||||||
self.assert_(user_filename in files,
|
self.assert_(user_filename in files,
|
||||||
'%r not found in %r' % (user_filename, files))
|
'%r not found in %r' % (user_filename, files))
|
||||||
finally:
|
finally:
|
||||||
for key, value in old.items():
|
|
||||||
if value is None:
|
|
||||||
continue
|
|
||||||
os.environ[key] = value
|
|
||||||
os.remove(user_filename)
|
os.remove(user_filename)
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
|
|
|
@ -8,28 +8,23 @@ import unittest
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
from distutils.errors import DistutilsPlatformError
|
from distutils.errors import DistutilsPlatformError
|
||||||
|
from distutils.util import (get_platform, convert_path, change_root,
|
||||||
from distutils.util import get_platform
|
check_environ, split_quoted, strtobool,
|
||||||
from distutils.util import convert_path
|
rfc822_escape)
|
||||||
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 import util # used to patch _environ_checked
|
from distutils import util # used to patch _environ_checked
|
||||||
from distutils.sysconfig import get_config_vars
|
from distutils.sysconfig import get_config_vars
|
||||||
from distutils import sysconfig
|
from distutils import sysconfig
|
||||||
|
from distutils.tests import support
|
||||||
|
|
||||||
class utilTestCase(unittest.TestCase):
|
class UtilTestCase(support.EnvironGuard, unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(UtilTestCase, self).setUp()
|
||||||
# saving the environment
|
# saving the environment
|
||||||
self.name = os.name
|
self.name = os.name
|
||||||
self.platform = sys.platform
|
self.platform = sys.platform
|
||||||
self.version = sys.version
|
self.version = sys.version
|
||||||
self.sep = os.sep
|
self.sep = os.sep
|
||||||
self.environ = dict(os.environ)
|
|
||||||
self.join = os.path.join
|
self.join = os.path.join
|
||||||
self.isabs = os.path.isabs
|
self.isabs = os.path.isabs
|
||||||
self.splitdrive = os.path.splitdrive
|
self.splitdrive = os.path.splitdrive
|
||||||
|
@ -51,10 +46,6 @@ class utilTestCase(unittest.TestCase):
|
||||||
sys.platform = self.platform
|
sys.platform = self.platform
|
||||||
sys.version = self.version
|
sys.version = self.version
|
||||||
os.sep = self.sep
|
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.join = self.join
|
||||||
os.path.isabs = self.isabs
|
os.path.isabs = self.isabs
|
||||||
os.path.splitdrive = self.splitdrive
|
os.path.splitdrive = self.splitdrive
|
||||||
|
@ -63,6 +54,7 @@ class utilTestCase(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
del os.uname
|
del os.uname
|
||||||
sysconfig._config_vars = copy(self._config_vars)
|
sysconfig._config_vars = copy(self._config_vars)
|
||||||
|
super(UtilTestCase, self).tearDown()
|
||||||
|
|
||||||
def _set_uname(self, uname):
|
def _set_uname(self, uname):
|
||||||
self._uname = uname
|
self._uname = uname
|
||||||
|
@ -102,7 +94,7 @@ class utilTestCase(unittest.TestCase):
|
||||||
('Darwin Kernel Version 8.11.1: '
|
('Darwin Kernel Version 8.11.1: '
|
||||||
'Wed Oct 10 18:23:28 PDT 2007; '
|
'Wed Oct 10 18:23:28 PDT 2007; '
|
||||||
'root:xnu-792.25.20~1/RELEASE_I386'), 'i386'))
|
'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 '
|
get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
|
||||||
'-fwrapv -O3 -Wall -Wstrict-prototypes')
|
'-fwrapv -O3 -Wall -Wstrict-prototypes')
|
||||||
|
@ -110,7 +102,7 @@ class utilTestCase(unittest.TestCase):
|
||||||
self.assertEquals(get_platform(), 'macosx-10.3-i386')
|
self.assertEquals(get_platform(), 'macosx-10.3-i386')
|
||||||
|
|
||||||
# macbook with fat binaries (fat, universal or fat64)
|
# 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 '
|
get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
|
||||||
'/Developer/SDKs/MacOSX10.4u.sdk '
|
'/Developer/SDKs/MacOSX10.4u.sdk '
|
||||||
'-fno-strict-aliasing -fno-common '
|
'-fno-strict-aliasing -fno-common '
|
||||||
|
@ -214,21 +206,14 @@ class utilTestCase(unittest.TestCase):
|
||||||
|
|
||||||
# posix without HOME
|
# posix without HOME
|
||||||
if os.name == 'posix': # this test won't run on windows
|
if os.name == 'posix': # this test won't run on windows
|
||||||
old_home = os.environ.get('HOME')
|
check_environ()
|
||||||
try:
|
import pwd
|
||||||
check_environ()
|
self.assertEquals(self.environ['HOME'],
|
||||||
import pwd
|
pwd.getpwuid(os.getuid())[5])
|
||||||
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']
|
|
||||||
else:
|
else:
|
||||||
check_environ()
|
check_environ()
|
||||||
|
|
||||||
self.assertEquals(os.environ['PLAT'], get_platform())
|
self.assertEquals(self.environ['PLAT'], get_platform())
|
||||||
self.assertEquals(util._environ_checked, 1)
|
self.assertEquals(util._environ_checked, 1)
|
||||||
|
|
||||||
def test_split_quoted(self):
|
def test_split_quoted(self):
|
||||||
|
@ -253,7 +238,7 @@ class utilTestCase(unittest.TestCase):
|
||||||
self.assertEquals(res, wanted)
|
self.assertEquals(res, wanted)
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
return unittest.makeSuite(utilTestCase)
|
return unittest.makeSuite(UtilTestCase)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main(defaultTest="test_suite")
|
unittest.main(defaultTest="test_suite")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue