summaryrefslogtreecommitdiff
path: root/test/test_coverage.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-06-28 17:43:05 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-06-28 17:43:05 -0400
commit2f217f38e03b1fd0b3a053f2c47e31a69f186aca (patch)
tree098eccef4aa53703b17f99b2a0adfcf9c73fbc00 /test/test_coverage.py
parenteba53328c9bc79297b06b58b0627ee6c1ce58a8e (diff)
downloadpython-coveragepy-git-2f217f38e03b1fd0b3a053f2c47e31a69f186aca.tar.gz
Epic bug: pyexpat fiddles incorrectly with the systrace function. This is a hack to make it behave correctly with coverage.py. Fixes bug #10.
Diffstat (limited to 'test/test_coverage.py')
-rw-r--r--test/test_coverage.py47
1 files changed, 46 insertions, 1 deletions
diff --git a/test/test_coverage.py b/test/test_coverage.py
index 30ac4b8c..2d08281f 100644
--- a/test/test_coverage.py
+++ b/test/test_coverage.py
@@ -1704,6 +1704,51 @@ class RecursionTest(CoverageTest):
[1,2,3,5,7], "")
+class PyexpatTest(CoverageTest):
+ """Pyexpat screws up tracing. Make sure we've counter-defended properly."""
+ def testPyexpat(self):
+ # pyexpat calls the trace function explicitly (inexplicably), and does
+ # it wrong for exceptions. Parsing a DOCTYPE for some reason throws
+ # an exception internally, and triggers its wrong behavior. This test
+ # checks that our fake PyTrace_RETURN hack in tracer.c works. It will
+ # also detect if the pyexpat bug is fixed unbeknownst to us, meaning
+ # we'd see two RETURNs where there should only be one.
+
+ self.makeFile("trydom.py", """\
+ import xml.dom.minidom
+
+ XML = '''\\
+ <!DOCTYPE fooey SYSTEM "http://www.example.com/example.dtd">
+ <root><child/><child/></root>
+ '''
+
+ def foo():
+ dom = xml.dom.minidom.parseString(XML)
+ assert len(dom.getElementsByTagName('child')) == 2
+ print "Parsed"
+
+ foo()
+ """)
+
+ self.makeFile("outer.py", "\n"*100 + "import trydom\nprint 'done'\n")
+
+ cov = coverage.coverage()
+ cov.erase()
+
+ # Import the python file, executing it.
+ cov.start()
+ self.importModule("outer")
+ cov.stop()
+
+ _, statements, missing, _ = cov.analysis("trydom.py")
+ self.assertEqual(statements, [1,3,8,9,10,11,13])
+ self.assertEqual(missing, [])
+
+ _, statements, missing, _ = cov.analysis("outer.py")
+ self.assertEqual(statements, [101,102])
+ self.assertEqual(missing, [])
+
+
if __name__ == '__main__':
print "Testing under Python version: %s" % sys.version
unittest.main()
@@ -1714,4 +1759,4 @@ if __name__ == '__main__':
# in an expression!)
# TODO: Generator comprehensions?
# TODO: Constant if tests ("if 1:"). Py 2.4 doesn't execute them.
-# TODO: There are no tests for analysis2 directly. \ No newline at end of file
+# TODO: There are no tests for analysis2 directly.