summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2013-09-08 15:31:10 -0400
committerNed Batchelder <ned@nedbatchelder.com>2013-09-08 15:31:10 -0400
commitfda9a46afb56ce3d9d4f403a3f0d85b2899ebace (patch)
tree56bcd11d844a8b27d18adc2d7021b6a4ac0eff73 /tests
parent83411f84debeefa313a1b61121ef4fc9c9607fd6 (diff)
downloadpython-coveragepy-fda9a46afb56ce3d9d4f403a3f0d85b2899ebace.tar.gz
A test that the collector is using the should_trace_cache properly.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_collector.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_collector.py b/tests/test_collector.py
new file mode 100644
index 0000000..d0aa997
--- /dev/null
+++ b/tests/test_collector.py
@@ -0,0 +1,47 @@
+"""Tests of coverage/collector.py and other collectors."""
+
+import re
+
+import coverage
+from coverage.backward import StringIO
+
+from tests.coveragetest import CoverageTest
+
+
+class CollectorTest(CoverageTest):
+ """Test specific aspects of the collection process."""
+
+ def test_should_trace_cache(self):
+ # The tracers should only invoke should_trace once for each file name.
+
+ # Make some files that invoke each other.
+ self.make_file("f1.py", """\
+ def f1(x, f):
+ return f(x)
+ """)
+
+ self.make_file("f2.py", """\
+ import f1
+
+ def func(x):
+ return f1.f1(x, otherfunc)
+
+ def otherfunc(x):
+ return x*x
+
+ for i in range(10):
+ func(i)
+ """)
+
+ debug_out = StringIO()
+ cov = coverage.coverage(
+ include=["f1.py"], debug=['trace'], debug_file=debug_out
+ )
+
+ # Import the python file, executing it.
+ self.start_import_stop(cov, "f2")
+
+ # Grab all the filenames mentioned in debug output, there should be no
+ # duplicates.
+ filenames = re.findall(r"'[^']+'", debug_out.getvalue())
+ self.assertEqual(len(filenames), len(set(filenames)))