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

Unified Diff: tools/telemetry/third_party/coverage/tests/plugin1.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/plugin1.py
diff --git a/tools/telemetry/third_party/coverage/tests/plugin1.py b/tools/telemetry/third_party/coverage/tests/plugin1.py
new file mode 100644
index 0000000000000000000000000000000000000000..af4dfc521b2b38a58fc53da5d9854eddd6cfd702
--- /dev/null
+++ b/tools/telemetry/third_party/coverage/tests/plugin1.py
@@ -0,0 +1,51 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+"""A plugin for test_plugins.py to import."""
+
+import os.path
+
+import coverage
+
+
+class Plugin(coverage.CoveragePlugin):
+ """A plugin to import, so that it isn't in the test's current directory."""
+
+ def file_tracer(self, filename):
+ """Trace only files named xyz.py"""
+ if "xyz.py" in filename:
+ return FileTracer(filename)
+
+ def file_reporter(self, filename):
+ return FileReporter(filename)
+
+
+class FileTracer(coverage.FileTracer):
+ """A FileTracer emulating a simple static plugin."""
+
+ def __init__(self, filename):
+ """Claim that xyz.py was actually sourced from ABC.zz"""
+ self._filename = filename
+ self._source_filename = os.path.join(
+ "/src",
+ os.path.basename(filename.replace("xyz.py", "ABC.zz"))
+ )
+
+ def source_filename(self):
+ return self._source_filename
+
+ def line_number_range(self, frame):
+ """Map the line number X to X05,X06,X07."""
+ lineno = frame.f_lineno
+ return lineno*100+5, lineno*100+7
+
+
+class FileReporter(coverage.FileReporter):
+ """Dead-simple FileReporter."""
+ def lines(self):
+ return set([105, 106, 107, 205, 206, 207])
+
+
+def coverage_init(reg, options): # pylint: disable=unused-argument
+ """Called by coverage to initialize the plugins here."""
+ reg.add_file_tracer(Plugin())
« no previous file with comments | « tools/telemetry/third_party/coverage/tests/osinfo.py ('k') | tools/telemetry/third_party/coverage/tests/plugin2.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698