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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
3
4 """A plugin for test_plugins.py to import."""
5
6 import os.path
7
8 import coverage
9
10
11 class Plugin(coverage.CoveragePlugin):
12 """A plugin to import, so that it isn't in the test's current directory."""
13
14 def file_tracer(self, filename):
15 """Trace only files named xyz.py"""
16 if "xyz.py" in filename:
17 return FileTracer(filename)
18
19 def file_reporter(self, filename):
20 return FileReporter(filename)
21
22
23 class FileTracer(coverage.FileTracer):
24 """A FileTracer emulating a simple static plugin."""
25
26 def __init__(self, filename):
27 """Claim that xyz.py was actually sourced from ABC.zz"""
28 self._filename = filename
29 self._source_filename = os.path.join(
30 "/src",
31 os.path.basename(filename.replace("xyz.py", "ABC.zz"))
32 )
33
34 def source_filename(self):
35 return self._source_filename
36
37 def line_number_range(self, frame):
38 """Map the line number X to X05,X06,X07."""
39 lineno = frame.f_lineno
40 return lineno*100+5, lineno*100+7
41
42
43 class FileReporter(coverage.FileReporter):
44 """Dead-simple FileReporter."""
45 def lines(self):
46 return set([105, 106, 107, 205, 206, 207])
47
48
49 def coverage_init(reg, options): # pylint: disable=unused-argument
50 """Called by coverage to initialize the plugins here."""
51 reg.add_file_tracer(Plugin())
OLDNEW
« 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