Skip to content

Instantly share code, notes, and snippets.

@matham
Created July 10, 2019 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matham/333ebf55059bbf824bb7efd1d06a3747 to your computer and use it in GitHub Desktop.
Save matham/333ebf55059bbf824bb7efd1d06a3747 to your computer and use it in GitHub Desktop.
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