Created
July 10, 2019 19:21
-
-
Save matham/333ebf55059bbf824bb7efd1d06a3747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import coverage | |
class KivyCoveragePlugin(coverage.plugin.CoveragePlugin): | |
def file_tracer(self, filename): | |
if filename.endswith('.kv'): | |
return KivyFileTracer(filename=filename) | |
return None | |
def file_reporter(self, filename): | |
print('ree', filename) | |
return KivyFileReporter(filename=filename) | |
def find_executable_files(self, src_dir): | |
for (dirpath, dirnames, filenames) in os.walk(src_dir): | |
for filename in filenames: | |
print(filename) | |
if filename.endswith('.kv'): | |
yield os.path.join(dirpath, filename) | |
class KivyFileTracer(coverage.plugin.FileTracer): | |
filename = '' | |
def __init__(self, filename, **kwargs): | |
super(KivyFileTracer, self).__init__(**kwargs) | |
self.filename = filename | |
def source_filename(self): | |
return self.filename | |
class KivyFileReporter(coverage.plugin.FileReporter): | |
def lines(self): | |
with open(self.filename) as fh: | |
lines = {i + 1 for i, line in enumerate(fh.readlines()) if line.strip()} | |
return lines | |
def coverage_init(reg, options): | |
reg.add_file_tracer(KivyCoveragePlugin()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment