SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import coverage
  3.  
  4.  
  5. class KivyCoveragePlugin(coverage.plugin.CoveragePlugin):
  6.  
  7.     def file_tracer(self, filename):
  8.         if filename.endswith('.kv'):
  9.             return KivyFileTracer(filename=filename)
  10.         return None
  11.  
  12.     def file_reporter(self, filename):
  13.         print('ree', filename)
  14.         return KivyFileReporter(filename=filename)
  15.  
  16.     def find_executable_files(self, src_dir):
  17.         for (dirpath, dirnames, filenames) in os.walk(src_dir):
  18.             for filename in filenames:
  19.                 print(filename)
  20.                 if filename.endswith('.kv'):
  21.                     yield os.path.join(dirpath, filename)
  22.  
  23.  
  24. class KivyFileTracer(coverage.plugin.FileTracer):
  25.  
  26.     filename = ''
  27.  
  28.     def __init__(self, filename, **kwargs):
  29.         super(KivyFileTracer, self).__init__(**kwargs)
  30.         self.filename = filename
  31.  
  32.     def source_filename(self):
  33.         return self.filename
  34.  
  35.  
  36. class KivyFileReporter(coverage.plugin.FileReporter):
  37.  
  38.     def lines(self):
  39.         with open(self.filename) as fh:
  40.             lines = {i + 1 for i, line in enumerate(fh.readlines()) if line.strip()}
  41.         return lines
  42.  
  43.  
  44. def coverage_init(reg, options):
  45.     reg.add_file_tracer(KivyCoveragePlugin())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top