コード例 #1
0
ファイル: core.py プロジェクト: TimSimpsonR/python-proboscis
 def _register_test_class(self, cls, info):
     """Registers the methods within a class."""
     test_entries = []
     methods = compatability.get_class_methods(cls)
     before_class_methods = []
     after_class_methods = []
     for method in methods:
         func = compatability.get_method_function(method)
         if hasattr(func, "_proboscis_entry_"):
             entry = self._change_function_to_method(method, cls, info)
             test_entries.append(entry)
             if entry.info.before_class:
                 before_class_methods.append(entry)
             elif entry.info.after_class:
                 after_class_methods.append(entry)
     for before_entry in before_class_methods:
         for test_entry in test_entries:
             if not test_entry.info.before_class:
                 test_entry.info.depends_on.add(before_entry.home)
     for after_entry in after_class_methods:
         for test_entry in test_entries:
             if not test_entry.info.after_class:
                 after_entry.info.depends_on.add(test_entry.home)
     entry = TestMethodClassEntry(cls, info, test_entries)
     self._register_entry(entry)
     return entry.home
コード例 #2
0
    def test_if_set_on_parent_func_adds_parent_items_to_list(self):
        from proboscis import test

        @test(runs_after_groups=["yet_another_test"])
        class ExampleTest(object):
            @test(runs_after_groups=["other_test"])
            def test_1(self):
                pass

        for t in self.registry.tests:
            if t.home == ExampleTest:
                assert_equal(1, len(t.info.runs_after_groups))
                assert_true("yet_another_test" in t.info.runs_after_groups)
            elif t.home == get_method_function(ExampleTest.test_1):
                assert_equal(2, len(t.info.runs_after_groups))
                expected_homes = {
                    "other_test": False,
                    "yet_another_test": False
                }
                for home in t.info.runs_after_groups:
                    if home not in expected_homes.keys():
                        fail("%s should not be in runs_after_groups" % home)
                    expected_homes[home] = True
                for expected_home, found in expected_homes.items():
                    if not found:
                        fail("%s was not found in runs_after_groups" %
                             expected_home)
            else:
                fail("Unexpected test seen in iteration: %s" % t)
コード例 #3
0
 def _register_test_class(self, cls, info):
     """Registers the methods within a class."""
     test_entries = []
     methods = compatability.get_class_methods(cls)
     before_class_methods = []
     after_class_methods = []
     for method in methods:
         func = compatability.get_method_function(method)
         if hasattr(func, "_proboscis_entry_"):
             entry = self._change_function_to_method(method, cls, info)
             test_entries.append(entry)
             if entry.info.before_class:
                 before_class_methods.append(entry)
             elif entry.info.after_class:
                 after_class_methods.append(entry)
     for before_entry in before_class_methods:
         for test_entry in test_entries:
             if not test_entry.info.before_class:
                 test_entry.info.depends_on.add(before_entry.home)
     for after_entry in after_class_methods:
         for test_entry in test_entries:
             if not test_entry.info.after_class:
                 after_entry.info.depends_on.add(test_entry.home)
     entry = TestMethodClassEntry(cls, info, test_entries)
     self._register_entry(entry)
     return entry.home
コード例 #4
0
ファイル: test_core.py プロジェクト: DCully/python-proboscis
    def test_if_set_on_parent_func_adds_parent_items_to_list(self):
        from proboscis import test

        @test(runs_after_groups=["yet_another_test"])
        class ExampleTest(object):
            @test(runs_after_groups=["other_test"])
            def test_1(self):
                pass

        for t in self.registry.tests:
            if t.home == ExampleTest:
                assert_equal(1, len(t.info.runs_after_groups))
                assert_true("yet_another_test" in t.info.runs_after_groups)
            elif t.home == get_method_function(ExampleTest.test_1):
                assert_equal(2, len(t.info.runs_after_groups))
                expected_homes = {"other_test":False, "yet_another_test":False}
                for home in t.info.runs_after_groups:
                    if home not in expected_homes.keys():
                        fail("%s should not be in runs_after_groups" % home)
                    expected_homes[home] = True
                for expected_home, found in expected_homes.items():
                    if not found:
                        fail("%s was not found in runs_after_groups"
                             % expected_home)
            else:
                fail("Unexpected test seen in iteration: %s" % t)
コード例 #5
0
ファイル: core.py プロジェクト: TimSimpsonR/python-proboscis
 def _change_function_to_method(self, method, cls, cls_info):
     """Add an entry to a method by altering its function entry."""
     function = compatability.get_method_function(method)
     method_entry = function._proboscis_entry_
     method_entry.mark_as_child(method, cls)
     new_groups = method_entry.info.inherit(cls_info)
     for group_name in new_groups:
         group = self.get_group(group_name)
         group.add_entry(method_entry)
     return method_entry
コード例 #6
0
 def _change_function_to_method(self, method, cls, cls_info):
     """Add an entry to a method by altering its function entry."""
     function = compatability.get_method_function(method)
     method_entry = function._proboscis_entry_
     method_entry.mark_as_child(method, cls)
     new_groups = method_entry.info.inherit(cls_info)
     for group_name in new_groups:
         group = self.get_group(group_name)
         group.add_entry(method_entry)
     return method_entry
コード例 #7
0
    def test_if_set_then_func_should_not_inherit(self):
        from proboscis import test

        @test(enabled=False)
        class ExampleTest(object):
            @test(enabled=False)
            def test_1(self):
                pass

        for t in self.registry.tests:
            if t.home is ExampleTest:
                assert_false(t.info.enabled)
            elif t.home is get_method_function(ExampleTest.test_1):
                assert_false(t.info.enabled)
            else:
                fail("Unexpected test seen in iteration: %s" % t)
コード例 #8
0
ファイル: test_core.py プロジェクト: DCully/python-proboscis
    def test_if_set_then_func_should_not_inherit(self):
        from proboscis import test

        @test(enabled=False)
        class ExampleTest(object):
            @test(enabled=False)
            def test_1(self):
                pass

        for t in self.registry.tests:
            if t.home is ExampleTest:
                assert_false(t.info.enabled)
            elif t.home is get_method_function(ExampleTest.test_1):
                assert_false(t.info.enabled)
            else:
                fail("Unexpected test seen in iteration: %s" % t)
コード例 #9
0
    def test_if_not_set_on_parent_func_is_unaffected(self):
        from proboscis import test

        @test
        class ExampleTest(object):
            @test(runs_after_groups=["other_test"])
            def test_1(self):
                pass

        for t in self.registry.tests:
            if t.home == ExampleTest:
                assert_equal(0, len(t.info.runs_after_groups))
            elif t.home == get_method_function(ExampleTest.test_1):
                assert_equal(1, len(t.info.runs_after_groups))
                assert_true("other_test" in t.info.runs_after_groups)
            else:
                fail("Unexpected test seen in iteration: %s" % t)
コード例 #10
0
ファイル: test_core.py プロジェクト: DCully/python-proboscis
    def test_if_not_set_on_parent_func_is_unaffected(self):
        from proboscis import test

        @test
        class ExampleTest(object):
            @test(runs_after_groups=["other_test"])
            def test_1(self):
                pass

        for t in self.registry.tests:
            if t.home == ExampleTest:
                assert_equal(0, len(t.info.runs_after_groups))
            elif t.home == get_method_function(ExampleTest.test_1):
                assert_equal(1, len(t.info.runs_after_groups))
                assert_true("other_test" in t.info.runs_after_groups)
            else:
                fail("Unexpected test seen in iteration: %s" % t)
コード例 #11
0
 def create_cases_from_instance(factory, instance):
     if isinstance(instance, type):
         raise RuntimeError("Factory %s returned type %s (rather than an "
             "instance), which is not allowed." % (factory, instance))
     if isinstance(instance, types.MethodType):
         home = compatability.get_method_function(instance)
     elif isinstance(instance, types.FunctionType):
         home = instance
     else:
         home = type(instance)
     if issubclass(home, unittest.TestCase):
         raise RuntimeError("Factory %s returned a unittest.TestCase "
             "instance %s, which is not legal.")
     try:
         entry = home._proboscis_entry_
     except AttributeError:
         raise RuntimeError("Factory method %s returned an instance %s "
             "which was not tagged as a Proboscis TestEntry." %
             (factory, instance))
     entry.mark_as_used_by_factory()  # Don't iterate this since a
                                      # function is creating it.
     if entry.is_child:
         raise RuntimeError("Function %s, which exists as a bound method "
             "in a decorated class may not be returned from a factory." %
             instance)
     # There is potentially an issue in that a different Registry might
     # register an entry, and we could then read that in with a factory.
     # Later the entry would not be found in the dictionary of entries.
     if isinstance(instance, types.MethodType):
         try:
             state = TestMethodState(instance.im_self)
         except AttributeError:
             raise RuntimeError("Only bound methods may be returned from "
                 "factories. %s is not bound." % instance)
     else:
         state = TestMethodState(entry, instance)
     return TestPlan._create_test_cases_for_entry(entry, state)
コード例 #12
0
ファイル: core.py プロジェクト: TimSimpsonR/python-proboscis
def transform_depends_on_target(target):
    if isinstance(target, types.MethodType):
        return compatability.get_method_function(target)
    else:
        return target
コード例 #13
0
def transform_depends_on_target(target):
    if isinstance(target, types.MethodType):
        return compatability.get_method_function(target)
    else:
        return target