def test_noexclude_stdlib(self): """Check that stdlib files are covered if not excluded. Only works for python >= 2.5, because of some changes in the way frame objs f_code.co_filename is reported. """ if version_string in ('2.3', '2.4'): # CTB return figleaf.start(ignore_python_lib=False) os.path.dirname('/some/weird/path') # use some stdlib code figleaf.stop() coverage = figleaf.get_data().gather_files() print 'sysdir is:', sysdir found = False for k in coverage: print 'checking:', k if k.startswith(sysdir): found = True break assert found
def runCoverage(params, remoteHost, session): from MaKaC.services.interface.rpc.process import lookupHandler methodList = params['methodList'] results = {} import figleaf import cPickle for (methodName, args) in methodList: handler = lookupHandler(methodName) error = None result = None figleaf.start() try: if hasattr(handler, "process"): result = handler(args, remoteHost, session).process() else: result = handler(args, remoteHost, session) except Exception, e: error = "%s: %s" % (e.__class__, str(e)) results[methodName] = { 'parameters': args, 'result': result, 'error': error }
def _run_with_figleaf(self): import figleaf figleaf.start() try: self._run_tests() finally: figleaf.stop() figleaf.write_coverage(self.coverage_summary)
def start_coverage_tests(): """ Starts code coverage monitoring during the tests. This is a module function so that we can start coverage reporting as soon as possible after the app starts, even before the app and test runner is fully initialized. """ if has_figleaf: figleaf.start(ignore_python_lib=True)
def run(self): if self.coverage: import figleaf figleaf.start() nose.run(argv=['nosetests']) if self.coverage: figleaf.stop() figleaf.write_coverage('.figleaf')
def startCoverage(self): try: import figleaf self._log.info("Starting coverage tracking") figleaf.start() return jsonify(None) except Exception, e: self._log.exception("Exception") return jsonify(None, code=2, msg=traceback.format_exc())
def startCoverage (self): try: import figleaf self._log.info("Starting coverage tracking") figleaf.start() return jsonify(None) except Exception, e: self._log.exception("Exception") return jsonify(None, code = 2, msg = traceback.format_exc())
def test(): figleaf.start() common() figleaf.start_section('a') a() figleaf.stop_section() common2() figleaf.start_section('b') b() figleaf.start_section('c') c() figleaf.stop() in_common = set() union = set() expected = dict(a = set([17, 18, 11, 14]), b = set([22, 11, 21, 14]), c = set([25, 26, 11, 14])) for i in ('a', 'b', 'c'): actual = figleaf.get_info(section_name=i).get(thisfile()) print '******', thisfile() print 'section:', i, '; lines:', actual print expected[i] x = list(expected[i]) x.sort() y = list(actual) y.sort() print x, y assert x == y # note: depends on absolute line no. # so don't shift lines in this file ;) if not in_common: in_common.update(actual) else: in_common.intersection_update(actual) union.update(actual) in_common = list(in_common) in_common.sort() print 'common:', in_common assert in_common == [11, 14] union = list(union) union.sort() print 'union:', union assert union == [11, 14, 17, 18, 21, 22, 25, 26]
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 test_noexclude_misc_path(self): "Check that tests/tst_exclude1.py is covered, if no excl specified" figleaf.init(None, None) figleaf.start() execfile('tests/tst_exclude1.py') figleaf.stop() coverage = figleaf.get_data().gather_files() assert 'tests/tst_exclude1.py' in coverage.keys()
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 start(self): """Starts coverage collection if the environment variable USE_FIGLEAF is set.""" try: if os.getenv('USE_FIGLEAF', None): logger.info('Code coverage will be generated') MakeDir(os.path.dirname(self.filename)).run() self.running = True ExecutionContext.propagate_env_map.update({'FIGLEAF_DIR': os.getenv('FIGLEAF_DIR', self.directory), 'USE_FIGLEAF': 1, 'FIGLEAF_PID': self.main_pid }) figleaf.start() except Exception, e: logger.error('Error starting code coverage: %s' % e)
def test_include_misc_path(self): "Check that tests/tst_include1.py is the only thing covered, if set" figleaf.init(None, 'tests') figleaf.start() execfile('tests/tst_include1.py') figleaf.stop() coverage = figleaf.get_data().gather_files() assert 'tests/tst_include1.py' in coverage.keys() assert len(coverage) == 1
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 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 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 start_coverage(): import figleaf from figleaf import annotate_html # Fix for figleaf misbehaving. It is adding a logger at root level # and that will add a handler to all subloggers (ours as well) # needs to be fixed in figleaf import logging root = logging.getLogger() # remove all root handlers for hand in root.handlers: root.removeHandler(hand) figleaf.start()
def test_exclude_misc_path(self): "Check that tests/tst_exclude1.py is not covered, if excl specified" testspath = os.path.abspath('tests/') print 'IGNORING', testspath figleaf.init(testspath, None) figleaf.start() execfile('tests/tst_exclude1.py') figleaf.stop() coverage = figleaf.get_data().gather_files() print coverage.keys() assert not 'tests/tst_exclude1.py' in coverage.keys()
def test_exclude_stdlib(self): "Check that stdlib files are not covered if excluded." if version_string in ('2.3', '2.4'): # CTB return ### first check that they would be covered ordinarily! figleaf.start(ignore_python_lib=False) os.path.dirname('/some/weird/path') # use some stdlib code figleaf.stop() coverage = figleaf.get_data().gather_files() print 'sysdir is:', sysdir found = False for k in coverage: print 'checking:', k if k.startswith(sysdir): found = True break assert found # this will fail in 2.3, 2.4 ### ok, now check that they're ignored properly. figleaf._t = None # RESET figleaf.start(ignore_python_lib=True) os.path.dirname('/some/weird/path') # use some stdlib code figleaf.stop() coverage = figleaf.get_data().gather_files() for k in coverage: # posixpath & threading somehow evade the discrimination!? if k.startswith(sysdir) and (k.endswith('posixpath.py') or k.endswith('threading.py')): continue assert not k.startswith(sysdir), '%s starts with %s' % (k, sysdir,)
def start_figleaf(close_at_exit = False): try: import figleaf if sys.gettrace() is None: if os.path.exists('.unittest_coverage'): os.unlink('.unittest_coverage') print "starting figleaf in directory:", os.getcwd() figleaf.start() if close_at_exit: import atexit atexit.register(close_figleaf) return True except Exception: pass return False
def start_figleaf(close_at_exit=False): try: import figleaf if sys.gettrace() is None: if os.path.exists('.unittest_coverage'): os.unlink('.unittest_coverage') print "starting figleaf in directory:", os.getcwd() figleaf.start() if close_at_exit: import atexit atexit.register(close_figleaf) return True except Exception: pass return False
def generate_coverage(func, path, *args, **kwds): """ Generates code coverage for the function and places the results in the path """ import figleaf from figleaf import annotate_html # Fix for figleaf misbehaving. It is adding a logger at root level # and that will add a handler to all subloggers (ours as well) # needs to be fixed in figleaf import logging root = logging.getLogger() # remove all root handlers for hand in root.handlers: root.removeHandler(hand) if os.path.isdir(path): shutil.rmtree(path) info("collecting coverage information") figleaf.start() # execute the function itself return_vals = func(*args, **kwds) figleaf.stop() info('generating coverage') coverage = figleaf.get_data().gather_files() annotate_html.prepare_reportdir(path) # skip python modules and the test modules regpatt = lambda patt: re.compile(patt, re.IGNORECASE) patterns = map(regpatt, ['python', 'tests', 'django', 'path*']) annotate_html.report_as_html(coverage, path, exclude_patterns=patterns, files_list='') return return_vals
def test_dos_eol(): """ Make sure that we can annotate files with DOS EOL characters in them. """ import figleaf, figleaf.annotate_html figleaf.start() execfile(os.path.join(thisdir, "tst_dos_eol.py")) figleaf.stop() coverage = figleaf.get_data().gather_files() tmpdir = tempfile.mkdtemp(".figleaf") try: figleaf.annotate_html.report_as_html(coverage, tmpdir, [], {}) finally: files = glob.glob("%s/*" % (tmpdir,)) for f in files: os.unlink(f) os.rmdir(tmpdir)
def generate_coverage( func, path, *args, **kwds): """ Generates code coverage for the function and places the results in the path """ import figleaf from figleaf import annotate_html # Fix for figleaf misbehaving. It is adding a logger at root level # and that will add a handler to all subloggers (ours as well) # needs to be fixed in figleaf import logging root = logging.getLogger() # remove all root handlers for hand in root.handlers: root.removeHandler(hand) if os.path.isdir( path ): shutil.rmtree( path ) info( "collecting coverage information" ) figleaf.start() # execute the function itself return_vals = func( *args, **kwds) figleaf.stop() info( 'generating coverage' ) coverage = figleaf.get_data().gather_files() annotate_html.prepare_reportdir( path ) # skip python modules and the test modules regpatt = lambda patt: re.compile( patt, re.IGNORECASE ) patterns = map( regpatt, [ 'python', 'tests', 'django', 'path*' ] ) annotate_html.report_as_html( coverage, path, exclude_patterns=patterns, files_list='') return return_vals
def test_exclude_stdlib(self): "Check that stdlib files are not covered if excluded." if version_string in ('2.3', '2.4'): # CTB return ### first check that they would be covered ordinarily! figleaf.start(ignore_python_lib=False) os.path.dirname('/some/weird/path') # use some stdlib code figleaf.stop() coverage = figleaf.get_data().gather_files() found = False for k in coverage: print k if k.startswith(sysdir): found = True break assert found # this will fail in 2.3, 2.4 ### ok, now check that they're ignored properly. figleaf._t = None # RESET figleaf.start(ignore_python_lib=True) os.path.dirname('/some/weird/path') # use some stdlib code figleaf.stop() coverage = figleaf.get_data().gather_files() for k in coverage: assert not k.startswith(sysdir)
def __init__(self, app): URLInterceptor.__init__(self, app) import figleaf figleaf.start()
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')
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
def test(): figleaf.start() common() figleaf.start_section('a') a() figleaf.stop_section() common2() figleaf.start_section('b') b() figleaf.start_section('c') c() figleaf.stop() in_common = set() union = set() expected = dict(a = set([17, 18, 11, 14]), b = set([11, 14, 21, 22]), c = set([11, 14, 25, 26])) expected_in_common = [11, 14] expected_union = [11, 14, 17, 18, 21, 22, 25, 26] if figleaf.internals.PythonCollector is not figleaf.internals.Collector: expected['a'].update([40, 42, 43, 44, 45, 47]) expected['b'].update([40, 42, 45, 47, 48, 49]) expected['c'].update([40, 42, 45, 47, 50, 51]) expected_in_common += [40, 42, 45, 47] expected_union += [40, 42, 43, 44, 45, 47, 48, 49, 50, 51] for i in ('a', 'b', 'c'): actual = figleaf.get_info(section_name=i).get(thisfile()) print '******', thisfile() print 'section:', i, '; lines:', actual print expected[i] x = list(expected[i]) x.sort() y = list(actual) y.sort() print x, y assert x == y # note: depends on absolute line no. # so don't shift lines in this file ;) if not in_common: in_common.update(actual) else: in_common.intersection_update(actual) union.update(actual) in_common = list(in_common) in_common.sort() print 'common:', in_common assert in_common == expected_in_common union = list(union) union.sort() print 'union:', union assert union == expected_union
# # ----------------- # Revision Details: (Updated by Revision Control System) # ----------------- # $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__":
def begin(self): """ Initialize: start recording coverage info. """ figleaf.start()
def compare_coverage(filename): print filename fullpath = os.path.abspath(os.path.join(testdir, filename)) ### run file & record coverage maindict = {} maindict.update(__main__.__dict__) figleaf.start() try: execfile(fullpath, maindict) except: pass figleaf.stop() d = figleaf.get_data().gather_files() coverage_info = d.get(fullpath, None) ### ok, now get the interesting lines from our just-executed python script f1 = open(fullpath) SYNTAX_ERROR = False try: line_info = figleaf.get_lines(f1) except SyntaxError: SYNTAX_ERROR = True # not supported in this ver? ### load in the previously annotated lines coverage_file = filename + '.cover.' + version_string try: f2 = open(os.path.join(testdir, coverage_file)) assert not SYNTAX_ERROR except IOError: assert SYNTAX_ERROR # it's ok, skip this test return ########## No syntax error, check aginst previously annotated stuff. actual_lines = f2.readlines() f2.close() ### annotate lines with coverage style 'cover' f1.seek(0) (_, _, output) = figleaf.annotate_cover.make_cover_lines(line_info, coverage_info, f1) ### compare! f1.close() for (i, (check_line, recorded_line)) in enumerate(zip(output, actual_lines)): check_line = check_line.strip() recorded_line = recorded_line.strip() assert check_line == recorded_line, "regression mismatch, file %s:%d\ncurrent '%s'\nactual '%s'\n" % (fullpath, i, check_line, recorded_line,)
def pytest_sessionstart(session): # pylint: disable=W0613 """ Start figleaf coverage reporting. """ figleaf.start()
def __init__(self, app): import figleaf self.app = app figleaf.start()
#!/usr/bin/env python import figleaf figleaf.start(ignore_python_lib=True) import doctest import os import sys import traceback import unittest REGRESSION_TESTS_DIR_NAME = 'regressiontests' TEST_TEMPLATE_DIR = 'templates' REGRESSION_TEST_DIR = os.path.join(os.path.dirname(__file__), REGRESSION_TESTS_DIR_NAME) ALWAYS_INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.auth', 'django.contrib.sites', #'django.contrib.flatpages', #'django.contrib.redirects', 'django.contrib.sessions', #'django.contrib.comments', 'django.contrib.admin', ] def get_test_models(): models = []
def pre_run(self, __): """ starts figleaf """ figleaf.start()
def pytest_configure(config): figleaf.start()