Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_getopt.py

    r2 r391  
    22# David Goodger <dgoodger@bigfoot.com> 2000-08-19
    33
    4 from test.test_support import verbose, run_doctest, run_unittest
     4from test.test_support import verbose, run_doctest, run_unittest, EnvironmentVarGuard
    55import unittest
    66
    77import getopt
    8 import os
    98
    109sentinel = object()
     
    1211class GetoptTests(unittest.TestCase):
    1312    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"]
    1716
    1817    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
    2320
    2421    def assertError(self, *args, **kwargs):
     
    2623
    2724    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'))
    3027        self.assertError(getopt.short_has_arg, 'a', 'b')
    3128
    3229    def test_long_has_args(self):
    3330        has_arg, option = getopt.long_has_args('abc', ['abc='])
    34         self.failUnless(has_arg)
     31        self.assertTrue(has_arg)
    3532        self.assertEqual(option, 'abc')
    3633
    3734        has_arg, option = getopt.long_has_args('abc', ['abc'])
    38         self.failIf(has_arg)
     35        self.assertFalse(has_arg)
    3936        self.assertEqual(option, 'abc')
    4037
    4138        has_arg, option = getopt.long_has_args('abc', ['abcd'])
    42         self.failIf(has_arg)
     39        self.assertFalse(has_arg)
    4340        self.assertEqual(option, 'abcd')
    4441
     
    125122                                ('--alpha', ''), ('--beta', '2')])
    126123
     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
    127129        # Posix style via +
    128130        opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
     
    131133
    132134        # Posix style via POSIXLY_CORRECT
    133         os.environ["POSIXLY_CORRECT"] = "1"
     135        self.env["POSIXLY_CORRECT"] = "1"
    134136        opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
    135137        self.assertEqual(opts, [('-a', '')])
     
    172174        run_doctest(m, verbose)
    173175
     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'])
    174182
    175183def test_main():
Note: See TracChangeset for help on using the changeset viewer.