예제 #1
0
def is_enabled():
    try:
        from App.config import getConfiguration
        debug_mode = getConfiguration().debug_mode
    except:
        debug_mode = False
    if debug_mode:
        return True

    try:
        from zope import testrunner
        from zope.testrunner import options
    except ImportError:
        from zope.testing import testrunner
        from zope.testing.testrunner import options
    frame = sys._getframe(2)
    while frame is not None and frame.f_code is not testrunner.run.func_code:
        frame = frame.f_back
    if frame is not None:
        try:
            pm = options.get_options().post_mortem
            return bool(pm)
        except:
            # options not recognized by test runnergiven
            pass

    return False
예제 #2
0
파일: setup.py 프로젝트: gforcada/zope.tal
def alltests():
    # use the zope.testrunner machinery to find all the
    # test suites we've put under ourselves
    from zope.testrunner.options import get_options
    from zope.testrunner.find import find_suites
    from unittest import TestSuite
    here = os.path.abspath(os.path.dirname(sys.argv[0]))
    args = sys.argv[:]
    src = os.path.join(here, 'src')
    defaults = ['--test-path', src]
    options = get_options(args, defaults)
    suites = list(find_suites(options))
    return TestSuite(suites)
예제 #3
0
def test_suite():
    # use the zope.testrunner machinery to find all the
    # test suites we've put under ourselves
    from zope.testrunner.options import get_options
    from zope.testrunner.find import find_suites
    from unittest import TestSuite
    here = os.path.abspath(os.path.dirname(sys.argv[0]))
    args = sys.argv[:]
    src = os.path.join(here, 'src')
    defaults = ['--test-path', src]
    options = get_options(args, defaults)
    suites = list(find_suites(options))
    return TestSuite(suites)
예제 #4
0
파일: runner.py 프로젝트: aregee/Mailman
    def configure(self):
        if self.args is None:
            self.args = sys.argv[:]
        # Check to see if we are being run as a subprocess. If we are,
        # then use the resume-layer and defaults passed in.
        if len(self.args) > 1 and self.args[1] == '--resume-layer':
            self.args.pop(1)
            resume_layer = self.args.pop(1)
            resume_number = int(self.args.pop(1))
            self.defaults = []
            while len(self.args) > 1 and self.args[1] == '--default':
                self.args.pop(1)
                self.defaults.append(self.args.pop(1))

            sys.stdin = FakeInputContinueGenerator()
        else:
            resume_layer = resume_number = None

        options = get_options(self.args, self.defaults)

        options.testrunner_defaults = self.defaults
        options.resume_layer = resume_layer
        options.resume_number = resume_number

        self.options = options

        self.features.append(zope.testrunner.selftest.SelfTest(self))
        self.features.append(zope.testrunner.logsupport.Logging(self))
        self.features.append(zope.testrunner.coverage.Coverage(self))
        self.features.append(zope.testrunner._doctest.DocTest(self))
        self.features.append(zope.testrunner.profiling.Profiling(self))
        if is_jython:
            # Jython GC support is not yet implemented
            pass
        else:
            self.features.append(
                zope.testrunner.garbagecollection.Threshold(self))
            self.features.append(
                zope.testrunner.garbagecollection.Debug(self))

        self.features.append(zope.testrunner.find.Find(self))
        self.features.append(zope.testrunner.shuffle.Shuffle(self))
        self.features.append(zope.testrunner.process.SubProcess(self))
        self.features.append(zope.testrunner.filter.Filter(self))
        self.features.append(zope.testrunner.listing.Listing(self))
        self.features.append(
            zope.testrunner.statistics.Statistics(self))
        self.features.append(zope.testrunner.tb_format.Traceback(self))

        # Remove all features that aren't activated
        self.features = [f for f in self.features if f.active]
예제 #5
0
    def configure(self):
        if self.args is None:
            self.args = sys.argv[:]
        # Check to see if we are being run as a subprocess. If we are,
        # then use the resume-layer and defaults passed in.
        if len(self.args) > 1 and self.args[1] == '--resume-layer':
            self.args.pop(1)
            resume_layer = self.args.pop(1)
            resume_number = int(self.args.pop(1))
            self.defaults = []
            while len(self.args) > 1 and self.args[1] == '--default':
                self.args.pop(1)
                self.defaults.append(self.args.pop(1))

            sys.stdin = FakeInputContinueGenerator()
        else:
            resume_layer = resume_number = None

        options = get_options(self.args, self.defaults)

        options.testrunner_defaults = self.defaults
        options.resume_layer = resume_layer
        options.resume_number = resume_number

        self.options = options

        self.features.append(zope.testrunner.selftest.SelfTest(self))
        self.features.append(zope.testrunner.logsupport.Logging(self))
        self.features.append(zope.testrunner.coverage.Coverage(self))
        self.features.append(zope.testrunner._doctest.DocTest(self))
        self.features.append(zope.testrunner.profiling.Profiling(self))
        if is_jython:
            # Jython GC support is not yet implemented
            pass
        else:
            self.features.append(
                zope.testrunner.garbagecollection.Threshold(self))
            self.features.append(
                zope.testrunner.garbagecollection.Debug(self))

        self.features.append(zope.testrunner.find.Find(self))
        self.features.append(zope.testrunner.shuffle.Shuffle(self))
        self.features.append(zope.testrunner.process.SubProcess(self))
        self.features.append(zope.testrunner.filter.Filter(self))
        self.features.append(zope.testrunner.listing.Listing(self))
        self.features.append(
            zope.testrunner.statistics.Statistics(self))
        self.features.append(zope.testrunner.tb_format.Traceback(self))

        # Remove all features that aren't activated
        self.features = [f for f in self.features if f.active]
예제 #6
0
def run(defaults=None, args=None, script_parts=None):
    """Main runner function which can be and is being used from main programs.

    Will execute the tests and exit the process according to the test result.

    """
    op = options.get_options(args, defaults)
    testresult_dir = os.getcwd()

    if op.testresult_dir:
        testresult_dir = op.testresult_dir
    if not os.path.exists(testresult_dir):
        os.mkdir(testresult_dir)
    # coverage support
    if op.coverage_modules:
        cover = coverage.coverage(branch=op.coverage_branch)
        cover.exclude('#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]')
        cover.start()
    # test runner
    failed = run_internal(defaults, args, script_parts)

    # coverage report
    if op.coverage_modules:
        cover.stop()
        cover.save()
        modules = [module for name, module in sys.modules.items()
                   if with_coverage(name, module, op.coverage_modules)]
        print "\nCoverage report\n===============\n"

        cover.report(modules)
        if op.coverage_xml:
            # thanks to nosexcover for this part
            morfs = [m.__file__ for m in modules if hasattr(m, '__file__')]
            cover.xml_report(morfs, outfile=os.path.join(
                testresult_dir, 'testreports', 'coverage.xml'))
        if op.coverage_annotate:
            cover.annotate(morfs=modules,
                           directory=op.coverage_annotate)
        if op.coverage_html:
            coverHtmlDir = op.coverage_html_dir
            log.debug("Generating HTML coverage report")
            cover.html_report(morfs, directory=os.path.join(
                testresult_dir, coverHtmlDir))

    # return code
    sys.exit(int(failed))