tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

coveragetest.py (1942B)


      1 #!/usr/bin/env vpython3
      2 # Copyright 2017 The Chromium Authors
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 """Ensure files in the directory are thoroughly tested."""
      6 
      7 import importlib
      8 import io
      9 import os
     10 import sys
     11 import unittest
     12 
     13 import coverage  # pylint: disable=import-error
     14 
     15 # The files need to have sufficient coverages.
     16 COVERED_FILES = [
     17    'compatible_utils.py', 'deploy_to_fuchsia.py', 'flash_device.py',
     18    'log_manager.py', 'publish_package.py', 'serve_repo.py'
     19 ]
     20 
     21 # The files will be tested without coverage requirements.
     22 TESTED_FILES = [
     23    'bundled_test_runner.py', 'common.py', 'ffx_emulator.py',
     24    'modification_waiter.py', 'monitors.py', 'serial_boot_device.py',
     25    'test_env_setup.py', 'test_server.py', 'version.py'
     26 ]
     27 
     28 
     29 def main():
     30    """Gather coverage data, ensure included files are 100% covered."""
     31 
     32    # Fuchsia tests not supported on Windows
     33    if os.name == 'nt':
     34        return 0
     35 
     36    cov = coverage.coverage(data_file=None,
     37                            include=COVERED_FILES,
     38                            config_file=True)
     39    cov.start()
     40 
     41    for file in COVERED_FILES + TESTED_FILES:
     42        print('Testing ' + file + ' ...')
     43        # pylint: disable=import-outside-toplevel
     44        # import tests after coverage start to also cover definition lines.
     45        module = importlib.import_module(file.replace('.py', '_unittests'))
     46        # pylint: enable=import-outside-toplevel
     47 
     48        tests = unittest.TestLoader().loadTestsFromModule(module)
     49        if not unittest.TextTestRunner().run(tests).wasSuccessful():
     50            return 1
     51 
     52    cov.stop()
     53    outf = io.StringIO()
     54    percentage = cov.report(file=outf, show_missing=True)
     55    if int(percentage) != 100:
     56        print(outf.getvalue())
     57        print('FATAL: Insufficient coverage (%.f%%)' % int(percentage))
     58        return 1
     59    return 0
     60 
     61 
     62 if __name__ == '__main__':
     63    sys.exit(main())