コード例 #1
0
    def test_can_load_tests_from_parameterized_by_cartesian_params_methods(self):
        class Mod(object):
            __name__ = 'themod'

        class Test(TestCase):

            @cartesian_params(
                (1, 2),
                (2, 3),
            )
            def test(self, a, b):
                assert a == b
        m = Mod()
        m.Test = Test
        Test.__module__ = m.__name__
        event = events.LoadFromModuleEvent(self.loader, m)
        self.session.hooks.loadTestsFromModule(event)
        self.assertEqual(len(event.extraTests), 1)
        self.assertEqual(len(event.extraTests[0]._tests), 4)
        # check that test names are sensible
        self.assertEqual(util.test_name(event.extraTests[0]._tests[0]),
                         'themod.Test.test:1')
        self.assertEqual(util.test_name(event.extraTests[0]._tests[1]),
                         'themod.Test.test:2')
        self.assertEqual(util.test_name(event.extraTests[0]._tests[2]),
                         'themod.Test.test:3')
        self.assertEqual(util.test_name(event.extraTests[0]._tests[3]),
                         'themod.Test.test:4')
コード例 #2
0
ファイル: test_params_plugin.py プロジェクト: nose-devs/nose2
    def test_can_load_tests_from_parameterized_by_cartesian_params_methods(
            self):
        class Mod(object):
            __name__ = "themod"

        class Test(TestCase):
            @cartesian_params((1, 2), (2, 3))
            def test(self, a, b):
                assert a == b

        m = Mod()
        m.Test = Test
        Test.__module__ = m.__name__
        event = events.LoadFromModuleEvent(self.loader, m)
        self.session.hooks.loadTestsFromModule(event)
        self.assertEqual(len(event.extraTests), 1)
        self.assertEqual(len(event.extraTests[0]._tests), 4)
        # check that test names are sensible
        self.assertEqual(util.test_name(event.extraTests[0]._tests[0]),
                         "themod.Test.test:1")
        self.assertEqual(util.test_name(event.extraTests[0]._tests[1]),
                         "themod.Test.test:2")
        self.assertEqual(util.test_name(event.extraTests[0]._tests[2]),
                         "themod.Test.test:3")
        self.assertEqual(util.test_name(event.extraTests[0]._tests[3]),
                         "themod.Test.test:4")
コード例 #3
0
    def test_can_load_tests_from_parameterized_by_cartesian_params_functions(
            self):
        class Mod(object):
            __name__ = 'themod'

        def check(x, y):
            assert x == y

        @cartesian_params(
            (1, 2),
            (2, 3),
        )
        def test(a, b):
            check(a, b)

        m = Mod()
        m.test = test
        test.__module__ = m.__name__
        event = events.LoadFromModuleEvent(self.loader, m)
        self.session.hooks.loadTestsFromModule(event)
        self.assertEqual(len(event.extraTests), 4)
        # check that test names are sensible
        self.assertEqual(util.test_name(event.extraTests[0]), 'themod.test:1')
        self.assertEqual(util.test_name(event.extraTests[1]), 'themod.test:2')
        self.assertEqual(util.test_name(event.extraTests[2]), 'themod.test:3')
        self.assertEqual(util.test_name(event.extraTests[3]), 'themod.test:4')
コード例 #4
0
    def test_can_load_tests_from_parameterized_by_cartesian_params_functions(self):
        class Mod(object):
            __name__ = 'themod'

        def check(x, y):
            assert x == y

        @cartesian_params(
            (1, 2),
            (2, 3),
        )
        def test(a, b):
            check(a, b)
        m = Mod()
        m.test = test
        test.__module__ = m.__name__
        event = events.LoadFromModuleEvent(self.loader, m)
        self.session.hooks.loadTestsFromModule(event)
        self.assertEqual(len(event.extraTests), 4)
        # check that test names are sensible
        self.assertEqual(util.test_name(event.extraTests[0]),
                         'themod.test:1')
        self.assertEqual(util.test_name(event.extraTests[1]),
                         'themod.test:2')
        self.assertEqual(util.test_name(event.extraTests[2]),
                         'themod.test:3')
        self.assertEqual(util.test_name(event.extraTests[3]),
                         'themod.test:4')
コード例 #5
0
ファイル: mp.py プロジェクト: blockspacer/Qgis_TST
    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
コード例 #6
0
 def test_testcase_test_name(self):
     test = UtilTests('test_ensure_importable')
     self.assertEqual(
         test.id(),
         'nose2.tests.unit.test_util.UtilTests.test_ensure_importable')
     self.assertEqual(
         util.test_name(test),
         'nose2.tests.unit.test_util.UtilTests.test_ensure_importable')
コード例 #7
0
 def __getstate__(self):
     state = self.__dict__.copy()
     # FIXME fails for loadTestsFailure
     if "test" in state:
         test = state["test"]
         state["test"] = util.test_name(test)
         # subtest support
         if sys.version_info >= (3, 4):
             if isinstance(test, unittest.case._SubTest):
                 state["metadata"]["subtest"] = (test._message, test.params)
コード例 #8
0
 def test_can_load_tests_from_generator_functions(self):
     class Mod(object):
         __name__ = 'themod'
     def check(x):
         assert x == 1
     def test():
         yield check, 1
         yield check, 2
     m = Mod()
     m.test = test
     test.__module__ = m.__name__
     event = events.LoadFromModuleEvent(self.loader, m)
     self.session.hooks.loadTestsFromModule(event)
     self.assertEqual(len(event.extraTests), 2)
     # check that test names are sensible
     self.assertEqual(util.test_name(event.extraTests[0]),
                      'themod.test:1')
     self.assertEqual(util.test_name(event.extraTests[1]),
                      'themod.test:2')
コード例 #9
0
    def test_can_load_tests_from_generator_functions(self):
        class Mod(object):
            __name__ = 'themod'

        def check(x):
            assert x == 1

        def test():
            yield check, 1
            yield check, 2

        m = Mod()
        m.test = test
        test.__module__ = m.__name__
        event = events.LoadFromModuleEvent(self.loader, m)
        self.session.hooks.loadTestsFromModule(event)
        self.assertEqual(len(event.extraTests), 2)
        # check that test names are sensible
        self.assertEqual(util.test_name(event.extraTests[0]), 'themod.test:1')
        self.assertEqual(util.test_name(event.extraTests[1]), 'themod.test:2')
コード例 #10
0
ファイル: test_params_plugin.py プロジェクト: nose-devs/nose2
    def test_can_load_tests_from_parameterized_by_params_functions(self):
        class Mod(object):
            __name__ = "themod"

        def check(x):
            assert x == 1

        @params(1, 2)
        def test(a):
            check(a)

        m = Mod()
        m.test = test
        test.__module__ = m.__name__
        event = events.LoadFromModuleEvent(self.loader, m)
        self.session.hooks.loadTestsFromModule(event)
        self.assertEqual(len(event.extraTests), 2)
        # check that test names are sensible
        self.assertEqual(util.test_name(event.extraTests[0]), "themod.test:1")
        self.assertEqual(util.test_name(event.extraTests[1]), "themod.test:2")
コード例 #11
0
ファイル: test_params_plugin.py プロジェクト: nose-devs/nose2
    def test_can_load_tests_from_parameterized_by_params_functions(self):
        class Mod(object):
            __name__ = "themod"

        def check(x):
            assert x == 1

        @params(1, 2)
        def test(a):
            check(a)

        m = Mod()
        m.test = test
        test.__module__ = m.__name__
        event = events.LoadFromModuleEvent(self.loader, m)
        self.session.hooks.loadTestsFromModule(event)
        self.assertEqual(len(event.extraTests), 2)
        # check that test names are sensible
        self.assertEqual(util.test_name(event.extraTests[0]), "themod.test:1")
        self.assertEqual(util.test_name(event.extraTests[1]), "themod.test:2")
コード例 #12
0
ファイル: testid.py プロジェクト: JNRowe/nose2
 def reportStartTest(self, event):
     """Record and possibly output test id"""
     testid = util.test_name(event.testEvent.test)
     if testid not in self.tests:
         id_ = self.nextId()
         self.ids[id_] = testid
         self.tests[testid] = id_
     else:
         id_ = self.tests[testid]
     event.metadata['testid'] = id_
     if self.session.verbosity > 1:
         event.stream.write('#%s ' % id_)
コード例 #13
0
ファイル: test_params_plugin.py プロジェクト: dlai0001/nose2
    def test_can_load_tests_from_parameterized_methods(self):
        class Mod(object):
            __name__ = 'themod'

        class Test(TestCase):
            @params(1, 2)
            def test(self, a):
                assert a == 1

        m = Mod()
        m.Test = Test
        Test.__module__ = m.__name__
        event = events.LoadFromModuleEvent(self.loader, m)
        self.session.hooks.loadTestsFromModule(event)
        self.assertEqual(len(event.extraTests), 1)
        self.assertEqual(len(event.extraTests[0]._tests), 2)
        # check that test names are sensible
        self.assertEqual(util.test_name(event.extraTests[0]._tests[0]),
                         'themod.Test.test:1')
        self.assertEqual(util.test_name(event.extraTests[0]._tests[1]),
                         'themod.Test.test:2')
コード例 #14
0
ファイル: testid.py プロジェクト: Carter0/learningPython
 def reportStartTest(self, event):
     """Record and possibly output test id"""
     testid = util.test_name(event.testEvent.test)
     if testid not in self.tests:
         id_ = self.nextId()
         self.ids[id_] = testid
         self.tests[testid] = id_
     else:
         id_ = self.tests[testid]
     event.metadata['testid'] = id_
     if self.session.verbosity > 1:
         event.stream.write('#%s ' % id_)
コード例 #15
0
 def test_subtest_test_name(self):
     from unittest.case import _SubTest
     sentinel = getattr(unittest.case, '_subtest_msg_sentinel', None)
     test = UtilTests('test_ensure_importable')
     test = _SubTest(test, sentinel, {'i': 1, 'j': 2})
     self.assertEqual(
         test.id(),
         'nose2.tests.unit.test_util.UtilTests.test_ensure_importable (i=1, j=2)'
     )
     self.assertEqual(
         util.test_name(test),
         'nose2.tests.unit.test_util.UtilTests.test_ensure_importable')
コード例 #16
0
ファイル: test_params_plugin.py プロジェクト: nose-devs/nose2
    def test_can_load_tests_from_parameterized_by_params_methods(self):
        class Mod(object):
            __name__ = "themod"

        class Test(TestCase):
            @params(1, 2)
            def test(self, a):
                assert a == 1

        m = Mod()
        m.Test = Test
        Test.__module__ = m.__name__
        event = events.LoadFromModuleEvent(self.loader, m)
        self.session.hooks.loadTestsFromModule(event)
        self.assertEqual(len(event.extraTests), 1)
        self.assertEqual(len(event.extraTests[0]._tests), 2)
        # check that test names are sensible
        t1 = util.test_name(event.extraTests[0]._tests[0], qualname=False)
        self.assertEqual(t1, "themod.Test.test:1")
        t2 = util.test_name(event.extraTests[0]._tests[1], qualname=False)
        self.assertEqual(t2, "themod.Test.test:2")
コード例 #17
0
    def test_subtest_test_name(self):
        from unittest.case import _SubTest

        sentinel = getattr(unittest.case, "_subtest_msg_sentinel", None)
        test = UtilTests("test_ensure_importable")
        test = _SubTest(test, sentinel, {"i": 1, "j": 2})
        self.assertEqual(
            test.id(),
            "nose2.tests.unit.test_util.UtilTests.test_ensure_importable (i=1, j=2)",
        )
        self.assertEqual(
            util.test_name(test),
            "nose2.tests.unit.test_util.UtilTests.test_ensure_importable",
        )
コード例 #18
0
ファイル: mp.py プロジェクト: ltfish/nose2
    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
コード例 #19
0
ファイル: events.py プロジェクト: JNRowe/nose2
 def __getstate__(self):
     state = self.__dict__
     # FIXME fails for loadTestsFailure
     if 'test' in state:
         state['test'] = util.test_name(state['test'])
     if 'executeTests' in state:
         state['executeTests'] = None
     if 'exc_info' in state and state['exc_info'] is not None:
         ec, ev, tb = state['exc_info']
         state['exc_info'] = (ec, ev, util.format_traceback(None, (ec, ev, tb)))
     clear = ('loader', 'result', 'runner')
     for attr in clear:
         if attr in state:
             state[attr] = None
     return state
コード例 #20
0
ファイル: nose2complete.py プロジェクト: sanga/nose2complete
def get_tests(d = '.'):
    T = TestLoader()
    t = T.discover(d)
    stack = [t]
    tests = []

    while stack:
        s = stack.pop()
        for t in s:
            if isinstance(t, TestSuite):
                stack.append(t)
            else:
                tests.append(t)

    return [test_name(v) for v in tests] # all test qualified names from this dir
コード例 #21
0
ファイル: events.py プロジェクト: federicoferniot/behave
 def __getstate__(self):
     state = self.__dict__
     # FIXME fails for loadTestsFailure
     if 'test' in state:
         state['test'] = util.test_name(state['test'])
     if 'executeTests' in state:
         state['executeTests'] = None
     if 'exc_info' in state and state['exc_info'] is not None:
         ec, ev, tb = state['exc_info']
         state['exc_info'] = (
             ec, ev, util.format_traceback(None, (ec, ev, tb)))
     clear = ('loader', 'result', 'runner')
     for attr in clear:
         if attr in state:
             state[attr] = None
     return state
コード例 #22
0
ファイル: mp.py プロジェクト: hugovk/nose2
    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