Пример #1
0
 def test_it_compares_function_equality(self):
     def add(a, b): return a + b
     def new_add(a, b): return a + b
     def sub(a, b): return a - b
     def sub_const(a): return a - 2
     self.assertTrue(func_equal(add, new_add))
     self.assertFalse(func_equal(new_add, sub))
     self.assertFalse(func_equal(sub, sub_const))
Пример #2
0
    def test_it_compares_callables(self, getfn):
        getfn.side_effect = lambda o: (o.__call__, None)
        class Foo(object):
            def __call__(self, a, b):
                return a + b
        class FooBar(object):
            def __call__(self, a, b):
                return a + self.b
        class Cake(object):
            def __call__(self, c, b):
                return c + b

        self.assertFalse(func_equal(Foo(), FooBar()))
        self.assertTrue(func_equal(Foo(), Cake()))
Пример #3
0
    def test_it_compares_class_constructors(self, getfn):
        getfn.side_effect = lambda o: (o.__init__, None)
        class Foo(object):
            def __init__(self, bar):
                self.bar = bar
        class FooBar(object):
            def __init__(self, cake):
                self.bar = cake
        class ABC(object):
            def __init__(self, cake, bar):
                self.cake = cake
                self.bar()
        class Cake(object):
            def __init__(self, roflcopter, empty):
                self.bake = roflcopter

        self.assertTrue(func_equal(Foo, FooBar))
        print 'equal'
        self.assertFalse(func_equal(Foo, ABC))
        self.assertFalse(func_equal(Foo, Cake))
Пример #4
0
 def test_it_compares_lambda_function_equality(self):
     self.assertTrue(func_equal(lambda:0, lambda:0))
     self.assertTrue(func_equal(lambda:1, lambda:1))
     self.assertFalse(func_equal(lambda:2, lambda:1))