Example #1
0
class WorkerProtocol(AMP):
    """
    The worker-side trial distributed protocol.
    """
    def __init__(self, forceGarbageCollection=False):
        self._loader = TestLoader()
        self._result = WorkerReporter(self)
        self._forceGarbageCollection = forceGarbageCollection

    def run(self, testCase):
        """
        Run a test case by name.
        """
        case = self._loader.loadByName(testCase)
        suite = TrialSuite([case], self._forceGarbageCollection)
        suite.run(self._result)
        return {'success': True}

    workercommands.Run.responder(run)

    def start(self, directory):
        """
        Set up the worker, moving into given directory for tests to run in
        them.
        """
        os.chdir(directory)
        return {'success': True}

    workercommands.Start.responder(start)
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 _load_tests(name):
    """
    Find all the tests under ``name``.

    :param str name: The fully-qualified Python name of an object.
    :return: A ``TestSuite`` or ``TestCase`` containing all the tests.
    """
    loader = TestLoader()
    return loader.loadByName(name, recurse=True)
Example #4
0
def _load_tests(name):
    """
    Find all the tests under ``name``.

    :param str name: The fully-qualified Python name of an object.
    :return: A ``TestSuite`` or ``TestCase`` containing all the tests.
    """
    loader = TestLoader()
    return loader.loadByName(name, recurse=True)
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 #6
0
class TestTestVisitor(unittest.TestCase):
    def setUp(self):
        self.loader = TestLoader()
        try:
            from twisted.trial.unittest import TestVisitor
            class MockVisitor(TestVisitor):
                def __init__(self):
                    self.calls = []
                def visitCase(self, testCase):
                    self.calls.append(("case", testCase))
                def visitSuite(self, testModule):
                    self.calls.append(("suite", testModule))
                def visitSuiteAfter(self, testModule):
                    self.calls.append(("suite_after", testModule))
            self.mock_visitor = MockVisitor
        except ImportError:
            pass
    def test_imports(self):
        from twisted.trial.unittest import TestVisitor
    def test_visit_case_default(self):
        from twisted.trial.unittest import TestVisitor
        testCase = self.loader.loadMethod(self.test_visit_case_default)
        test_visitor = TestVisitor()
        testCase.visit(test_visitor)
    def test_visit_case(self):
        testCase = TestTestVisitor('test_visit_case')
        test_visitor = self.mock_visitor()
        testCase.visit(test_visitor)
        self.assertEqual(test_visitor.calls, [("case", testCase)])
    def test_visit_module_default(self):
        from twisted.trial.unittest import TestVisitor
        import sys
        testCase = self.loader.loadModule(sys.modules[__name__])
        test_visitor = TestVisitor()
        testCase.visit(test_visitor)
    def test_visit_module(self):
        import sys
        test_visitor = self.mock_visitor()
        testCase = self.loader.loadModule(sys.modules[__name__])
        testCase.visit(test_visitor)
        self.failIf(len(test_visitor.calls) < 5, str(test_visitor.calls))
        self.assertEqual(test_visitor.calls[1][0], "case")
    def test_visit_class_default(self):
        from twisted.trial.unittest import TestVisitor
        testCase = self.loader.loadMethod(self.test_visit_class_default)
        test_visitor = TestVisitor()
        testCase.visit(test_visitor)
    def test_visit_class(self):
        test_visitor = self.mock_visitor()
        testCase = self.loader.loadMethod(self.test_visit_class)
        testCase.visit(test_visitor)
        self.assertEqual(len(test_visitor.calls), 1)
        self.assertEqual(test_visitor.calls[0][0], "case")
Example #7
0
File: worker.py Project: 0004c/VTK
class WorkerProtocol(AMP):
    """
    The worker-side trial distributed protocol.
    """

    def __init__(self, forceGarbageCollection=False):
        self._loader = TestLoader()
        self._result = WorkerReporter(self)
        self._forceGarbageCollection = forceGarbageCollection


    def run(self, testCase):
        """
        Run a test case by name.
        """
        case = self._loader.loadByName(testCase)
        suite = TrialSuite([case], self._forceGarbageCollection)
        suite.run(self._result)
        return {'success': True}

    workercommands.Run.responder(run)


    def start(self, directory):
        """
        Set up the worker, moving into given directory for tests to run in
        them.
        """
        os.chdir(directory)
        return {'success': True}

    workercommands.Start.responder(start)
Example #8
0
 def assertSuitesEqual(self, test1, names):
     loader = TestLoader()
     names1 = testNames(test1)
     names2 = testNames(TestSuite(map(loader.loadByName, names)))
     names1.sort()
     names2.sort()
     self.assertEqual(names1, names2)
Example #9
0
def get_tests_for(python_name):
    """
    Find all tests for the given ``python_name``.

    :param python_name: Either directory in ``REPOSITORY`` or a Python FQPN
        importable from ``REPOSITORY``.
    :return: PSet of test names.
    """
    def _extract_ids(t):
        if isinstance(t, TestSuite):
            result = pset()
            for sub_tests in t:
                result = result | _extract_ids(sub_tests)
            return result
        else:
            return pset([t.id()])

    loader = TestLoader()
    tests = loader.loadByName(python_name, recurse=True)
    return _extract_ids(tests)
Example #10
0
def get_tests_for(python_name):
    """
    Find all tests for the given ``python_name``.

    :param python_name: Either directory in ``REPOSITORY`` or a Python FQPN
        importable from ``REPOSITORY``.
    :return: PSet of test names.
    """
    def _extract_ids(t):
        if isinstance(t, TestSuite):
            result = pset()
            for sub_tests in t:
                result = result | _extract_ids(sub_tests)
            return result
        else:
            return pset([t.id()])

    loader = TestLoader()
    tests = loader.loadByName(python_name, recurse=True)
    return _extract_ids(tests)
Example #11
0
    def setUp(self):
        self.loader = TestLoader()
        try:
            from twisted.trial.unittest import TestVisitor

            class MockVisitor(TestVisitor):
                def __init__(self):
                    self.calls = []

                def visitCase(self, testCase):
                    self.calls.append(("case", testCase))

                def visitSuite(self, testModule):
                    self.calls.append(("suite", testModule))

                def visitSuiteAfter(self, testModule):
                    self.calls.append(("suite_after", testModule))

            self.mock_visitor = MockVisitor
        except ImportError:
            pass
Example #12
0
 def setUp(self):
     self.loader = TestLoader()
     try:
         from twisted.trial.unittest import TestVisitor
         class MockVisitor(TestVisitor):
             def __init__(self):
                 self.calls = []
             def visitCase(self, testCase):
                 self.calls.append(("case", testCase))
             def visitSuite(self, testModule):
                 self.calls.append(("suite", testModule))
             def visitSuiteAfter(self, testModule):
                 self.calls.append(("suite_after", testModule))
         self.mock_visitor = MockVisitor
     except ImportError:
         pass
Example #13
0
def runtests(root_dir='pyofwave'):
    runner = TrialRunner(TreeReporter)
    loader = TestLoader()
    failures = runner.run(loader.loadByName(root_dir, recurse=True))
    sys.exit(failures)
Example #14
0
 def setUp(self):
     self.config = trial.Options()
     self.loader = TestLoader()
Example #15
0
class TestTestVisitor(unittest.TestCase):
    def setUp(self):
        self.loader = TestLoader()
        try:
            from twisted.trial.unittest import TestVisitor

            class MockVisitor(TestVisitor):
                def __init__(self):
                    self.calls = []

                def visitCase(self, testCase):
                    self.calls.append(("case", testCase))

                def visitSuite(self, testModule):
                    self.calls.append(("suite", testModule))

                def visitSuiteAfter(self, testModule):
                    self.calls.append(("suite_after", testModule))

            self.mock_visitor = MockVisitor
        except ImportError:
            pass

    def test_imports(self):
        from twisted.trial.unittest import TestVisitor

    def test_visit_case_default(self):
        from twisted.trial.unittest import TestVisitor
        testCase = self.loader.loadMethod(self.test_visit_case_default)
        test_visitor = TestVisitor()
        testCase.visit(test_visitor)

    def test_visit_case(self):
        testCase = TestTestVisitor('test_visit_case')
        test_visitor = self.mock_visitor()
        testCase.visit(test_visitor)
        self.assertEqual(test_visitor.calls, [("case", testCase)])

    def test_visit_module_default(self):
        from twisted.trial.unittest import TestVisitor
        import sys
        testCase = self.loader.loadModule(sys.modules[__name__])
        test_visitor = TestVisitor()
        testCase.visit(test_visitor)

    def test_visit_module(self):
        import sys
        test_visitor = self.mock_visitor()
        testCase = self.loader.loadModule(sys.modules[__name__])
        testCase.visit(test_visitor)
        self.failIf(len(test_visitor.calls) < 5, str(test_visitor.calls))
        self.assertEqual(test_visitor.calls[1][0], "case")

    def test_visit_class_default(self):
        from twisted.trial.unittest import TestVisitor
        testCase = self.loader.loadMethod(self.test_visit_class_default)
        test_visitor = TestVisitor()
        testCase.visit(test_visitor)

    def test_visit_class(self):
        test_visitor = self.mock_visitor()
        testCase = self.loader.loadMethod(self.test_visit_class)
        testCase.visit(test_visitor)
        self.assertEqual(len(test_visitor.calls), 1)
        self.assertEqual(test_visitor.calls[0][0], "case")
Example #16
0
 def __init__(self, forceGarbageCollection=False):
     self._loader = TestLoader()
     self._result = WorkerReporter(self)
     self._forceGarbageCollection = forceGarbageCollection
Example #17
0
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:
                                    methodName = loader.methodPrefix + method
                                    print "found %s" % methodName
                                    suite.addTest(cls(methodName, fixtureDir, workingDir))
        print ""
        print "running test cases ..."
Example #18
0
def testSuite():
    loader = TestLoader()
    return TestSuite(
        list(
            loader.loadModule(namedModule(module))
            for module in PORTED_TEST_MODULES))
Example #19
0
def runtests(root_dir='pyofwave'):
    runner = TrialRunner(TreeReporter)
    loader = TestLoader()
    failures = runner.run(loader.loadByName(root_dir, recurse=True))
    sys.exit(failures)
Example #20
0
File: worker.py Project: 0004c/VTK
 def __init__(self, forceGarbageCollection=False):
     self._loader = TestLoader()
     self._result = WorkerReporter(self)
     self._forceGarbageCollection = forceGarbageCollection
                            data_suffix=True,
                            config_file=False,
                            branch=True,
                            source=['ipv8'],
                            include=['*'],
                            omit="ipv8/ipv8.py")
    cov.exclude('pass')
    cov.start()

    for line in lines:
        print "Measuring coverage for", line

        output_stream = StringIO()
        formatted_line = line.replace('/', '.').replace('.py:', '.')

        suite = TestLoader().loadTestsFromName(formatted_line)
        reporter = VerboseTextReporter(stream=output_stream)
        reporter.failfast = True
        suite.run(reporter)

        assert len(reporter.errors) == 0,\
            "ERROR: UNIT TESTS FAILED, PLEASE FIX BEFORE RUNNING COVERAGE:\n%s\n%s" % (output_stream.getvalue(), ''.join([repr(error) for error in reporter.errors]))
        output_stream.close()

    cov.stop()
    print "Generating HTML report"
    cov.html_report(directory='coverage', omit="ipv8/keyvault/libnacl/*")
    cov.erase()

clean_directory()