Beispiel #1
0
def my_run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    """
    Run the unit tests for all the test labels in the provided list.
    Labels must be of the form:
     - app.TestClass.test_method
        Run a single specific test method
     - app.TestClass
        Run all the test methods in a given class
     - app
        Search for doctests and unittests in the named application.

    When looking for tests, the test runner will look in the models and
    tests modules for the application.

    A list of 'extra' tests may also be provided; these tests
    will be added to the test suite.

    Returns the number of tests that failed.
    """
    coveragemodules = []
    if hasattr(settings, 'COVERAGE_MODULES'):
        coveragemodules = settings.COVERAGE_MODULES
    if coveragemodules:
        coverage.start()

    result = run_tests(test_labels, verbosity, interactive, extra_tests)

    if coveragemodules:
        coverage.stop()
        coveragedir = './build/coverage'
        if hasattr(settings, 'COVERAGE_DIR'):
            coveragedir = settings.COVERAGE_DIR
        if not os.path.exists(coveragedir):
            os.makedirs(coveragedir)
        modules = []
        for module_string in coveragemodules:
            module = __import__(module_string, globals(), locals(), [""])
            modules.append(module)
            f,s,m,mf = coverage.analysis(module)
            fp = file(os.path.join(coveragedir, module_string + ".html"), "wb")
            coverage_color.colorize_file(f, outstream=fp, not_covered=mf)
            fp.close()
        coverage.the_coverage.report(modules, show_missing=1)
        coverage.erase()

    return result
Beispiel #2
0
def main():
    try:
        cov_idx = sys.argv.index('--cov')
    except ValueError:
        coverage = None
    else:
        del sys.argv[cov_idx]
        try:
            import coverage
        except ImportError:
            sys.stderr.write('''\
Please install "coverage" module to collect coverage. Try typing:
sudo easy_install coverage
''')
            sys.exit(1)
        import coverage_color
        coverage.start()
    global akshell, script
    akshell = __import__('akshell')
    script = __import__('script')
    try:
        server_idx = sys.argv.index('--server')
    except ValueError:
        pass
    else:
        akshell.SERVER = sys.argv[server_idx + 1]
        del sys.argv[server_idx : server_idx + 2]
    try:
        unittest.main(defaultTest='suite')
    finally:
        if coverage:
            coverage.stop()
            for module in (akshell, script):
                path, stmts_, missing_, missing_str = coverage.analysis(module)
                with open('coverage_%s.html' % module.__name__, 'w') as f:
                    coverage_color.colorize_file(path, f, missing_str)
            coverage.report([akshell, script], show_missing=False)
            coverage.erase()
Beispiel #3
0
	suites = []
	for m in allModules:
		suites.append(m.suite())
	
	return unittest.TestSuite(suites)

if __name__ == "__main__":
	COVERAGE_DIR = "coverage" # Where the HTML output should go
	COVERAGE_MODULES = ["Peach",
						"Peach.Engine.parser",
						"Peach.Engine.engine",
						"Peach.Engine.incoming",
						"Peach.Engine.dom",
						"Peach.Engine.state"
						] # The modules that you want colorized
	runner = unittest.TextTestRunner()
	coverage.start()
	runner.run(suite())
	coverage.stop()
	if not os.path.exists(COVERAGE_DIR):
		os.makedirs(COVERAGE_DIR)
	for module_string in COVERAGE_MODULES:
		module = __import__(module_string, globals(), locals(), [""])
		f,s,m,mf = coverage.analysis(module)
		fp = file(os.path.join(COVERAGE_DIR, module_string + ".html"), "wb")
		coverage_color.colorize_file(f, outstream=fp, not_covered=mf)
		fp.close()
	coverage.erase()

# end