Ejemplo n.º 1
0
    def test_addition(self):
        m = Mock()

        def job1():
            m.job1()

        def job2():
            m.job2()

        def job3():
            m.job3()

        runner1 = Runner(job1, job2)
        runner2 = Runner(job3)
        runner = runner1 + runner2
        runner()

        verify(runner,
                    (job1, set()),
                    (job2, set()),
                    (job3, set()),
                    )
        compare([
                call.job1(),
                call.job2(),
                call.job3(),
                ], m.mock_calls)
Ejemplo n.º 2
0
    def test_replace_for_testing(self):
        m = Mock()
        class T1(object): pass
        class T2(object): pass

        t1 = T1()
        t2 = T2()

        def job1():
            raise Exception() # pragma: nocover

        @requires(T1)
        def job2(obj):
            raise Exception() # pragma: nocover

        @requires(T2)
        def job3(obj):
            raise Exception() # pragma: nocover

        runner = Runner(job1, job2, job3)
        runner.replace(job1, m.job1)
        m.job1.return_value = t1
        runner.replace(job2, m.job2)
        m.job2.return_value = t2
        runner.replace(job3, m.job3)
        runner()

        compare([
                call.job1(),
                call.job2(t1),
                call.job3(t2),
                ], m.mock_calls)
Ejemplo n.º 3
0
    def test_extend_with_runners(self):
        m = Mock()        
        class T1(object): pass
        class T2(object): pass

        t1 = T1()
        t2 = T2()

        def job1():
            m.job1()
            return t1

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

        @requires(T2)
        def job3(obj):
            m.job3(obj)

        runner1 = Runner(job1)
        runner2 = Runner(job2)
        runner3 = Runner(job3)

        runner = Runner(runner1)
        runner.extend(runner2, runner3)
        runner()
        
        compare([
                call.job1(),
                call.job2(t1),
                call.job3(t2),
                ], m.mock_calls)
Ejemplo n.º 4
0
    def test_extend(self):
        m = Mock()
        class T1(object): pass
        class T2(object): pass

        t1 = T1()
        t2 = T2()

        def job1():
            m.job1()
            return t1

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

        @requires(T2)
        def job3(obj):
            m.job3(obj)

        runner = Runner()
        runner.extend(job1, job2, job3)
        runner()

        compare([
                call.job1(),
                call.job2(t1),
                call.job3(t2),
                ], m.mock_calls)
Ejemplo n.º 5
0
    def test_replace_for_testing(self):
        m = Mock()        
        class T1(object): pass
        class T2(object): pass

        t1 = T1()
        t2 = T2()

        def job1():
            raise Exception() # pragma: nocover

        @requires(T1)
        def job2(obj):
            raise Exception() # pragma: nocover

        @requires(T2)
        def job3(obj):
            raise Exception() # pragma: nocover

        runner = Runner(job1, job2, job3)
        runner.replace(job1, m.job1)
        m.job1.return_value = t1
        runner.replace(job2, m.job2)
        m.job2.return_value = t2
        runner.replace(job3, m.job3)
        runner()
        
        compare([
                call.job1(),
                call.job2(t1),
                call.job3(t2),
                ], m.mock_calls)
Ejemplo n.º 6
0
    def test_simple(self):
        m = Mock()

        runner = Runner()
        runner.add(m.job1, label='one')
        runner.add(m.job2)
        runner.add(m.job3, label='three')
        runner.add(m.job4)

        class MyPlug(Plug):

            def one(self):
                m.plug_one()

            def three(self):
                m.plug_two()

        plug = MyPlug()
        plug.add_to(runner)

        runner()

        compare([
            call.job1(), call.plug_one(), call.job2(),
            call.job3(), call.plug_two(), call.job4()
        ], m.mock_calls)

        verify(runner,
               (m.job1, set()),
               (plug.one, {'one'}),
               (m.job2, set()),
               (m.job3, set()),
               (plug.three, {'three'}),
               (m.job4, set()),
               )
Ejemplo n.º 7
0
    def test_context_declarative(self):
        m = Mock()        
        class T1(object): pass
        class T2(object): pass

        t1 = T1()
        t2 = T2()

        def job1():
            m.job1()
            return t1

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

        @requires(T2)
        def job3(obj):
            m.job3(obj)

        runner = Runner(job1, job2, job3)
        runner()
        
        compare([
                call.job1(),
                call.job2(t1),
                call.job3(t2),
                ], m.mock_calls)
Ejemplo n.º 8
0
    def test_replace_explicit_with_labels(self):
        m = Mock()

        runner = Runner(m.job0)
        runner.add_label('foo')
        runner['foo'].add(m.job1)
        runner['foo'].add(m.job2)

        runner.replace(m.job2, m.jobnew, returns='mock')

        runner()

        compare([call.job0(), call.job1(), call.jobnew()], m.mock_calls)

        # check added_using is handled correctly
        m.reset_mock()
        runner2 = runner.clone(added_using='foo')
        runner2()

        compare([call.job1(), call.jobnew()], actual=m.mock_calls)

        # check runner's label pointer is sane
        m.reset_mock()
        runner['foo'].add(m.job3)
        runner()

        compare(
            [call.job0(), call.job1(),
             call.jobnew(),
             call.job3()],
            actual=m.mock_calls)
Ejemplo n.º 9
0
    def test_addition(self):
        m = Mock()

        def job1():
            m.job1()

        def job2():
            m.job2()

        def job3():
            m.job3()

        runner1 = Runner(job1, job2)
        runner2 = Runner(job3)
        runner = runner1 + runner2
        runner()

        verify(runner,
                    (job1, set()),
                    (job2, set()),
                    (job3, set()),
                    )
        compare([
                call.job1(),
                call.job2(),
                call.job3(),
                ], m.mock_calls)
Ejemplo n.º 10
0
    def test_extend_with_runners(self):
        m = Mock()

        class T1(object):
            pass

        class T2(object):
            pass

        t1 = T1()
        t2 = T2()

        def job1():
            m.job1()
            return t1

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

        @requires(T2)
        def job3(obj):
            m.job3(obj)

        runner1 = Runner(job1)
        runner2 = Runner(job2)
        runner3 = Runner(job3)

        runner = Runner(runner1)
        runner.extend(runner2, runner3)
        runner()

        verify(
            runner,
            (job1, set()),
            (job2, set()),
            (job3, set()),
        )
        compare([
            call.job1(),
            call.job2(t1),
            call.job3(t2),
        ], m.mock_calls)
Ejemplo n.º 11
0
    def test_imperative(self):
        m = Mock()

        class T1(object):
            pass

        class T2(object):
            pass

        t1 = T1()
        t2 = T2()

        def job1():
            m.job1()
            return t1

        def job2(obj):
            m.job2(obj)
            return t2

        def job3(t2_):
            m.job3(t2_)

        # imperative config trumps declarative
        @requires(T1)
        def job4(t2_):
            m.job4(t2_)

        runner = Runner()
        runner.add(job1)
        runner.add(job2, requires(T1))
        runner.add(job3, requires(t2_=T2))
        runner.add(job4, requires(T2))
        runner()

        compare([
            call.job1(),
            call.job2(t1),
            call.job3(t2),
            call.job4(t2),
        ], m.mock_calls)
Ejemplo n.º 12
0
    def test_requirements_and_returns(self):
        m = Mock()

        @returns('r1')
        def job1():
            m.job1()
            return 1

        @requires('r2')
        def job3(r):
            m.job3(r)

        runner = Runner()
        runner.add(job1, label='point')
        runner.add(job3)

        class MyPlug(Plug):
            @requires('r1')
            @returns('r2')
            def point(self, r):
                m.point(r)
                return 2

        plug = MyPlug()
        plug.add_to(runner)

        runner()

        compare([
            call.job1(),
            call.point(1),
            call.job3(2),
        ], m.mock_calls)

        verify(
            runner,
            (job1, set()),
            (plug.point, {'point'}),
            (job3, set()),
        )
Ejemplo n.º 13
0
    def test_replace_explicit_with_labels(self):
        m = Mock()

        runner = Runner(m.job0)
        runner.add_label('foo')
        runner['foo'].add(m.job1)
        runner['foo'].add(m.job2)

        runner.replace(m.job2, m.jobnew, returns='mock')

        runner()

        compare([
            call.job0(),
            call.job1(),
            call.jobnew()
        ], m.mock_calls)

        # check added_using is handled correctly
        m.reset_mock()
        runner2 = runner.clone(added_using='foo')
        runner2()

        compare([
            call.job1(),
            call.jobnew()
        ], actual=m.mock_calls)

        # check runner's label pointer is sane
        m.reset_mock()
        runner['foo'].add(m.job3)
        runner()

        compare([
            call.job0(),
            call.job1(),
            call.jobnew(),
            call.job3()
        ], actual=m.mock_calls)
Ejemplo n.º 14
0
    def test_requirements_and_returns(self):
        m = Mock()

        @returns('r1')
        def job1():
            m.job1()
            return 1

        @requires('r2')
        def job3(r):
            m.job3(r)

        runner = Runner()
        runner.add(job1, label='point')
        runner.add(job3)

        class MyPlug(Plug):

            @requires('r1')
            @returns('r2')
            def point(self, r):
                m.point(r)
                return 2

        plug = MyPlug()
        plug.add_to(runner)

        runner()

        compare([
            call.job1(), call.point(1), call.job3(2),
        ], m.mock_calls)

        verify(runner,
               (job1, set()),
               (plug.point, {'point'}),
               (job3, set()),
               )
Ejemplo n.º 15
0
    def test_context_imperative(self):
        m = Mock()        
        class T1(object): pass
        class T2(object): pass

        t1 = T1()
        t2 = T2()

        def job1():
            m.job1()
            return t1

        def job2(obj):
            m.job2(obj)
            return t2

        def job3(t2_):
            m.job3(t2_)

        # imperative config trumps declarative
        @requires(T1)
        def job4(t2_):
            m.job4(t2_)
            
        runner = Runner()
        runner.add(job1)
        runner.add(job2, T1)
        runner.add(job3, t2_=T2)
        runner.add(job4, T2)
        runner()
        
        compare([
                call.job1(),
                call.job2(t1),
                call.job3(t2),
                call.job4(t2),
                ], m.mock_calls)