def doctest(self): import doctest, coverage # (f,t) = doctest.testmod(eval('isconf.Kernel')) # doctest.master.summarize() # sys.exit(f) modules = [] olddir = os.getcwd() os.chdir('lib/python') os.path.walk('.',getmods,modules) os.chdir(olddir) print modules # modules=[rpc822] fail=0 total=0 coverage.erase() coverage.start() for mod in modules: (f,t) = doctest.testmod(mod,report=0) fail += f total += t doctest.master.summarize() coverage.stop() for mod in modules: coverage.analysis(mod) coverage.report(modules) sys.exit(fail)
def doit(): srcdir = os.environ['RTTSrcDir'] pyfiles = glob.glob(os.path.join(srcdir, '*.py')) coverage.erase() coverage.start() run.TestFramework() coverage.stop() coverage.analysis(run) coverage.report(pyfiles) coverage.erase()
def run_tests(self, test_labels, verbosity=1, interactive=True, extra_tests=[]): coveragemodules = getattr(settings, 'COVERAGE_MODULES', []) if coveragemodules: coverage.start() self.setup_test_environment() suite = self.build_suite(test_labels, extra_tests) old_config = self.setup_databases() result = self.run_suite(suite) if coveragemodules: coverage.stop() coveragedir = getattr(settings, 'COVERAGE_DIR', './build/coverage') 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") colorize.colorize_file(f, outstream=fp, not_covered=mf) fp.close() coverage.report(modules, show_missing=0) coverage.erase() self.teardown_databases(old_config) self.teardown_test_environment() return len(result.failures) + len(result.errors)
def writeCoverage(module, oldBase, newBase): filename, numbers, unexecuted, s = coverage.analysis(module) coverFilename = filename + ',cover' if coverFilename.startswith(oldBase): coverFilename = newBase + coverFilename[len(oldBase):] fout = open(coverFilename, 'w') fin = open(filename) i = 1 lines = 0 good = 0 while 1: line = fin.readline() if not line: break assert line[-1] == '\n' fout.write(line[:-1]) unused = i in unexecuted interesting = interestingLine(line, unused) if interesting: if unused: fout.write(' '*(72-len(line))) fout.write('#@@@@') lastUnused = True else: lastUnused = False good += 1 lines += 1 fout.write('\n') i += 1 fout.write('\n# Coverage:\n') fout.write('# %i/%i, %i%%' % ( good, lines, lines and int(good*100/lines))) fout.close() fin.close()
def nose_start(LOG, REPO_PATH): # test names """ Find all python modules in REPO_PATH """ WORKING_DIR = getcwd() chdir(REPO_PATH) coverage.erase() coverage.start() nose.run() coverage.stop() LOG.info(coverage.analysis(nose)) LOG.info(coverage.report()) chdir(WORKING_DIR)
def runTests(testModules=None, profileOut=None, coverageOutDir=None): if coverageOutDir is not None: if not os.path.exists(coverageOutDir): os.makedirs(coverageOutDir) coverage.erase() coverage.start() alltests = unittest.TestLoader().loadTestsFromNames(testModules) if profileOut is not None: results = Profiler().profile(alltests) results.sort() results.reverse() out = open(profileOut, 'w') for result in results: out.write("%s \t%3.6f\n" % (result[1], result[0])) print "unittest profiling information written in " + profileOut out.close() else: # if we don't add this else the tests are run twice unittest.TextTestRunner().run(alltests) if coverageOutDir is not None: coverage.stop() modules = glob('../*.py') #modules.remove('../__init__.py') for module in modules: f, s, m, mf = coverage.analysis(module) out = file(join(coverageOutDir, os.path.basename(f) + '.html'), 'wb') colorize.colorize_file(f, outstream=out, not_covered=mf) out.close() print coverageReportTxt = file(join(coverageOutDir, "coverage.txt"), 'w') coverage.report(modules, show_missing=False, omit_prefixes=['__'], file=coverageReportTxt) coverageReportTxt.close() coverage.report(modules, show_missing=False, omit_prefixes=['__']) coverage.erase() coverageReportTxt.close() print print "Coverage information updated in " + coverageOutDir print import webbrowser webbrowser.open('file://' + join(getcwd(), coverageOutDir))
def get_coverage(modules, covered_lines): topdir = get_topdir() import coverage # Compile the expressions in COVERED_LINES covered_lines = [(lines, re.compile(pattern)) for (lines, pattern) in covered_lines] # Get the coverage statistics stats = [] for module in modules: (filename, stmtlines, stmtmissed, stmtmissed_desc) = coverage.analysis(module) filename = canonical_path(filename) if filename.startswith(topdir): filename = filename[len(topdir) + 1:] lines = open(filename).readlines() linenum = len(lines) # Remove whitelisted lines stmtmissed = [linenum for linenum in stmtmissed if not check_whitelist(lines, linenum, covered_lines)] # Sort the lines (probably already in order, but let's double-check) stmtlines.sort() stmtmissed.sort() # Build a compressed list of ranges of lines which have no statements # which were executed, but do contain statements. missed_ranges = [] stmtpos = 0 currrange = None for linenum in stmtmissed: while stmtlines[stmtpos] < linenum: # If there are any statements before the current linenum, we # end the current range of missed statements currrange = None stmtpos += 1 if currrange is None: currrange = [linenum, linenum] missed_ranges.append(currrange) else: currrange[1] = linenum stmtpos += 1 percent = (len(stmtlines) - len(stmtmissed)) * 100.0 / len(stmtlines) stats.append((filename, percent, len(stmtlines), missed_ranges)) return stats
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
def runTests(testModules=None, profileOut=None, coverageOutDir=None): if coverageOutDir is not None: if not os.path.exists(coverageOutDir): os.makedirs(coverageOutDir) coverage.erase() coverage.start() alltests = unittest.TestLoader().loadTestsFromNames(testModules) if profileOut is not None: results = Profiler().profile(alltests) results.sort() results.reverse() out = open(profileOut, 'w') for result in results: out.write("%s \t%3.6f\n" % (result[1], result[0])) print "unittest profiling information written in " + profileOut out.close() else: # if we don't add this else the tests are run twice unittest.TextTestRunner().run(alltests) if coverageOutDir is not None: coverage.stop() modules = glob('../pytof/*.py') modules.remove('../pytof/__init__.py') for module in modules: f, s, m, mf = coverage.analysis(module) out = file(join(coverageOutDir, os.path.basename(f)+'.html'), 'wb') colorize.colorize_file(f, outstream=out, not_covered=mf) out.close() print coverageReportTxt = file(join(coverageOutDir, "coverage.txt"), 'w') coverage.report(modules, show_missing=False, omit_prefixes=['__'], file=coverageReportTxt) coverageReportTxt.close() coverage.report(modules, show_missing=False, omit_prefixes=['__']) coverage.erase() coverageReportTxt.close() print print "Coverage information updated in " + coverageOutDir print import webbrowser webbrowser.open('file://' + join(getcwd(), coverageOutDir))
def test_simple(self): coverage.erase() self.make_file("mycode.py", """\ a = 1 b = 2 if b == 3: c = 4 d = 5 """) # Import the Python file, executing it. self.start_import_stop(coverage, "mycode") _, statements, missing, missingtext = coverage.analysis("mycode.py") self.assertEqual(statements, [1,2,3,4,5]) self.assertEqual(missing, [4]) self.assertEqual(missingtext, "4")
def test_simple(self): coverage.erase() self.make_file( "mycode.py", """\ a = 1 b = 2 if b == 3: c = 4 d = 5 """) # Import the Python file, executing it. self.start_import_stop(coverage, "mycode") _, statements, missing, missingtext = coverage.analysis("mycode.py") self.assertEqual(statements, [1, 2, 3, 4, 5]) self.assertEqual(missing, [4]) self.assertEqual(missingtext, "4")
def testSimple(self): coverage.erase() self.make_file("mycode.py", """\ a = 1 b = 2 if b == 3: c = 4 d = 5 """) # Import the python file, executing it. coverage.start() self.import_module("mycode") # pragma: recursive coverage coverage.stop() # pragma: recursive coverage _, statements, missing, missingtext = coverage.analysis("mycode.py") self.assertEqual(statements, [1,2,3,4,5]) self.assertEqual(missing, [4]) self.assertEqual(missingtext, "4")
def test_simple(self): coverage.erase() self.make_file("mycode.py", """\ a = 1 b = 2 if b == 3: c = 4 d = 5 """) # Import the python file, executing it. coverage.start() self.import_local_file("mycode") # pragma: recursive coverage coverage.stop() # pragma: recursive coverage _, statements, missing, missingtext = coverage.analysis("mycode.py") self.assertEqual(statements, [1,2,3,4,5]) self.assertEqual(missing, [4]) self.assertEqual(missingtext, "4")
def run_tests(self, test_labels, verbosity=1, interactive=True, extra_tests=[]): coveragemodules = getattr(settings, 'COVERAGE_MODULES', []) if coveragemodules: coverage.start() self.setup_test_environment() suite = self.build_suite(test_labels, extra_tests) old_config = self.setup_databases() result = self.run_suite(suite) if coveragemodules: coverage.stop() coveragedir = getattr(settings, 'COVERAGE_DIR', './build/coverage') 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") colorize.colorize_file(f, outstream=fp, not_covered=mf) fp.close() coverage.report(modules, show_missing=0) coverage.erase() self.teardown_databases(old_config) self.teardown_test_environment() return len(result.failures) + len(result.errors)
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()
if __name__ == "__main__": if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _OGMultiPoint from _OGMultiPoint import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_OGMultiPoint) print "\n" coverage.report(_OGMultiPoint)
if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _Point from _Point import * import _Box from _Box import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_Box) print "\n" coverage.report(_Box)
if __name__ == "__main__": if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _OGMultiLineString from _OGMultiLineString import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_OGMultiLineString) print "\n" coverage.report(_OGMultiLineString)
if __name__ == "__main__": if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _OGLineString from _OGLineString import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_OGLineString) print "\n" coverage.report(_OGLineString)
if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _Point from _Point import * import _LineSeg from _LineSeg import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_LineSeg) print "\n" coverage.report(_LineSeg)
if __name__ == "__main__": if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _OGMultiPolygon from _OGMultiPolygon import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_OGMultiPolygon) print "\n" coverage.report(_OGMultiPolygon)
def main(): """Main testing interface""" parser = OptionParser(add_help_option=False) parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Run tests verbosely") parser.add_option("-q", "--quiet", action="store_true", dest="quiet", help="Silent output (on success)") parser.add_option("-s", "--stop", action="store_true", dest="stop", help="Stop") parser.add_option("-d", "--debug", action="store_true", dest="debug", help="Debug (drop into PDB)") parser.add_option("-p", "--package", action="append", type="string", dest="package", help="Only run tests for a specific package. (E.g: elf or weaver)") (options, args) = parser.parse_args() if args == []: args = glob.glob("test_*.py") args.sort() passed = True # If a test fails set this to false for test_file in args: test_module = os.path.splitext(test_file)[0] fp, pathname, description = imp.find_module(test_module) start_coverage() module = imp.load_module(test_module, fp, pathname, description) result = unittest.TestResult() tested_modules = getattr(module, "modules_under_test", []) if options.package: skip = False for test_mod in tested_modules: package = test_mod.__name__.split(".")[0] if package not in options.package: skip = True break if skip: continue suite = unittest.defaultTestLoader.loadTestsFromModule(module) if options.debug: try: suite.debug() except: traceback.print_exc() _, _, tb = sys.exc_info() pdb.post_mortem(tb) sys.exit() else: suite.run(result) # Reload the modules under test for module in tested_modules: bits = module.__name__.split(".") module_name = bits[-1] if len(bits) > 1: path = [os.path.dirname(module.__file__)] else: path = None try: fp, pathname, description = imp.find_module(module_name, path) except ImportError: pdb.set_trace() print "Error loading", module, path imp.load_module(module_name + "_loaded_for_test", fp, pathname, description) coverage.stop() # Determine which modules do not have 100% coverage. Print # coverage reports on those modules. coverage_print = [] for mod in tested_modules: if len(coverage.analysis(mod)[2]): coverage_print.append(mod) # Result if not result.wasSuccessful() or coverage_print: print ">>> %s" % test_file if not result.wasSuccessful(): for _t, err in result.errors + result.failures: print "=" * 80 print _t print "=" * 80 print err passed = False if coverage_print: coverage.report(coverage_print) print sys.exit(not passed) # If a test failures return a non-zero return code
if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 from _Point import * from _LineSeg import * import _Polygon from _Polygon import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_Polygon) print "\n" coverage.report(_Polygon)
if __name__ == "__main__": if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _OGGeometryCollection from _OGGeometryCollection import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_OGGeometryCollection) print "\n" coverage.report(_OGGeometryCollection)
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
try: import coverage coverage.erase() coverage.start() COVERAGE = 1 from _Point import * from _LineSeg import * import _Polygon from _Polygon import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_Polygon) print "\n" coverage.report(_Polygon)
try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _Point from _Point import * import _Box from _Box import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_Box) print "\n" coverage.report(_Box)
if __name__ == "__main__": import os if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _PsycopgInit except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_PsycopgInit) print "\n" coverage.report(_PsycopgInit)
if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import GeoTypes except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(GeoTypes) print "\n" coverage.report(GeoTypes)
if __name__ == "__main__": if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _OGLinearRing from _OGLinearRing import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_OGLinearRing) print "\n" coverage.report(_OGLinearRing)
if __name__ == "__main__": if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _Point from _Point import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_Point) print "\n" coverage.report(_Point)
if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _Point from _Point import * import _Circle from _Circle import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_Circle) print "\n" coverage.report(_Circle)
if __name__ == "__main__": import os if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import GeoTypes except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(GeoTypes) print "\n" coverage.report(GeoTypes)
try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _Point from _Point import * import _Circle from _Circle import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_Circle) print "\n" coverage.report(_Circle)
if __name__ == "__main__": if os.environ.get('USECOVERAGE') == '1': try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _OGPoint from _OGPoint import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_OGPoint) print "\n" coverage.report(_OGPoint)
prog = testprogram.TestProgram( MODULE_NAMES, testRunner=test_runner, localServerProcess=testprogram.TwistedServerProcess(), ) result = prog.runTests() if run_coverage: # HTML coverage report import colorize try: os.mkdir("coverage") except OSError: pass private_modules = glob.glob("mechanize/_*.py") private_modules.remove("mechanize/__init__.py") for module_filename in private_modules: module_name = module_filename.replace("/", ".")[:-3] print module_name module = sys.modules[module_name] f, s, m, mf = coverage.analysis(module) fo = open(os.path.join('coverage', os.path.basename(f) + '.html'), 'wb') colorize.colorize_file(f, outstream=fo, not_covered=mf) fo.close() coverage.report(module) #print coverage.analysis(module) # XXX exit status is wrong -- does not take account of doctests sys.exit(not result.wasSuccessful())
if __name__ == "__main__": if os.environ.get("USECOVERAGE") == "1": try: import coverage coverage.erase() coverage.start() COVERAGE = 1 import _OGLinearRing from _OGLinearRing import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get("USEPYCHECK") == "1": try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_OGLinearRing) print "\n" coverage.report(_OGLinearRing)
import coverage coverage.erase() coverage.start() COVERAGE = 1 from _Point import * from _LineSeg import * import _Path from _Path import * except: print "Error setting up coverage checking" COVERAGE = 0 else: COVERAGE = 0 if os.environ.get('USEPYCHECK') == '1': try: import pychecker.checker except: print "Pychecker not installed on this machine" unittest.TextTestRunner().run(testSuite()) if COVERAGE: coverage.stop() x = coverage.analysis(_Path) print "\n" coverage.report(_Path)