Merged revisions 71984 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r71984 | walter.doerwald | 2009-04-26 22:51:44 +0200 (So, 26 Apr 2009) | 2 lines

  Use test.test_support.EnvironmentVarGuard where tests change environment vars.
........
This commit is contained in:
Walter Dörwald 2009-04-26 21:39:21 +00:00
parent 4af362905c
commit b525e18500
6 changed files with 36 additions and 64 deletions

View file

@ -117,27 +117,19 @@ class urlopen_FileTests(unittest.TestCase):
class ProxyTests(unittest.TestCase):
def setUp(self):
# Save all proxy related env vars
self._saved_environ = dict([(k, v) for k, v in os.environ.items()
if k.lower().find('proxy') >= 0])
# Delete all proxy related env vars
for k in self._saved_environ:
del os.environ[k]
# Records changes to env vars
self.env = support.EnvironmentVarGuard()
def tearDown(self):
# Restore all proxy related env vars
for k, v in self._saved_environ.items():
os.environ[k] = v
self.env.__exit__()
del self.env
def test_getproxies_environment_keep_no_proxies(self):
try:
os.environ['NO_PROXY'] = 'localhost'
proxies = urllib.request.getproxies_environment()
# getproxies_environment use lowered case truncated (no '_proxy') keys
self.assertEquals('localhost', proxies['no'])
finally:
# The old value will be restored by tearDown, if applicable.
del os.environ['NO_PROXY']
self.env.set('NO_PROXY', 'localhost')
proxies = urllib.request.getproxies_environment()
# getproxies_environment use lowered case truncated (no '_proxy') keys
self.assertEquals('localhost', proxies['no'])
class urlopen_HttpTests(unittest.TestCase):