示例#1
0
 def test_uses_copy_of_methods(self):
     l = [lambda: 42]
     mc = MultiCall(l, {})
     repr(mc)
     l[:] = []
     res = mc.execute()
     return res == 42
示例#2
0
 def test_uses_copy_of_methods(self):
     l = [lambda: 42]
     mc = MultiCall(l, {})
     repr(mc)
     l[:] = []
     res = mc.execute()
     return res == 42
示例#3
0
    def test_keyword_args_with_defaultargs(self):
        def f(x, z=1):
            return x + z

        reslist = MultiCall([f], dict(x=23, y=24)).execute()
        assert reslist == [24]
        reslist = MultiCall([f], dict(x=23, z=2)).execute()
        assert reslist == [25]
示例#4
0
    def test_call_none_is_no_result(self):
        def m1():
            return 1

        def m2():
            return None

        res = MultiCall([m1, m2], {}, firstresult=True).execute()
        assert res == 1
        res = MultiCall([m1, m2], {}).execute()
        assert res == [1]
示例#5
0
    def test_call_subexecute(self):
        def m(__multicall__):
            subresult = __multicall__.execute()
            return subresult + 1

        def n():
            return 1

        call = MultiCall([n, m], {}, firstresult=True)
        res = call.execute()
        assert res == 2
示例#6
0
    def test_call_subexecute(self):
        def m(__multicall__):
            subresult = __multicall__.execute()
            return subresult + 1

        def n():
            return 1

        call = MultiCall([n, m], {}, firstresult=True)
        res = call.execute()
        assert res == 2
示例#7
0
 def test_keyword_args(self):
     def f(x):
         return x + 1
     class A:
         def f(self, x, y):
             return x + y
     multicall = MultiCall([f, A().f], dict(x=23, y=24))
     assert "'x': 23" in repr(multicall)
     assert "'y': 24" in repr(multicall)
     reslist = multicall.execute()
     assert reslist == [24+23, 24]
     assert "2 results" in repr(multicall)
示例#8
0
    def test_keyword_args(self):
        def f(x):
            return x + 1

        class A:
            def f(self, x, y):
                return x + y

        multicall = MultiCall([f, A().f], dict(x=23, y=24))
        assert "'x': 23" in repr(multicall)
        assert "'y': 24" in repr(multicall)
        reslist = multicall.execute()
        assert reslist == [24 + 23, 24]
        assert "2 results" in repr(multicall)
示例#9
0
    def test_call_passing(self):
        class P1:
            def m(self, __multicall__, x):
                assert len(__multicall__.results) == 1
                assert not __multicall__.methods
                return 17

        class P2:
            def m(self, __multicall__, x):
                assert __multicall__.results == []
                assert __multicall__.methods
                return 23

        p1 = P1()
        p2 = P2()
        multicall = MultiCall([p1.m, p2.m], {'x': 23})
        assert "23" in repr(multicall)
        reslist = multicall.execute()
        assert len(reslist) == 2
        # ensure reversed order
        assert reslist == [23, 17]
示例#10
0
    def test_call_passing(self):
        class P1:
            def m(self, __multicall__, x):
                assert len(__multicall__.results) == 1
                assert not __multicall__.methods
                return 17

        class P2:
            def m(self, __multicall__, x):
                assert __multicall__.results == []
                assert __multicall__.methods
                return 23

        p1 = P1()
        p2 = P2()
        multicall = MultiCall([p1.m, p2.m], {'x': 23})
        assert "23" in repr(multicall)
        reslist = multicall.execute()
        assert len(reslist) == 2
        # ensure reversed order
        assert reslist == [23, 17]
示例#11
0
 def test_tags_call_error(self):
     multicall = MultiCall([lambda x: x], {})
     pytest.raises(TypeError, "multicall.execute()")