summaryrefslogtreecommitdiff
path: root/unit_tests/test_doctest_munging.rst
diff options
context:
space:
mode:
authorJason Pellerin <jpellerin@gmail.com>2007-10-13 21:45:45 +0000
committerJason Pellerin <jpellerin@gmail.com>2007-10-13 21:45:45 +0000
commit75c9c574e20b4ebe53c6a33753295ad65557d9bf (patch)
treef8bfb09eccdba87d5741fd83b0a37393b41ecdde /unit_tests/test_doctest_munging.rst
parent65b2975d6c4e6af7a64725987a5838d3e71245e5 (diff)
downloadnose-75c9c574e20b4ebe53c6a33753295ad65557d9bf.tar.gz
Merged 0.10.0-stable [308]:[378] into trunk
Diffstat (limited to 'unit_tests/test_doctest_munging.rst')
-rw-r--r--unit_tests/test_doctest_munging.rst105
1 files changed, 105 insertions, 0 deletions
diff --git a/unit_tests/test_doctest_munging.rst b/unit_tests/test_doctest_munging.rst
new file mode 100644
index 0000000..fdbce64
--- /dev/null
+++ b/unit_tests/test_doctest_munging.rst
@@ -0,0 +1,105 @@
+doctest output normalization for plugin testing support
+=======================================================
+
+nose.plugins.plugintest.run() is used for testing nose plugins in
+doctests, so it needs to normalise nose output to remove information
+that is not of interest to most plugin tests.
+
+We strip stack trace from formatted exceptions, using a regexp copied
+from ``doctest.py``. That regexp always matches to the end of a
+string, so we split on blank lines before running the regexp on each
+resulting block.
+
+ >>> from nose.plugins.plugintest import blankline_separated_blocks
+ >>> list(blankline_separated_blocks("spam\neggs\n\nfoo\nbar\n\n"))
+ ['spam\neggs\n\n', 'foo\nbar\n\n']
+ >>> list(blankline_separated_blocks("spam\neggs\n\nfoo\nbar\n"))
+ ['spam\neggs\n\n', 'foo\nbar\n']
+ >>> list(blankline_separated_blocks("spam\neggs\n\nfoo\nbar"))
+ ['spam\neggs\n\n', 'foo\nbar']
+ >>> list(blankline_separated_blocks(""))
+ []
+ >>> list(blankline_separated_blocks("spam"))
+ ['spam']
+
+``remove_stack_traces`` removes the stack traces, replacing them with
+an ellipsis. Note the first line here is chosen not to be "Traceback
+(most recent...", since doctest would interpret that as meaning that
+the example should raise an exception!
+
+ >>> from nose.plugins.plugintest import remove_stack_traces
+ >>> print remove_stack_traces("""\
+ ... Ceci n'est pas une traceback.
+ ... Traceback (most recent call last):
+ ... File "/some/dir/foomodule.py", line 15, in runTest
+ ... File "/some/dir/spam.py", line 293, in who_knows_what
+ ... AssertionError: something bad happened
+ ... """)
+ Ceci n'est pas une traceback.
+ Traceback (most recent call last):
+ ...
+ AssertionError: something bad happened
+ <BLANKLINE>
+
+Multiple tracebacks in an example are all replaced, as long as they're
+separated by blank lines.
+
+ >>> print remove_stack_traces("""\
+ ... Ceci n'est pas une traceback.
+ ... Traceback (most recent call last):
+ ... File spam
+ ... AttributeError: eggs
+ ...
+ ... Traceback (most recent call last):
+ ... File eggs
+ ... AttributeError: spam
+ ... """)
+ Ceci n'est pas une traceback.
+ Traceback (most recent call last):
+ ...
+ AttributeError: eggs
+ <BLANKLINE>
+ Traceback (most recent call last):
+ ...
+ AttributeError: spam
+ <BLANKLINE>
+
+
+Putting it together, ``munge_nose_output_for_doctest()`` removes stack
+traces, removes test timings from "Ran n test(s)" output, and strips
+trailing blank lines.
+
+ >>> from nose.plugins.plugintest import munge_nose_output_for_doctest
+ >>> print munge_nose_output_for_doctest("""\
+ ... runTest (foomodule.PassingTest) ... ok
+ ... runTest (foomodule.FailingTest) ... FAIL
+ ...
+ ... ======================================================================
+ ... FAIL: runTest (foomodule.FailingTest)
+ ... ----------------------------------------------------------------------
+ ... Traceback (most recent call last):
+ ... File "/some/dir/foomodule.py", line 15, in runTest
+ ... File "/some/dir/spam.py", line 293, in who_knows_what
+ ... AssertionError: something bad happened
+ ...
+ ... ----------------------------------------------------------------------
+ ... Ran 1 test in 0.082s
+ ...
+ ... FAILED (failures=1)
+ ...
+ ...
+ ... """)
+ runTest (foomodule.PassingTest) ... ok
+ runTest (foomodule.FailingTest) ... FAIL
+ <BLANKLINE>
+ ======================================================================
+ FAIL: runTest (foomodule.FailingTest)
+ ----------------------------------------------------------------------
+ Traceback (most recent call last):
+ ...
+ AssertionError: something bad happened
+ <BLANKLINE>
+ ----------------------------------------------------------------------
+ Ran 1 test in ...s
+ <BLANKLINE>
+ FAILED (failures=1)