def finalize(self, result): """ Finalize: stop recording coverage info, save & exit. """ figleaf.stop() figleaf.write_coverage(self.figleaf_file, append=False)
def generate_coverage_report(self): """ Generates a coverage report in HTML format. Returns the absolute path to the report file. Note that it is generated in a temp directory, so be sure to either move or delete the report. """ if not has_figleaf: return figleaf.stop() tempdir = tempfile.mkdtemp() coverage_file = os.path.join(tempdir, "coverage.txt") logging.info("Writing coverage to %s" % coverage_file) logging.info("coverage info = %r" % figleaf.get_data()) figleaf.write_coverage(coverage_file) coverage = {} d = figleaf.read_coverage(coverage_file) coverage_data = figleaf.combine_coverage(coverage, d) logging.info("Preparing to write report...") report_dir = os.path.join(tempdir, "figleaf-html-report") if not os.path.exists(report_dir): os.makedirs(report_dir) html_report.report_as_html(coverage_data, report_dir, [ re.compile(".*site-packages.*"), re.compile(".*pubsub.*"), re.compile(".*pew/.*") ], {}) logging.info("Writing report to %s" % report_dir) return os.path.join(report_dir, "index.html")
def stopCoverage(): if figleaf_started is not None: figleaf.stop() figleaf.write_coverage('.figleaf') print "Figleaf stats were written to .figleaf" else: print "Warning: NO coverage written as the debugger was active"
def run(self): if self.coverage: import figleaf figleaf.start() nose.run(argv=['nosetests']) if self.coverage: figleaf.stop() figleaf.write_coverage('.figleaf')
def _run_with_figleaf(self): import figleaf figleaf.start() try: self._run_tests() finally: figleaf.stop() figleaf.write_coverage(self.coverage_summary)
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): setup_test_environment() figleaf.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) figleaf.stop() if not os.path.isdir(os.path.join("temp", "figleaf")): os.mkdir(os.path.join("temp", "figleaf")) file_name = "temp/figleaf/test_output.figleaf" figleaf.write_coverage(file_name) output = commands.getoutput("figleaf2html " + file_name + " --output-directory=temp/figleaf") print output return test_results
def stopCoverage (self): try: import figleaf figleaf.stop() self._log.info("Coverage tracking stopped") path = "/opt/ofelia/ofam/local/log/figleaf.%f.log" % (time.time()) figleaf.write_coverage(path) self._log.info("Coverage written to %s" % (path)) return jsonify({"output-path" : path}) except Exception, e: self._log.exception("Exception") return jsonify(None, code = 2, msg = traceback.format_exc())
def stopCoverage(self): try: import figleaf figleaf.stop() self._log.info("Coverage tracking stopped") path = "/opt/ofelia/ofam/local/log/figleaf.%f.log" % (time.time()) figleaf.write_coverage(path) self._log.info("Coverage written to %s" % (path)) return jsonify({"output-path": path}) except Exception, e: self._log.exception("Exception") return jsonify(None, code=2, msg=traceback.format_exc())
def stop(self): """Stops code coverage.""" try: if self.running: logger.info('Stopping code coverage') figleaf.stop() figleaf.write_coverage(self.filename) self.running = False for k in ['FIGLEAF_DIR', 'USE_FIGLEAF', 'FIGLEAF_PID']: del ExecutionContext.propagate_env_map[k] except Exception, e: logger.error('Error stopping code coverage: %s' % e)
def cover_program(self, program_name): import figleaf cur_trace = sys.gettrace() if os.path.exists('.figleaf_test'): os.remove('.figleaf_test') figleaf.start() self.run_program(program_name) figleaf.stop() figleaf.write_coverage('.figleaf_test', append=False) if hasattr(cur_trace, '__call__'): sys.settrace(cur_trace) elif hasattr(cur_trace, 'start'): cur_trace.start()
def cover_program(self, program_name): import figleaf cur_trace = sys.gettrace() if os.path.exists(".figleaf_test"): os.remove(".figleaf_test") figleaf.start() self.run_program(program_name) figleaf.stop() figleaf.write_coverage(".figleaf_test", append=False) if hasattr(cur_trace, "__call__"): sys.settrace(cur_trace) elif hasattr(cur_trace, "start"): cur_trace.start()
def main(test_dict, test_order): figleaf.start() try: for test in test_order: print '[+]', test_dict[test] Tester(test) except Exception as e: return False else: return True finally: figleaf.stop() figleaf.write_coverage('.figleaf')
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): setup_test_environment() figleaf.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) figleaf.stop() if not os.path.isdir(os.path.join("temp", "figleaf")): os.makedirs(os.path.join("temp", "figleaf")) file_name = "temp/figleaf/test_output.figleaf" figleaf.write_coverage(file_name) output = commands.getoutput("figleaf2html " + file_name + " --output-directory=temp/figleaf") print output return test_results
def pytest_terminal_summary(terminalreporter): config = terminalreporter.config datafile = py.path.local(config.getvalue('figleafdata')) tw = terminalreporter._tw tw.sep('-', 'figleaf') tw.line('Writing figleaf data to %s' % (datafile)) figleaf.stop() figleaf.write_coverage(str(datafile)) coverage = get_coverage(datafile, config) reportdir = py.path.local(config.getvalue('figleafhtml')) tw.line('Writing figleaf html to file://%s' % (reportdir)) figleaf.annotate_html.prepare_reportdir(str(reportdir)) exclude = [] figleaf.annotate_html.report_as_html(coverage, str(reportdir), exclude, {})
from glob import glob from doctest import testmod from sys import modules import figleaf files = glob('datagrid/*.py') + glob('datagrid/*/*.py') figleaf.start() for f in files: name = f.replace('.py','').replace('/','.') __import__(name) testmod(modules[name]) import tests.runner figleaf.stop() figleaf.write_coverage('.figleaf')
alltests = unittest.TestSuite(( encrypt.getTestSuite(), analyzer.getTestSuite(), #index.getTestSuite(), converter.getTestSuite(), library.metadata.getTestSuite(), )) results = unittest.TestResult() alltests.run(results) if results.wasSuccessful(): print "%d tests passed!" % (results.testsRun) else: print "\n%d tests failed!\n" % (len(results.failures)) for error in results.failures: print "------ " + str(error[0]) + " ------" print error[1] for error in results.errors: print "------ " + str(error[0]) + " ------" print error[1] sys.exit(1) if hasFigleaf: figleaf.stop() figleaf.write_coverage(figfile) # generate a spiffy HTML report from this os.system("figleaf2html -d ./tests_code_coverage %s" % figfile)
def close_figleaf(): import figleaf print "Figleaf cleaning up" figleaf.stop() figleaf.write_coverage('.unittest_coverage', append=False)
def save_figleaf_info(): figleaf.stop() figleaf.write_coverage('.figleaf')
def OnExit(self): if has_figleaf: figleaf.stop() figleaf.write_coverage("eclass_library_run.figleaf") return True #wx.PySimpleApp.OnExit(self)
# $Date: 2009/06/02 01:10:00 $ # $Author: Taha Zerrouki $ # $Revision: 0.7 $ # $Source: arabtechies.sourceforge.net # #***********************************************************************/ ##from verb_const import * ##from ar_ctype import * ##from classverb import * import figleaf figleaf.start() from src.verb_const import * from src.ar_verb import * def main(): word = u"تُيُسَّرَ" letters, marks = uniformate_verb(word) marks = DAMMA + DAMMA + SUKUN + KASRA + FATHA newword = standard2(letters, marks) print letters.encode('utf8') print write_harakat_in_full(marks).encode('utf8') print newword.encode('utf8') if __name__ == "__main__": main() figleaf.stop() figleaf.write_coverage('performance.figleaf')
# Restore the old settings. settings.INSTALLED_APPS = old_installed_apps settings.ROOT_URLCONF = old_root_urlconf settings.TEMPLATE_DIRS = old_template_dirs settings.USE_I18N = old_use_i18n settings.LANGUAGE_CODE = old_language_code settings.LOGIN_URL = old_login_url settings.MIDDLEWARE_CLASSES = old_middleware_classes if __name__ == "__main__": from optparse import OptionParser usage = "%prog [options] [model model model ...]" parser = OptionParser(usage=usage) parser.add_option('-v', '--verbosity', action='store', dest='verbosity', default='0', type='choice', choices=['0', '1', '2'], help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') parser.add_option('--noinput', action='store_false', dest='interactive', default=True, help='Tells Django to NOT prompt the user for input of any kind.') parser.add_option('--settings', help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.') options, args = parser.parse_args() if options.settings: os.environ['DJANGO_SETTINGS_MODULE'] = options.settings elif "DJANGO_SETTINGS_MODULE" not in os.environ: parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. " "Set it or use --settings.") django_tests(int(options.verbosity), options.interactive, args) figleaf.stop() figleaf.write_coverage('.figleaf', append=True)
if MODE == 'coverage': # coverage with coverage module, will write to standard output import coverage coverage.erase() coverage.start() import test_all from statlib import stats, pstat suite = test_all.get_suite() unittest.TextTestRunner(verbosity=2).run(suite) coverage.report([stats, pstat]) elif MODE == 'figleaf': # coverage with figleaf, will write to the html directrory import figleaf from figleaf import annotate_html figleaf.start() import test_all from statlib import stats, pstat suite = test_all.get_suite() unittest.TextTestRunner(verbosity=2).run(suite) figleaf.stop() figleaf.write_coverage('.figleaf') data = figleaf.get_data().gather_files() annotate_html.report_as_html(data, 'html', []) else: print 'Invalid mode %s' % mode
if not testRunner.load(): sys.exit(1) success = True try: #2. SETUP testRunner.setup() if coverage_report and coverage_report != 'None': import figleaf figleaf.start() #3. RUN testRunner.run() if coverage_report and coverage_report != 'None': try: figleaf.stop() figleaf.write_coverage(coverage_report) except NameError: pass #4. TEAR-DOWN testRunner.tearDown() except Exception as e: import traceback traceback.print_exc(file=sys.stderr) success = False if coverage_report and coverage_report != 'None': try: figleaf.stop() figleaf.write_coverage(coverage_report) except: pass
## haraka=tuple_verb[2]; ## print transitive.encode("utf8") ## print haraka.encode("utf8"); ##""" ## print transi if not is_valid_infinitive_verb(word): print u"is invalid verb ", print word.encode("utf8") else: future_type=u""+tuple_verb[1]; future_type=get_future_type_entree(future_type); transitive=u""+tuple_verb[2]; if transitive in (u"متعدي",u"م",u"مشترك",u"ك","t","transitive"): transitive=True; else : transitive=False; text=do_sarf(word,future_type,all,past,future,passive,imperative,future_moode,confirmed,transitive,display_format); print text.encode("utf8") if __name__ == "__main__": main() figleaf.stop() figleaf.write_coverage('performance.figleaf')
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): figleaf.start() total_tests = simple.run_tests(test_labels, verbosity, interactive, extra_tests) figleaf.stop() figleaf.write_coverage('.figleaf') return total_tests
sys.exit(1) success = True try: # 2. SETUP testRunner.setup() if coverage_report and coverage_report != "None": import figleaf figleaf.start() # 3. RUN testRunner.run() if coverage_report and coverage_report != "None": try: figleaf.stop() figleaf.write_coverage(coverage_report) except NameError: pass # 4. TEAR-DOWN testRunner.tearDown() except Exception as e: import traceback traceback.print_exc(file=sys.stderr) success = False if coverage_report and coverage_report != "None": try: figleaf.stop() figleaf.write_coverage(coverage_report) except: pass