Commit 954e266a authored by Edward Loper's avatar Edward Loper

- 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.
parent 4e9d625e
This diff is collapsed.
...@@ -183,7 +183,9 @@ constructor: ...@@ -183,7 +183,9 @@ constructor:
... example ... example
... ''' ... '''
>>> globs = {} # globals to run the test in. >>> 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 >>> print test
<DocTest some_test from some_file:20 (2 examples)> <DocTest some_test from some_file:20 (2 examples)>
>>> len(test.examples) >>> len(test.examples)
...@@ -217,7 +219,7 @@ expected output of an example, then `DocTest` will raise a ValueError: ...@@ -217,7 +219,7 @@ expected output of an example, then `DocTest` will raise a ValueError:
... bad ... bad
... indentation ... indentation
... ''' ... '''
>>> doctest.DocTest(docstring, globs, 'some_test', 'filename', 0) >>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0)
Traceback (most recent call last): Traceback (most recent call last):
ValueError: line 4 of the docstring for some_test has inconsistent leading whitespace: ' indentation' 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: ...@@ -229,7 +231,7 @@ continuation lines, then `DocTest` will raise a ValueError:
... ... 2) ... ... 2)
... ('bad', 'indentation') ... ('bad', 'indentation')
... ''' ... '''
>>> doctest.DocTest(docstring, globs, 'some_test', 'filename', 0) >>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0)
Traceback (most recent call last): Traceback (most recent call last):
ValueError: line 2 of the docstring for some_test has inconsistent leading whitespace: ' ... 2)' 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` ...@@ -237,7 +239,7 @@ If there's no blank space after a PS1 prompt ('>>>'), then `DocTest`
will raise a ValueError: will raise a ValueError:
>>> docstring = '>>>print 1\n1' >>> 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): Traceback (most recent call last):
ValueError: line 1 of the docstring for some_test lacks blank after >>>: '>>>print 1' 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` ...@@ -245,7 +247,7 @@ If there's no blank space after a PS2 prompt ('...'), then `DocTest`
will raise a ValueError: will raise a ValueError:
>>> docstring = '>>> if 1:\n...print 1\n1' >>> 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): Traceback (most recent call last):
ValueError: line 2 of the docstring for some_test lacks blank after ...: '...print 1' ValueError: line 2 of the docstring for some_test lacks blank after ...: '...print 1'
...@@ -998,7 +1000,8 @@ def test_pdb_set_trace(): ...@@ -998,7 +1000,8 @@ def test_pdb_set_trace():
... >>> x = 42 ... >>> x = 42
... >>> import pdb; pdb.set_trace() ... >>> 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) >>> runner = doctest.DocTestRunner(verbose=False)
To demonstrate this, we'll create a fake standard input that To demonstrate this, we'll create a fake standard input that
...@@ -1040,7 +1043,7 @@ def test_pdb_set_trace(): ...@@ -1040,7 +1043,7 @@ def test_pdb_set_trace():
... >>> x=1 ... >>> x=1
... >>> calls_set_trace() ... >>> 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 = tempfile.TemporaryFile(mode='w+')
>>> fake_stdin.write('\n'.join([ >>> fake_stdin.write('\n'.join([
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment