summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/coveragetest.py2
-rw-r--r--test/test_coverage.py49
-rw-r--r--test/test_execfile.py11
3 files changed, 59 insertions, 3 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py
index 0fb8d163..dad96978 100644
--- a/test/coveragetest.py
+++ b/test/coveragetest.py
@@ -209,7 +209,7 @@ class CoverageTest(unittest.TestCase):
here = os.path.dirname(self.nice_file(coverage.__file__, ".."))
testmods = self.nice_file(here, 'test/modules')
zipfile = self.nice_file(here, 'test/zipmods.zip')
- pypath = os.environ['PYTHONPATH']
+ pypath = os.environ.get('PYTHONPATH', '')
if pypath:
pypath += os.pathsep
pypath += testmods + os.pathsep + zipfile
diff --git a/test/test_coverage.py b/test/test_coverage.py
index 30ac4b8c..3575f378 100644
--- a/test/test_coverage.py
+++ b/test/test_coverage.py
@@ -1689,7 +1689,7 @@ class RecursionTest(CoverageTest):
""",
[1,2,3,5,7], "")
- def xxtestLongRecursion(self):
+ def testLongRecursion(self):
# We can't finish a very deep recursion, but we don't crash.
self.assertRaises(RuntimeError, self.checkCoverage,
"""\
@@ -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.
diff --git a/test/test_execfile.py b/test/test_execfile.py
index eae227a1..6cc7cab8 100644
--- a/test/test_execfile.py
+++ b/test/test_execfile.py
@@ -46,3 +46,14 @@ class RunTest(CoverageTest):
self.assertEqual(os.listdir("."), ["xxx"])
run_python_file("xxx", ["xxx"])
self.assertEqual(os.listdir("."), ["xxx"])
+
+ def test_universal_newlines(self):
+ # Make sure we can read any sort of line ending.
+ pylines = """# try newlines|print 'Hello, world!'|""".split('|')
+ for nl in ('\n', '\r\n', '\r'):
+ fpy = open('nl.py', 'wb')
+ fpy.write(nl.join(pylines))
+ fpy.close()
+ run_python_file('nl.py', ['nl.py'])
+ self.assertEqual(self.stdout(), "Hello, world!\n"*3)
+