Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Unified Diff: tools/telemetry/third_party/coverage/tests/test_collector.py

Issue 1366913004: Add coverage Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/third_party/coverage/tests/test_collector.py
diff --git a/tools/telemetry/third_party/coverage/tests/test_collector.py b/tools/telemetry/third_party/coverage/tests/test_collector.py
new file mode 100644
index 0000000000000000000000000000000000000000..bd96341588b3881d755a92f96176358de80bc3fc
--- /dev/null
+++ b/tools/telemetry/third_party/coverage/tests/test_collector.py
@@ -0,0 +1,50 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+"""Tests of coverage/collector.py and other collectors."""
+
+import os.path
+
+import coverage
+
+from tests.coveragetest import CoverageTest
+from tests.helpers import CheckUniqueFilenames
+
+
+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)
+ """)
+
+ # Trace one file, but not the other. CheckUniqueFilenames will assert
+ # that _should_trace hasn't been called twice for the same file.
+ cov = coverage.Coverage(include=["f1.py"])
+ should_trace_hook = CheckUniqueFilenames.hook(cov, '_should_trace')
+
+ # Import the Python file, executing it.
+ self.start_import_stop(cov, "f2")
+
+ # Double-check that our files were checked.
+ abs_files = set(os.path.abspath(f) for f in should_trace_hook.filenames)
+ self.assertIn(os.path.abspath("f1.py"), abs_files)
+ self.assertIn(os.path.abspath("f2.py"), abs_files)

Powered by Google App Engine
This is Rietveld 408576698