コード例 #1
0
    def test_calls_the_implementation(self):
        question = object()
        answers = object()
        with doublex.Mock() as render_impl:
            render_impl.render(question, answers)
        sut = Render(render_impl)

        sut.render(question, answers)
コード例 #2
0
    def test_reads_a_line_and_prints_it(self):
        line = 'foo'
        stdin = FakeIO(line)
        with doublex.Mock() as log:
            log.log(line)

        sut = colorize.Printer(stdin, {}, log.log)

        sut.process()

        doublex.assert_that(log, doublex.verify())
コード例 #3
0
    def test_prompt_renders_a_questions(self):
        question1 = dbx.Stub()
        question1.name = 'foo'
        result1 = object()
        with dbx.Mock() as render:
            render.render(question1, dbx.ANY_ARG).returns(result1)

        result = prompt([question1], render=render)

        self.assertEquals({'foo': result1}, result)
        dbx.assert_that(render, dbx.verify())
コード例 #4
0
    def test_reads_two_lines_and_prints_them(self):
        line = '1\n2'
        stdin = FakeIO(line)
        with doublex.Mock() as log:
            log.log('1')
            log.log('2')

        sut = colorize.Printer(stdin, {}, log.log)

        sut.process()

        doublex.assert_that(log, doublex.verify())
コード例 #5
0
    def test_replacement(self):
        line = 'foo'
        stdin = FakeIO(line)
        expected = 'ok'
        with doublex.Mock() as log:
            log.log(expected)
        regexps = {'foo': expected}

        sut = colorize.Printer(stdin, regexps, log.log)

        sut.process()

        doublex.assert_that(log, doublex.verify())
コード例 #6
0
    def test_keyboard_interrupt_finalizes(self):
        question1 = dbx.Stub()
        question1.name = 'foo'
        question2 = dbx.Stub()
        question2.name = 'bar'

        with dbx.Mock() as render:
            render.reset()
            render.render(question1, dbx.ANY_ARG).raises(KeyboardInterrupt)
            render.render(question2, dbx.ANY_ARG)

        result = prompt([question1, question2], render=render)

        self.assertIsNone(result)
        dbx.assert_that(
            render.render,
            is_not(dbx.called().with_args(question2,
                                          dbx.ANY_ARG)))
コード例 #7
0
 def setUp(self):
     self.mock = doublex.Mock()
コード例 #8
0
# -*- coding: utf-8 -*-

import doublex
from expects import expect
from expects.testing import failure

from doublex_expects import *


with describe('have_been_satisfied_in_any_order'):
    with it('passes if mock methods have been called in order'):
        with doublex.Mock() as mock:
            mock.foo(1)
            mock.bar()

        mock.foo(1)
        mock.bar()

        expect(mock).to(have_been_satisfied_in_any_order)

    with it('passes if mock methods have been called in another order'):
        with doublex.Mock() as mock:
            mock.the_first_function_foo(1)
            mock.the_second_function_bar()

        mock.the_second_function_bar()
        mock.the_first_function_foo(1)

        expect(mock).to(have_been_satisfied_in_any_order)

    with it('fails if mock methods have not been called'):