Changeset 391 for python/trunk/Lib/test/test_getopt.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_getopt.py
r2 r391 2 2 # David Goodger <dgoodger@bigfoot.com> 2000-08-19 3 3 4 from test.test_support import verbose, run_doctest, run_unittest 4 from test.test_support import verbose, run_doctest, run_unittest, EnvironmentVarGuard 5 5 import unittest 6 6 7 7 import getopt 8 import os9 8 10 9 sentinel = object() … … 12 11 class GetoptTests(unittest.TestCase): 13 12 def setUp(self): 14 self. old_posixly_correct = os.environ.get("POSIXLY_CORRECT", sentinel)15 if self.old_posixly_correct is not sentinel:16 del os.environ["POSIXLY_CORRECT"]13 self.env = EnvironmentVarGuard() 14 if "POSIXLY_CORRECT" in self.env: 15 del self.env["POSIXLY_CORRECT"] 17 16 18 17 def tearDown(self): 19 if self.old_posixly_correct is sentinel: 20 os.environ.pop("POSIXLY_CORRECT", None) 21 else: 22 os.environ["POSIXLY_CORRECT"] = self.old_posixly_correct 18 self.env.__exit__() 19 del self.env 23 20 24 21 def assertError(self, *args, **kwargs): … … 26 23 27 24 def test_short_has_arg(self): 28 self. failUnless(getopt.short_has_arg('a', 'a:'))29 self. failIf(getopt.short_has_arg('a', 'a'))25 self.assertTrue(getopt.short_has_arg('a', 'a:')) 26 self.assertFalse(getopt.short_has_arg('a', 'a')) 30 27 self.assertError(getopt.short_has_arg, 'a', 'b') 31 28 32 29 def test_long_has_args(self): 33 30 has_arg, option = getopt.long_has_args('abc', ['abc=']) 34 self. failUnless(has_arg)31 self.assertTrue(has_arg) 35 32 self.assertEqual(option, 'abc') 36 33 37 34 has_arg, option = getopt.long_has_args('abc', ['abc']) 38 self. failIf(has_arg)35 self.assertFalse(has_arg) 39 36 self.assertEqual(option, 'abc') 40 37 41 38 has_arg, option = getopt.long_has_args('abc', ['abcd']) 42 self. failIf(has_arg)39 self.assertFalse(has_arg) 43 40 self.assertEqual(option, 'abcd') 44 41 … … 125 122 ('--alpha', ''), ('--beta', '2')]) 126 123 124 # recognize "-" as an argument 125 opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', []) 126 self.assertEqual(args, ['-']) 127 self.assertEqual(opts, [('-a', ''), ('-b', '-')]) 128 127 129 # Posix style via + 128 130 opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta=']) … … 131 133 132 134 # Posix style via POSIXLY_CORRECT 133 os.environ["POSIXLY_CORRECT"] = "1"135 self.env["POSIXLY_CORRECT"] = "1" 134 136 opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta=']) 135 137 self.assertEqual(opts, [('-a', '')]) … … 172 174 run_doctest(m, verbose) 173 175 176 def test_issue4629(self): 177 longopts, shortopts = getopt.getopt(['--help='], '', ['help=']) 178 self.assertEqual(longopts, [('--help', '')]) 179 longopts, shortopts = getopt.getopt(['--help=x'], '', ['help=']) 180 self.assertEqual(longopts, [('--help', 'x')]) 181 self.assertRaises(getopt.GetoptError, getopt.getopt, ['--help='], '', ['help']) 174 182 175 183 def test_main():
Note:
See TracChangeset
for help on using the changeset viewer.