summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-01-18 11:54:03 -0500
committerNed Batchelder <ned@nedbatchelder.com>2015-01-18 11:54:03 -0500
commit0d0836309b6354a07fb09cd8d28b309b6c8dba6c (patch)
tree53e7f22f8c83f09a6b00a54c9e0bb862d73dc68f /tests
parentb90a9db23aa99e58e20f48e53218fdb7fbd3c965 (diff)
downloadpython-coveragepy-git-0d0836309b6354a07fb09cd8d28b309b6c8dba6c.tar.gz
Properly deal with .pyc files missing their sources.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_summary.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/tests/test_summary.py b/tests/test_summary.py
index fa5b4461..77381186 100644
--- a/tests/test_summary.py
+++ b/tests/test_summary.py
@@ -1,6 +1,12 @@
"""Test text-based summary reporting for coverage.py"""
-import os, re, sys
+import glob
+import os
+import py_compile
+import re
+import sys
+
+from nose.plugins.skip import SkipTest
import coverage
from coverage.backward import StringIO
@@ -438,6 +444,55 @@ class SummaryTest(CoverageTest):
self.assertIn("start.pyw 2 0 100%", report)
self.assertIn("mod.pyw 1 0 100%", report)
+ def test_tracing_pyc_file(self):
+ # Create two Python files.
+ self.make_file("mod.py", "a = 1\n")
+ self.make_file("main.py", "import mod\n")
+
+ # Make one into a .pyc.
+ py_compile.compile("mod.py")
+
+ # Run the program.
+ cov = coverage.coverage()
+ cov.start()
+ import main # pragma: nested # pylint: disable=import-error,unused-variable
+ cov.stop() # pragma: nested
+
+ report = self.get_report(cov).splitlines()
+ self.assertIn("mod.py 1 0 100%", report)
+
+ def test_missing_py_file_during_run(self):
+ # PyPy2 doesn't run bare .pyc files.
+ if '__pypy__' in sys.builtin_module_names and sys.version_info < (3,):
+ raise SkipTest("PyPy2 doesn't run bare .pyc files")
+
+ # Create two Python files.
+ self.make_file("mod.py", "a = 1\n")
+ self.make_file("main.py", "import mod\n")
+
+ # Make one into a .pyc, and remove the .py.
+ py_compile.compile("mod.py")
+ os.remove("mod.py")
+
+ # Python 3 puts the .pyc files in a __pycache__ directory, and will
+ # not import from there without source. It will import a .pyc from
+ # the source location though.
+ if not os.path.exists("mod.pyc"):
+ pycs = glob.glob("__pycache__/mod.*.pyc")
+ self.assertEqual(len(pycs), 1)
+ os.rename(pycs[0], "mod.pyc")
+
+ # Run the program.
+ cov = coverage.coverage()
+ cov.start()
+ import main # pragma: nested # pylint: disable=import-error,unused-variable
+ cov.stop() # pragma: nested
+
+ # Put back the missing Python file.
+ self.make_file("mod.py", "a = 1\n")
+ report = self.get_report(cov).splitlines()
+ self.assertIn("mod.py 1 0 100%", report)
+
class SummaryTest2(CoverageTest):
"""Another bunch of summary tests."""