Ejemplo n.º 1
0
    def test_complex_(self):
        # parser -> args -> dbs (later) -> job (earlier)
        m = Mock()
        class T1(object): pass
        class T2(object): pass
        class T3(object): pass

        def parser():
            m.parser()
            return T1()

        @requires(T1)
        def args(obj):
            m.args(type(obj))
        
        @requires(T2)
        def dbs(obj):
            m.dbs(type(obj))
            return T3()
        
        @requires(last(T1))
        def parse(obj):
            m.parse(type(obj))
            return T2()

        runner = Runner(parser, args, dbs, parse)
        
        @requires(T1)
        def more_args(obj):
            m.more_args(type(obj))
        
        @requires(T2, T3)
        def job(o1, o2):
            m.job(type(o1), type(o2))

        runner.add(more_args)
        runner.add(job)
        runner()
        
        compare([
                call.parser(),
                call.args(T1),
                call.more_args(T1),
                call.parse(T1),
                call.dbs(T2),
                call.job(T2, T3),
                ], m.mock_calls)
Ejemplo n.º 2
0
    def test_simple_chain(self):
        m = Mock()        
        class T1(object): pass
        class T2(object): pass
        t1 = T1()
        t2 = T2()
        
        def parser():
            m.parser()
            return t1

        @requires(T1)
        def base_args(obj):
            m.base_args(obj)

        @requires(last(T1))
        def parse(obj):
            m.parse(obj)
            return t2

        runner = Runner(parser, base_args, parse)
        
        @requires(T1)
        def my_args(obj):
            m.my_args(obj)

        runner.add(my_args)
        
        @requires(T2)
        def job(obj):
            m.job(obj)

        runner.add(job)

        runner()
        
        compare([
                call.parser(),
                call.base_args(t1),
                call.my_args(t1),
                call.parse(t1),
                call.job(t2),
                ], m.mock_calls)