summaryrefslogtreecommitdiff
path: root/Lib/test/test_posixpath.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2009-05-01 17:35:37 +0000
committerWalter Dörwald <walter@livinglogic.de>2009-05-01 17:35:37 +0000
commit2df5858ce317caf4503c5e81f7eccd8a1613c52e (patch)
tree887de12e620472e8de3a7974ad3b08aa19069cb3 /Lib/test/test_posixpath.py
parenta076f4dbd680c8c5446287848bcead48b9b2d6da (diff)
downloadcpython-2df5858ce317caf4503c5e81f7eccd8a1613c52e.tar.gz
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_posixpath.py')
-rw-r--r--Lib/test/test_posixpath.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index b7fbd50dbb..0a0a48be96 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -346,18 +346,17 @@ class PosixPathTest(unittest.TestCase):
self.assert_(isinstance(posixpath.expanduser("~foo/"), basestring))
with test_support.EnvironmentVarGuard() as env:
- env.set('HOME', '/')
+ env['HOME'] = '/'
self.assertEqual(posixpath.expanduser("~"), "/")
self.assertRaises(TypeError, posixpath.expanduser)
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"
self.assertEqual(posixpath.expandvars("foo"), "foo")
self.assertEqual(posixpath.expandvars("$foo bar"), "bar bar")
self.assertEqual(posixpath.expandvars("${foo}bar"), "barbar")
@@ -370,9 +369,6 @@ class PosixPathTest(unittest.TestCase):
self.assertEqual(posixpath.expandvars("${{foo}}"), "baz1}")
self.assertEqual(posixpath.expandvars("$foo$foo"), "barbar")
self.assertEqual(posixpath.expandvars("$bar$bar"), "$bar$bar")
- finally:
- os.environ.clear()
- os.environ.update(oldenv)
self.assertRaises(TypeError, posixpath.expandvars)