diff options
| author | Walter Dörwald <walter@livinglogic.de> | 2009-05-01 17:35:37 (GMT) |
|---|---|---|
| committer | Walter Dörwald <walter@livinglogic.de> | 2009-05-01 17:35:37 (GMT) |
| commit | 6733bed57e780008f8c78422d2a9676b9a2710cf (patch) | |
| tree | 9ac7e1469b55cba61664a2b07e50566320a814d9 /Lib/test/test_ntpath.py | |
| parent | ca87fa5a5b650de2d4b5cb04fb5847cf631e75eb (diff) | |
| download | cpython-6733bed57e780008f8c78422d2a9676b9a2710cf.zip cpython-6733bed57e780008f8c78422d2a9676b9a2710cf.tar.gz cpython-6733bed57e780008f8c78422d2a9676b9a2710cf.tar.bz2 | |
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_ntpath.py')
| -rw-r--r-- | Lib/test/test_ntpath.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index a077c78..ade0790 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -124,12 +124,11 @@ class TestNtpath(unittest.TestCase): tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b') def test_expandvars(self): - oldenv = os.environ.copy() - try: - os.environ.clear() - os.environ["foo"] = "bar" - os.environ["{foo"] = "baz1" - os.environ["{foo}"] = "baz2" + with test_support.EnvironmentVarGuard() as env: + env.clear() + env["foo"] = "bar" + env["{foo"] = "baz1" + env["{foo}"] = "baz2" tester('ntpath.expandvars("foo")', "foo") tester('ntpath.expandvars("$foo bar")', "bar bar") tester('ntpath.expandvars("${foo}bar")', "barbar") @@ -149,9 +148,6 @@ class TestNtpath(unittest.TestCase): tester('ntpath.expandvars("%?bar%")', "%?bar%") tester('ntpath.expandvars("%foo%%bar")', "bar%bar") tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar") - finally: - os.environ.clear() - os.environ.update(oldenv) def test_abspath(self): # ntpath.abspath() can only be used on a system with the "nt" module |
