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.
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 @@
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 @@
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