mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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. ........
This commit is contained in:
parent
33841c3489
commit
155374d95d
10 changed files with 79 additions and 68 deletions
|
@ -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'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue