mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
Minor styling fixes for test coverage script
This commit is contained in:
parent
5016087d5c
commit
733a4fd139
@ -35,13 +35,13 @@ import unittest
|
|||||||
from plinth import tests
|
from plinth import tests
|
||||||
|
|
||||||
|
|
||||||
# project directories with testable source code
|
# Project directories with testable source code
|
||||||
SOURCE_DIRS = ['plinth'] + glob.glob('plinth/modules/*')
|
SOURCE_DIRS = ['plinth'] + glob.glob('plinth/modules/*')
|
||||||
|
|
||||||
# files to exclude from coverage analysis and reporting
|
# Files to exclude from coverage analysis and reporting
|
||||||
FILES_TO_OMIT = ['plinth/tests/*.py']
|
FILES_TO_OMIT = ['plinth/tests/*.py']
|
||||||
|
|
||||||
# location of coverage HTML report files
|
# Location of coverage HTML report files
|
||||||
COVERAGE_REPORT_DIR = 'plinth/tests/coverage/report'
|
COVERAGE_REPORT_DIR = 'plinth/tests/coverage/report'
|
||||||
|
|
||||||
|
|
||||||
@ -50,59 +50,55 @@ class TestCoverageCommand(setuptools.Command):
|
|||||||
Subclass of setuptools Command to perform code test coverage analysis.
|
Subclass of setuptools Command to perform code test coverage analysis.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
description = "Run test coverage analysis"
|
description = 'Run test coverage analysis'
|
||||||
user_options = [
|
user_options = [
|
||||||
('test-module=', 't', "Explicitly specify a single module to test")
|
('test-module=', 't', 'Explicitly specify a single module to test')
|
||||||
]
|
]
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
"""
|
"""Initialize options to default values."""
|
||||||
Initialize options to default values.
|
|
||||||
"""
|
|
||||||
self.test_module = None
|
self.test_module = None
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""Main command implementation."""
|
||||||
Main command implementation.
|
|
||||||
"""
|
|
||||||
if self.distribution.install_requires:
|
if self.distribution.install_requires:
|
||||||
self.distribution.fetch_build_eggs(
|
self.distribution.fetch_build_eggs(
|
||||||
self.distribution.install_requires)
|
self.distribution.install_requires)
|
||||||
|
|
||||||
# erase any existing HTML report files
|
|
||||||
if self.distribution.tests_require:
|
if self.distribution.tests_require:
|
||||||
self.distribution.fetch_build_eggs(self.distribution.tests_require)
|
self.distribution.fetch_build_eggs(self.distribution.tests_require)
|
||||||
|
|
||||||
|
# Erase any existing HTML report files
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(COVERAGE_REPORT_DIR, True)
|
shutil.rmtree(COVERAGE_REPORT_DIR, True)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# initialize a test suite for one or all modules
|
# Initialize a test suite for one or all modules
|
||||||
if self.test_module is None:
|
if self.test_module is None:
|
||||||
test_suite = tests.TEST_SUITE
|
test_suite = tests.TEST_SUITE
|
||||||
else:
|
else:
|
||||||
test = unittest.defaultTestLoader.\
|
test = unittest.defaultTestLoader.loadTestsFromNames(
|
||||||
loadTestsFromNames([self.test_module])
|
[self.test_module])
|
||||||
test_suite = unittest.TestSuite(test)
|
test_suite = unittest.TestSuite(test)
|
||||||
|
|
||||||
# run the coverage analysis
|
# Run the coverage analysis
|
||||||
runner = unittest.TextTestRunner()
|
runner = unittest.TextTestRunner()
|
||||||
import coverage
|
import coverage
|
||||||
cov = coverage.coverage(auto_data=True, branch=True,
|
cov = coverage.coverage(auto_data=True, branch=True,
|
||||||
source=SOURCE_DIRS, omit=FILES_TO_OMIT)
|
source=SOURCE_DIRS, omit=FILES_TO_OMIT)
|
||||||
cov.erase() # erase existing coverage data file
|
cov.erase() # Erase existing coverage data file
|
||||||
cov.start()
|
cov.start()
|
||||||
runner.run(test_suite)
|
runner.run(test_suite)
|
||||||
cov.stop()
|
cov.stop()
|
||||||
|
|
||||||
# generate an HTML report and print overall coverage
|
# Generate an HTML report and print overall coverage
|
||||||
html_report_title = ("FreedomBox:Plinth -- Test Coverage as of " +
|
html_report_title = 'FreedomBox:Plinth -- Test Coverage as of ' + \
|
||||||
time.strftime("%x %X %Z"))
|
time.strftime('%x %X %Z')
|
||||||
_coverage = cov.html_report(directory=COVERAGE_REPORT_DIR,
|
_coverage = cov.html_report(directory=COVERAGE_REPORT_DIR,
|
||||||
omit=FILES_TO_OMIT,
|
omit=FILES_TO_OMIT,
|
||||||
title=html_report_title)
|
title=html_report_title)
|
||||||
print('''\nOverall test coverage: {0:.2f} %\n'''.format(_coverage))
|
print('\nOverall test coverage: {0:.2f} %\n'.format(_coverage))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user