Beispiel #1
0
    def test_after(self):
        m = Mock()
        class Type(): pass

        def make_t(): return Type()

        @requires(first(Type))
        def f_t(t): m.f_t()
        @requires(Type)
        def n_t(t): m.n_t()
        @requires(last(Type))
        def l_t_1(t): m.l_t_1()
        @requires(after(Type))
        def after_t1(): m.after_t1()
        @requires(last(Type))
        def l_t_2(t): m.l_t_2()
        
        Runner(make_t, l_t_1, after_t1, l_t_2, n_t, f_t)()
        
        compare([
                call.f_t(),
                call.n_t(),
                call.l_t_1(),
                call.after_t1(),
                call.l_t_2(),
                ], m.mock_calls)
Beispiel #2
0
    def test_ordering_runners(self):
        m = Mock()
        class Type(): pass

        @requires(first())
        def f_none(): m.f_none()
        def n_none(): m.n_none()
        def l_none(): m.l_none()
        def make_t(): return Type()

        @requires(first(Type))
        def f_t(t): m.f_t()
        @requires(Type)
        def n_t(t): m.n_t()
        @requires(last(Type))
        def l_t(t): m.l_t()

        runner = Runner()
        runner.add(l_none, last())
        runner.add(f_t)
        
        Runner(Runner(l_t, n_t),
               runner,
               Runner(f_none, n_none),
               Runner(make_t))()
        
        compare([
                call.f_none(),
                call.n_none(),
                call.l_none(),
                call.f_t(),
                call.n_t(),
                call.l_t(),
                ], m.mock_calls)
Beispiel #3
0
    def test_ordering(self):
        m = Mock()
        class Type(): pass

        @requires(first())
        def f_none(): m.f_none()
        def n_none(): m.n_none()
        @requires(last())
        def l_none(): m.l_none()
        def make_t(): return Type()

        @requires(first(Type))
        def f_t(t): m.f_t()
        @requires(Type)
        def n_t(t): m.n_t()
        @requires(last(Type))
        def l_t(t): m.l_t()
        
        Runner(l_t, n_t, l_none, f_t, f_none, n_none, make_t)()
        
        compare([
                call.f_none(),
                call.n_none(),
                call.l_none(),
                call.f_t(),
                call.n_t(),
                call.l_t(),
                ], m.mock_calls)
Beispiel #4
0
    def test_how_when(self):
        m = Mock()
        class T(dict):
            foo = 'bar'
        @requires(item(first(T), 'baz'))
        def f_t(o): m.f_t(o)
        @requires(T)
        def n_t(o): m.n_t(o.__class__)
        @requires(attr(last(T), 'foo'))
        def l_t(o): m.l_t(o)

        def make_t():
            t = T()
            t['baz'] = 'bob'
            return t

        Runner(l_t, n_t, f_t, make_t)()

        compare([
                call.f_t('bob'),
                call.n_t(T),
                call.l_t('bar'),
                ], m.mock_calls)