Exemple #1
0
    def test_derived_testcase(self):
        class C(unittest.TestCase):
            def runTest(self):
                pass

        self.assertFalse(util.has_class_fixtures(C))
        self.assertFalse(util.has_class_fixtures(C()))
Exemple #2
0
    def test_testcase_with_teardown(self):
        class C(unittest.TestCase):
            @classmethod
            def tearDownClass(cls):
                pass

            def runTest(self):
                pass

        self.assertTrue(util.has_class_fixtures(C))
        self.assertTrue(util.has_class_fixtures(C()))
Exemple #3
0
    def _flatten(self, suite):
        # XXX
        # examine suite tests to find out if they have class
        # or module fixtures and group them that way into names
        # of test classes or modules
        # ALSO record all test cases in self.cases
        mods = {}
        classes = {}
        stack = [suite]
        while stack:
            suite = stack.pop()
            for test in suite:
                if isinstance(test, unittest.TestSuite):
                    stack.append(test)
                else:
                    testid = util.test_name(test)
                    self.cases[testid] = test
                    if util.has_module_fixtures(test):
                        mods.setdefault(test.__class__.__module__, []).append(
                            testid)
                    elif util.has_class_fixtures(test):
                        classes.setdefault(
                            "%s.%s" % (test.__class__.__module__,
                                       test.__class__.__name__),
                            []).append(testid)
                    else:
                        yield testid

        for cls in sorted(classes.keys()):
            yield cls
        for mod in sorted(mods.keys()):
            yield mod
Exemple #4
0
    def test_derived_derived_testcase(self):
        class C(unittest.TestCase):
            @classmethod
            def setUpClass(cls):
                pass

            @classmethod
            def tearDownClass(cls):
                pass

        class D(C):
            def runTest(self):
                pass

        self.assertTrue(util.has_class_fixtures(D))
        self.assertTrue(util.has_class_fixtures(D()))
Exemple #5
0
    class _GeneratorMethodCase(GeneratorFunctionCase):

        if util.has_class_fixtures(cls):
            @classmethod
            def setUpClass(klass):
                if hasattr(cls, 'setUpClass'):
                    cls.setUpClass()

            @classmethod
            def tearDownClass(klass):
                if hasattr(cls, 'tearDownClass'):
                    cls.tearDownClass()
Exemple #6
0
    def _flatten(self, suite):
        """
        Flatten test-suite into list of IDs, AND record all test case
        into self.cases

        CAVEAT:  Due to current limitation of the MP plugin, examine the suite
                 tests to find out if they have class or module fixtures and
                 group them that way into name of test classes or module.
                 This is aid in their dispatch.
        """
        log.debug("Flattening test into list of IDs")
        mods = {}
        classes = {}
        stack = [suite]
        while stack:
            suite = stack.pop()
            for test in suite:
                if isinstance(test, unittest.TestSuite):
                    stack.append(test)
                else:
                    testid = util.test_name(test)
                    self.cases[testid] = test
                    if util.has_module_fixtures(test):
                        mods.setdefault(test.__class__.__module__,
                                        []).append(testid)
                    elif util.has_class_fixtures(test):
                        if test.__class__.__name__ == "_MethodTestCase":
                            # wrapped by MethodTestCase in testclasses.py
                            test = test.obj
                        if hasattr(test,
                                   '_testMethodName') and test._testMethodName:
                            # test a single method under the test class
                            yield "%s.%s.%s" % (
                                test.__class__.__module__,
                                test.__class__.__name__,
                                test._testMethodName,
                            )
                        else:
                            classes.setdefault(
                                "%s.%s" % (test.__class__.__module__,
                                           test.__class__.__name__),
                                []).append(testid)
                    else:
                        yield testid

        for cls in sorted(classes.keys()):
            yield cls
        for mod in sorted(mods.keys()):
            yield mod
Exemple #7
0
    class _MethodTestCase(unittest.TestCase):
        def __init__(self, method):
            self.method = method
            self._name = "%s.%s.%s" % (cls.__module__, cls.__name__, method)
            self.obj = cls()
            unittest.TestCase.__init__(self, "runTest")

        if util.has_class_fixtures(cls):

            @classmethod
            def setUpClass(klass):
                if hasattr(cls, "setUpClass"):
                    cls.setUpClass()

            @classmethod
            def tearDownClass(klass):
                if hasattr(cls, "tearDownClass"):
                    cls.tearDownClass()

        def setUp(self):
            if hasattr(self.obj, "setUp"):
                self.obj.setUp()

        def tearDown(self):
            if hasattr(self.obj, "tearDown"):
                self.obj.tearDown()

        def __repr__(self):
            return self._name

        id = __str__ = __repr__

        def runTest(self):
            getattr(self.obj, self.method)()

        def shortDescription(self):
            doc = getattr(self.obj, self.method).__doc__
            return doc and doc.split("\n")[0].strip() or None
Exemple #8
0
    def _flatten(self, suite):
        """
        Flatten test-suite into list of IDs, AND record all test case
        into self.cases

        CAVEAT:  Due to current limitation of the MP plugin, examine the suite
                 tests to find out if they have class or module fixtures and
                 group them that way into name of test classes or module.
                 This is aid in their dispatch.
        """
        log.debug("Flattening test into list of IDs")
        mods = {}
        classes = {}
        stack = [suite]
        while stack:
            suite = stack.pop()
            for test in suite:
                if isinstance(test, unittest.TestSuite):
                    stack.append(test)
                else:
                    testid = util.test_name(test)
                    self.cases[testid] = test
                    if util.has_module_fixtures(test):
                        mods.setdefault(test.__class__.__module__, []).append(
                            testid)
                    elif util.has_class_fixtures(test):
                        classes.setdefault(
                            "%s.%s" % (test.__class__.__module__,
                                       test.__class__.__name__),
                            []).append(testid)
                    else:
                        yield testid

        for cls in sorted(classes.keys()):
            yield cls
        for mod in sorted(mods.keys()):
            yield mod
Exemple #9
0
 def test_unittest_testcase(self):
     C = unittest.TestCase
     self.assertFalse(util.has_class_fixtures(C))
     self.assertFalse(util.has_class_fixtures(C()))