mirror of
https://github.com/python/cpython.git
synced 2025-10-02 21:25:24 +00:00
[3.12] gh-89392: Use unittest test runner for doctests in test_getopt (GH-108916) (#108919)
gh-89392: Use unittest test runner for doctests in test_getopt (GH-108916)
(cherry picked from commit f980cc19b9
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
da02508a0e
commit
038b0a9cb0
1 changed files with 38 additions and 37 deletions
|
@ -1,8 +1,8 @@
|
|||
# test_getopt.py
|
||||
# David Goodger <dgoodger@bigfoot.com> 2000-08-19
|
||||
|
||||
from test.support import verbose, run_doctest
|
||||
from test.support.os_helper import EnvironmentVarGuard
|
||||
import doctest
|
||||
import unittest
|
||||
|
||||
import getopt
|
||||
|
@ -134,8 +134,15 @@ class GetoptTests(unittest.TestCase):
|
|||
self.assertEqual(opts, [('-a', '')])
|
||||
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
|
||||
|
||||
def test_libref_examples(self):
|
||||
s = """
|
||||
def test_issue4629(self):
|
||||
longopts, shortopts = getopt.getopt(['--help='], '', ['help='])
|
||||
self.assertEqual(longopts, [('--help', '')])
|
||||
longopts, shortopts = getopt.getopt(['--help=x'], '', ['help='])
|
||||
self.assertEqual(longopts, [('--help', 'x')])
|
||||
self.assertRaises(getopt.GetoptError, getopt.getopt, ['--help='], '', ['help'])
|
||||
|
||||
def test_libref_examples():
|
||||
"""
|
||||
Examples from the Library Reference: Doc/lib/libgetopt.tex
|
||||
|
||||
An example using only Unix style options:
|
||||
|
@ -166,16 +173,10 @@ class GetoptTests(unittest.TestCase):
|
|||
['a1', 'a2']
|
||||
"""
|
||||
|
||||
import types
|
||||
m = types.ModuleType("libreftest", s)
|
||||
run_doctest(m, verbose)
|
||||
def load_tests(loader, tests, pattern):
|
||||
tests.addTest(doctest.DocTestSuite())
|
||||
return tests
|
||||
|
||||
def test_issue4629(self):
|
||||
longopts, shortopts = getopt.getopt(['--help='], '', ['help='])
|
||||
self.assertEqual(longopts, [('--help', '')])
|
||||
longopts, shortopts = getopt.getopt(['--help=x'], '', ['help='])
|
||||
self.assertEqual(longopts, [('--help', 'x')])
|
||||
self.assertRaises(getopt.GetoptError, getopt.getopt, ['--help='], '', ['help'])
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue