OLD | NEW |
(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 for testing.""" |
| 13 def file_tracer(self, filename): |
| 14 if "render.py" in filename: |
| 15 return RenderFileTracer() |
| 16 |
| 17 def file_reporter(self, filename): |
| 18 return FileReporter(filename) |
| 19 |
| 20 |
| 21 class RenderFileTracer(coverage.FileTracer): |
| 22 """A FileTracer using information from the caller.""" |
| 23 |
| 24 def has_dynamic_source_filename(self): |
| 25 return True |
| 26 |
| 27 def dynamic_source_filename(self, filename, frame): |
| 28 if frame.f_code.co_name != "render": |
| 29 return None |
| 30 source_filename = os.path.abspath(frame.f_locals['filename']) |
| 31 return source_filename |
| 32 |
| 33 def line_number_range(self, frame): |
| 34 lineno = frame.f_locals['linenum'] |
| 35 return lineno, lineno+1 |
| 36 |
| 37 |
| 38 class FileReporter(coverage.FileReporter): |
| 39 """A goofy file reporter.""" |
| 40 def lines(self): |
| 41 # Goofy test arrangement: claim that the file has as many lines as the |
| 42 # number in its name. |
| 43 num = os.path.basename(self.filename).split(".")[0].split("_")[1] |
| 44 return set(range(1, int(num)+1)) |
| 45 |
| 46 |
| 47 def coverage_init(reg, options): # pylint: disable=unused-argument |
| 48 """Called by coverage to initialize the plugins here.""" |
| 49 reg.add_file_tracer(Plugin()) |
OLD | NEW |