diff options
author | Walter Dörwald <walter@livinglogic.de> | 2009-05-01 19:58:58 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2009-05-01 19:58:58 (GMT) |
commit | 155374d95d8ecd235d3a3edd92dd6f6a23d59f11 (patch) | |
tree | 91deb4c1d292387d2b216d869e79311cad1dbc61 /Lib/test/test_getopt.py | |
parent | 33841c34896834daa8ee38d3ff54d7800b9723c2 (diff) | |
download | cpython-155374d95d8ecd235d3a3edd92dd6f6a23d59f11.zip cpython-155374d95d8ecd235d3a3edd92dd6f6a23d59f11.tar.gz cpython-155374d95d8ecd235d3a3edd92dd6f6a23d59f11.tar.bz2 |
Merged revisions 72167 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72167 | walter.doerwald | 2009-05-01 19:35:37 +0200 (Fr, 01 Mai 2009) | 5 lines
Make test.test_support.EnvironmentVarGuard behave like a dictionary.
All changes are mirrored to the underlying os.environ dict, but rolled back
on exit from the with block.
........
Diffstat (limited to 'Lib/test/test_getopt.py')
-rw-r--r-- | Lib/test/test_getopt.py | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py index 11ae163..b7a6309 100644 --- a/Lib/test/test_getopt.py +++ b/Lib/test/test_getopt.py @@ -1,7 +1,7 @@ # test_getopt.py # David Goodger <dgoodger@bigfoot.com> 2000-08-19 -from test.support import verbose, run_doctest, run_unittest +from test.support import verbose, run_doctest, run_unittest, EnvironmentVarGuard import unittest import getopt @@ -11,15 +11,13 @@ sentinel = object() class GetoptTests(unittest.TestCase): def setUp(self): - self.old_posixly_correct = os.environ.get("POSIXLY_CORRECT", sentinel) - if self.old_posixly_correct is not sentinel: - del os.environ["POSIXLY_CORRECT"] + self.env = EnvironmentVarGuard() + if "POSIXLY_CORRECT" in self.env: + del self.env["POSIXLY_CORRECT"] def tearDown(self): - if self.old_posixly_correct is sentinel: - os.environ.pop("POSIXLY_CORRECT", None) - else: - os.environ["POSIXLY_CORRECT"] = self.old_posixly_correct + self.env.__exit__() + del self.env def assertError(self, *args, **kwargs): self.assertRaises(getopt.GetoptError, *args, **kwargs) @@ -135,7 +133,7 @@ class GetoptTests(unittest.TestCase): self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2']) # Posix style via POSIXLY_CORRECT - os.environ["POSIXLY_CORRECT"] = "1" + self.env["POSIXLY_CORRECT"] = "1" opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta=']) self.assertEqual(opts, [('-a', '')]) self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2']) |