def run():
    loader = TestLoader()
    suite = loader.loadPackage(lbrynet.tests, True)
    runner = TrialRunner(AndroidTestReporter)
    runner.stream = str_stream
    passFail = not runner.run(suite).wasSuccessful()

    print str_stream.getvalue()
    sys.exit(passFail)
Example #2
0
def runTests():
    """
    Run all of mimics tests.
    """
    loader = TestLoader()
    suite = loader.loadPackage(test)
    passFail = not TrialRunner(VerboseTextReporter).run(suite).wasSuccessful()
    sys.exit(passFail)
Example #3
0
    def run_suite(self, suite=None, **kwargs):
        non_server_result = super(MagicicadaRunner,
                                  self).run_suite(self.non_server_suite,
                                                  **kwargs)
        if not non_server_result.wasSuccessful():
            return non_server_result

        server_result = TrialRunner(reporterFactory=self.factory,
                                    realTimeErrors=True,
                                    workingDirectory=WORKING_DIR).run(
                                        self.server_suite)
        return server_result
Example #4
0
 def _make_runner(self, config, stream):
     # Based on twisted.scripts.trial._makeRunner
     mode = None
     if config['debug']:
         mode = TrialRunner.DEBUG
     if config['dry-run']:
         mode = TrialRunner.DRY_RUN
     return TrialRunner(config['reporter'],
                        mode=mode,
                        stream=stream,
                        profile=config['profile'],
                        logfile=config['logfile'],
                        tracebackFormat=config['tbformat'],
                        realTimeErrors=config['rterrors'],
                        uncleanWarnings=config['unclean-warnings'],
                        workingDirectory=config['temp-directory'],
                        forceGarbageCollection=config['force-gc'])
Example #5
0
            #os.rmdir(dir)
            print "deleted %s/" % dir
    #os.rmdir(root)
    print "deleted %s/" % root

if __name__ == '__main__':
    status = 0
    workingDir = tempfile.mkdtemp('', 'testtool.', '/tmp')
    try:
        print ""
        print "workingDir = %s" % workingDir
        fixtureDir = os.path.join(os.getcwd(), 'fixtures')
        print "fixtureDir = %s" % fixtureDir
        print ""

        runner = TrialRunner(VerboseTextReporter, workingDirectory=workingDir)
        suite = TestSuite()

        # find all tests
        print "searching for test cases ..."
        loader = TestLoader()
        for root,dirs,files in os.walk('.'):
            for name in files:
                if name.startswith('test_') and name.endswith('.py'):
                    module = loader.findByName(os.path.join(root,name))
                    classes = loader.findTestClasses(module)
                    if len(classes) > 0:
                        for cls in classes:
                            methods = loader.getTestCaseNames(cls)
                            if len(methods) > 0:
                                for method in methods:
Example #6
0
def runtests(root_dir='pyofwave'):
    runner = TrialRunner(TreeReporter)
    loader = TestLoader()
    failures = runner.run(loader.loadByName(root_dir, recurse=True))
    sys.exit(failures)
Example #7
0
def test_with_trial(options, topdir, testdirs, testpaths):
    """The main testing entry point."""
    # parse arguments

    # Ensure that the database watcher is installed early, so that
    # unexpected database access can be blocked.
    from backends.testing.resources import DatabaseResource
    watcher = DatabaseResource.get_watcher()
    watcher.enable('account')

    reporter_decorators = []
    if options.one:
        reporter_decorators.append(StopOnFailureDecorator)
    if options.logs_on_failure:
        reporter_decorators.append(LogsOnFailureDecorator)

    def factory(*args, **kwargs):
        """Custom factory tha apply the decorators to the TreeReporter"""
        if options.subunit:
            return SubunitReporter(*args, **kwargs)
        else:
            result = TreeReporter(*args, **kwargs)
            for decorator in reporter_decorators:
                result = decorator(result)
            return result
    reporterFactory = factory
    runner = TrialRunner(reporterFactory=reporterFactory,
                         realTimeErrors=True, workingDirectory=WORKING_DIR)

    suite = UnsortedOptimisingTestSuite()
    suite.adsorbSuite(collect_tests(topdir, testdirs, testpaths))

    if options.test:
        old_suite = suite
        suite = UnsortedOptimisingTestSuite()
        pattern = re.compile('.*%s.*' % options.test)
        for test in iter(old_suite):
            if pattern.match(test.id()):
                suite.addTest(test)

    if options.ignore:
        old_suite = suite
        suite = UnsortedOptimisingTestSuite()
        pattern = re.compile('.*%s.*' % options.ignore)
        for test in iter(old_suite):
            if not pattern.match(test.id()):
                suite.addTest(test)

    if options.loops > 1:
        # we could loop the .run() call, but creating a suite that contains
        # duplicate tests is more efficient and more likely to expose
        # test-to-test issues. Plus, the testrun summary reports are nicer
        # this way --gafton
        old_suite = suite
        suite = UnsortedOptimisingTestSuite()
        for x in xrange(options.loops):
            suite.addTest(old_suite)

    if options.debug:
        DelayedCall.debug = True

    watcher.disable('account')
    if options.coverage:
        tracer = trace.Trace(trace=False, count=True)
        tracer.runctx('runner.run(suite)', globals=globals(), locals=vars())
        r = tracer.results()
        if not os.path.exists(COVERAGE_DIR):
            os.mkdir(COVERAGE_DIR)
        r.write_results(show_missing=True, summary=True, coverdir=COVERAGE_DIR)
    else:
        result = runner.run(suite)
        return not result.wasSuccessful()
Example #8
0
def runtests(root_dir='pyofwave'):
    runner = TrialRunner(TreeReporter)
    loader = TestLoader()
    failures = runner.run(loader.loadByName(root_dir, recurse=True))
    sys.exit(failures)
Example #9
0
def test_with_trial(options, topdir, testdirs, testpaths):
    """The main testing entry point."""
    # parse arguments

    # Ensure that the database watcher is installed early, so that
    # unexpected database access can be blocked.
    from backends.testing.resources import DatabaseResource
    watcher = DatabaseResource.get_watcher()
    watcher.enable('account')

    reporter_decorators = []
    if options.one:
        reporter_decorators.append(StopOnFailureDecorator)
    if options.logs_on_failure:
        reporter_decorators.append(LogsOnFailureDecorator)

    def factory(*args, **kwargs):
        """Custom factory tha apply the decorators to the TreeReporter"""
        if options.subunit:
            return SubunitReporter(*args, **kwargs)
        else:
            result = TreeReporter(*args, **kwargs)
            for decorator in reporter_decorators:
                result = decorator(result)
            return result

    reporterFactory = factory
    runner = TrialRunner(reporterFactory=reporterFactory,
                         realTimeErrors=True,
                         workingDirectory=WORKING_DIR)

    suite = UnsortedOptimisingTestSuite()
    suite.adsorbSuite(collect_tests(topdir, testdirs, testpaths))

    if options.test:
        old_suite = suite
        suite = UnsortedOptimisingTestSuite()
        pattern = re.compile('.*%s.*' % options.test)
        for test in iter(old_suite):
            if pattern.match(test.id()):
                suite.addTest(test)

    if options.ignore:
        old_suite = suite
        suite = UnsortedOptimisingTestSuite()
        pattern = re.compile('.*%s.*' % options.ignore)
        for test in iter(old_suite):
            if not pattern.match(test.id()):
                suite.addTest(test)

    if options.loops > 1:
        # we could loop the .run() call, but creating a suite that contains
        # duplicate tests is more efficient and more likely to expose
        # test-to-test issues. Plus, the testrun summary reports are nicer
        # this way --gafton
        old_suite = suite
        suite = UnsortedOptimisingTestSuite()
        for x in xrange(options.loops):
            suite.addTest(old_suite)

    if options.debug:
        DelayedCall.debug = True

    watcher.disable('account')
    if options.coverage:
        tracer = trace.Trace(trace=False, count=True)
        tracer.runctx('runner.run(suite)', globals=globals(), locals=vars())
        r = tracer.results()
        if not os.path.exists(COVERAGE_DIR):
            os.mkdir(COVERAGE_DIR)
        r.write_results(show_missing=True, summary=True, coverdir=COVERAGE_DIR)
    else:
        result = runner.run(suite)
        return not result.wasSuccessful()