Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)