summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-11-25 09:13:29 -0500
committerNed Batchelder <ned@nedbatchelder.com>2009-11-25 09:13:29 -0500
commit19cf94d2af6f79cb5995f124bce3fe213823dac0 (patch)
tree4581d0cda1f051f51ac49101d42b4b58706b4af2
parent566932401e1801c4e860ccc2ac291fd6536952de (diff)
downloadpython-coveragepy-git-19cf94d2af6f79cb5995f124bce3fe213823dac0.tar.gz
Although issue #19 was a doctest flaw, it's good to have a test to be sure we're still working well with doctests.
-rw-r--r--test/test_oddball.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/test_oddball.py b/test/test_oddball.py
index 57d2fdbd..0376f65a 100644
--- a/test/test_oddball.py
+++ b/test/test_oddball.py
@@ -240,3 +240,47 @@ class ExceptionTest(CoverageTest):
continue
clean_lines[os.path.basename(f)] = llist
self.assertEqual(clean_lines, lines_expected)
+
+
+if sys.hexversion > 0x02050000:
+ class DoctestTest(CoverageTest):
+ """Tests invoked with doctest should measure properly."""
+
+ def setUp(self):
+ super(DoctestTest, self).setUp()
+
+ # Oh, the irony! This test case exists because Python 2.4's
+ # doctest module doesn't play well with coverage. But nose fixes
+ # the problem by monkeypatching doctest. I want to undo the
+ # monkeypatch to be sure I'm getting the doctest module that users
+ # of coverage will get. Deleting the imported module here is
+ # enough: when the test imports doctest again, it will get a fresh
+ # copy without the monkeypatch.
+ del sys.modules['doctest']
+
+ def testDoctest(self):
+ self.check_coverage('''\
+ def return_arg_or_void(arg):
+ """If <arg> is None, return "Void"; otherwise return <arg>
+
+ >>> return_arg_or_void(None)
+ 'Void'
+ >>> return_arg_or_void("arg")
+ 'arg'
+ >>> return_arg_or_void("None")
+ 'None'
+ """
+ if arg is None:
+ return "Void"
+ else:
+ return arg
+
+ import doctest, sys
+ doctest.testmod(sys.modules[__name__]) # we're not __main__ :(
+ ''',
+ [1,11,12,14,16,17], "")
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main()