Beispiel #1
0
    def test_extend_decorator_with_name(self):
        class Extendee(object):
            pass

        instance = Extendee()

        @extend(Extendee, "foo")
        def method(self):
            "This is the test extension method."
            return "The result of method()"

        self.assertTrue(hasattr(Extendee, "foo"))
        self.assertTrue(hasattr(instance, "foo"))

        self.assertEqual(method.__doc__, Extendee.foo.__doc__)
        self.assertEqual(function_name(method), function_name(Extendee.foo))

        self.assertEqual(instance.foo(), "The result of method()")
Beispiel #2
0
    def test_add_method_default_name(self):
        class Extendee(object):
            pass

        instance = Extendee()

        def method(self):
            "This is the test extension method."
            return "The result of method()"

        add_method(method, Extendee)

        self.assertTrue(hasattr(Extendee, "method"))
        self.assertTrue(hasattr(instance, "method"))

        self.assertEqual(method.__doc__, Extendee.method.__doc__)
        self.assertEqual(function_name(method), function_name(Extendee.method))

        self.assertEqual(instance.method(), "The result of method()")
Beispiel #3
0
    def test_extend_decorator_with_name(self):

        class Extendee(object):
            pass

        instance = Extendee()

        @extend(Extendee, "foo")
        def method(self):
            "This is the test extension method."
            return "The result of method()"

        self.assertTrue(hasattr(Extendee, "foo"))
        self.assertTrue(hasattr(instance, "foo"))

        self.assertEqual(method.__doc__, Extendee.foo.__doc__)
        self.assertEqual(function_name(method), function_name(Extendee.foo))

        self.assertEqual(instance.foo(), "The result of method()")
Beispiel #4
0
    def test_add_method_default_name(self):

        class Extendee(object):
            pass

        instance = Extendee()

        def method(self):
            "This is the test extension method."
            return "The result of method()"

        add_method(method, Extendee)

        self.assertTrue(hasattr(Extendee, "method"))
        self.assertTrue(hasattr(instance, "method"))
        
        self.assertEqual(method.__doc__, Extendee.method.__doc__)
        self.assertEqual(function_name(method), function_name(Extendee.method))

        self.assertEqual(instance.method(), "The result of method()")