mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
- DocTest is now a simple container class; its constructor is no longer
responsible for parsing the string. - Renamed Parser to DocTestParser - DocTestParser.get_*() now accept the string & name as command-line arguments; the parser's constructor is now empty. - Added DocTestParser.get_doctest() method - Replaced "doctest_factory" argument to DocTestFinder with a "parser" argument (takes a DocTestParser). - Changed _tag_msg to take an indentation string argument.
This commit is contained in:
parent
413ced6c22
commit
a1ef6110ba
2 changed files with 110 additions and 104 deletions
|
@ -183,7 +183,9 @@ constructor:
|
|||
... example
|
||||
... '''
|
||||
>>> globs = {} # globals to run the test in.
|
||||
>>> test = doctest.DocTest(docstring, globs, 'some_test', 'some_file', 20)
|
||||
>>> parser = doctest.DocTestParser()
|
||||
>>> test = parser.get_doctest(docstring, globs, 'some_test',
|
||||
... 'some_file', 20)
|
||||
>>> print test
|
||||
<DocTest some_test from some_file:20 (2 examples)>
|
||||
>>> len(test.examples)
|
||||
|
@ -217,7 +219,7 @@ expected output of an example, then `DocTest` will raise a ValueError:
|
|||
... bad
|
||||
... indentation
|
||||
... '''
|
||||
>>> doctest.DocTest(docstring, globs, 'some_test', 'filename', 0)
|
||||
>>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0)
|
||||
Traceback (most recent call last):
|
||||
ValueError: line 4 of the docstring for some_test has inconsistent leading whitespace: ' indentation'
|
||||
|
||||
|
@ -229,7 +231,7 @@ continuation lines, then `DocTest` will raise a ValueError:
|
|||
... ... 2)
|
||||
... ('bad', 'indentation')
|
||||
... '''
|
||||
>>> doctest.DocTest(docstring, globs, 'some_test', 'filename', 0)
|
||||
>>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0)
|
||||
Traceback (most recent call last):
|
||||
ValueError: line 2 of the docstring for some_test has inconsistent leading whitespace: ' ... 2)'
|
||||
|
||||
|
@ -237,7 +239,7 @@ If there's no blank space after a PS1 prompt ('>>>'), then `DocTest`
|
|||
will raise a ValueError:
|
||||
|
||||
>>> docstring = '>>>print 1\n1'
|
||||
>>> doctest.DocTest(docstring, globs, 'some_test', 'filename', 0)
|
||||
>>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0)
|
||||
Traceback (most recent call last):
|
||||
ValueError: line 1 of the docstring for some_test lacks blank after >>>: '>>>print 1'
|
||||
|
||||
|
@ -245,7 +247,7 @@ If there's no blank space after a PS2 prompt ('...'), then `DocTest`
|
|||
will raise a ValueError:
|
||||
|
||||
>>> docstring = '>>> if 1:\n...print 1\n1'
|
||||
>>> doctest.DocTest(docstring, globs, 'some_test', 'filename', 0)
|
||||
>>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0)
|
||||
Traceback (most recent call last):
|
||||
ValueError: line 2 of the docstring for some_test lacks blank after ...: '...print 1'
|
||||
|
||||
|
@ -998,7 +1000,8 @@ def test_pdb_set_trace():
|
|||
... >>> x = 42
|
||||
... >>> import pdb; pdb.set_trace()
|
||||
... '''
|
||||
>>> test = doctest.DocTest(doc, {}, "foo", "foo.py", 0)
|
||||
>>> parser = doctest.DocTestParser()
|
||||
>>> test = parser.get_doctest(doc, {}, "foo", "foo.py", 0)
|
||||
>>> runner = doctest.DocTestRunner(verbose=False)
|
||||
|
||||
To demonstrate this, we'll create a fake standard input that
|
||||
|
@ -1040,7 +1043,7 @@ def test_pdb_set_trace():
|
|||
... >>> x=1
|
||||
... >>> calls_set_trace()
|
||||
... '''
|
||||
>>> test = doctest.DocTest(doc, globals(), "foo", "foo.py", 0)
|
||||
>>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0)
|
||||
|
||||
>>> fake_stdin = tempfile.TemporaryFile(mode='w+')
|
||||
>>> fake_stdin.write('\n'.join([
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue