예제 #1
0
    def test_run_sets_text_if_present(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo',
                    text=Mock(name='text'))
        self.runner.step_registry.find_match.return_value = Mock()
        step.run(self.runner)

        eq_(self.context.text, step.text)
예제 #2
0
    def test_run_runs_before_hook_then_match_then_after_hook(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        side_effects = (None, AssertionError('whee'), Exception('whee'))
        for side_effect in side_effects:
            # Make match.run() and runner.run_hook() the same mock so
            # we can make sure things happen in the right order.
            self.runner.run_hook = match.run = Mock()

            def effect(thing):
                # pylint: disable=unused-argument
                def raiser_(*args, **kwargs):
                    match.run.side_effect = None
                    if thing:
                        raise thing

                def nonraiser(*args, **kwargs):
                    match.run.side_effect = raiser_

                return nonraiser

            match.run.side_effect = effect(side_effect)
            step.run(self.runner)

            eq_(match.run.call_args_list, [
                (('before_step', self.context, step), {}),
                ((self.context,), {}),
                (('after_step', self.context, step), {}),
            ])
예제 #3
0
파일: test_model.py 프로젝트: behave/behave
    def test_run_sets_text_if_present(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo",
                    text=Mock(name="text"))
        self.runner.step_registry.find_match.return_value = Mock()
        step.run(self.runner)

        assert self.context.text == step.text
예제 #4
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_runs_before_hook_then_match_then_after_hook(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        side_effects = (None, AssertionError('whee'), Exception('whee'))
        for side_effect in side_effects:
            # Make match.run() and runner.run_hook() the same mock so
            # we can make sure things happen in the right order.
            self.runner.run_hook = match.run = Mock()

            def effect(thing):
                # pylint: disable=unused-argument
                def raiser_(*args, **kwargs):
                    match.run.side_effect = None
                    if thing:
                        raise thing

                def nonraiser(*args, **kwargs):
                    match.run.side_effect = raiser_

                return nonraiser

            match.run.side_effect = effect(side_effect)
            step.run(self.runner)

            eq_(match.run.call_args_list, [
                (('before_step', self.context, step), {}),
                ((self.context, ), {}),
                (('after_step', self.context, step), {}),
            ])
예제 #5
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_sets_status_to_passed_if_nothing_goes_wrong(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        step.error_message = None
        self.runner.step_registry.find_match.return_value = Mock()
        step.run(self.runner)

        eq_(step.status, 'passed')
        eq_(step.error_message, None)
예제 #6
0
    def test_run_sets_status_to_passed_if_nothing_goes_wrong(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        step.error_message = None
        self.runner.step_registry.find_match.return_value = Mock()
        step.run(self.runner)

        eq_(step.status, Status.passed)
        eq_(step.error_message, None)
예제 #7
0
파일: test_model.py 프로젝트: behave/behave
    def test_run_sets_status_to_passed_if_nothing_goes_wrong(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        step.error_message = None
        self.runner.step_registry.find_match.return_value = Mock()
        step.run(self.runner)

        assert step.status == Status.passed
        assert step.error_message is None
예제 #8
0
    def test_run_sets_status_to_passed_if_nothing_goes_wrong(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        step.error_message = None
        self.runner.step_registry.find_match.return_value = Mock()
        step.run(self.runner)

        assert step.status == Status.passed
        assert step.error_message is None
예제 #9
0
    def test_run_sets_status_to_failed_on_assertion_error(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(AssertionError('whee'))
        self.runner.step_registry.find_match.return_value = match
        step.run(self.runner)

        eq_(step.status, 'failed')
        assert step.error_message.startswith('Assertion Failed')
예제 #10
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_sets_status_to_failed_on_assertion_error(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(AssertionError('whee'))
        self.runner.step_registry.find_match.return_value = match
        step.run(self.runner)

        eq_(step.status, 'failed')
        assert step.error_message.startswith('Assertion Failed')
예제 #11
0
    def test_run_sets_text_if_present(self):
        step = Step("foo.feature",
                    17,
                    u"Given",
                    "given",
                    u"foo",
                    text=Mock(name="text"))
        self.runner.step_registry.find_match.return_value = Mock()
        step.run(self.runner)

        assert self.context.text == step.text
예제 #12
0
    def test_run_sets_status_to_failed_on_exception(self, format_exc):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(Exception("whee"))
        self.runner.step_registry.find_match.return_value = match
        format_exc.return_value = "something to do with an exception"

        step.run(self.runner)
        assert step.status == Status.failed
        assert step.error_message == format_exc.return_value
예제 #13
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_sets_text_if_present(self):
        step = Step('foo.feature',
                    17,
                    u'Given',
                    'given',
                    u'foo',
                    text=Mock(name='text'))
        self.runner.step_registry.find_match.return_value = Mock()
        step.run(self.runner)

        eq_(self.context.text, step.text)
예제 #14
0
    def test_run_sets_status_to_failed_on_exception(self, format_exc):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(Exception('whee'))
        self.runner.step_registry.find_match.return_value = match
        format_exc.return_value = 'something to do with an exception'

        step.run(self.runner)
        eq_(step.status, Status.failed)
        eq_(step.error_message, format_exc.return_value)
예제 #15
0
파일: test_model.py 프로젝트: behave/behave
    def test_run_sets_status_to_failed_on_exception(self, format_exc):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(Exception("whee"))
        self.runner.step_registry.find_match.return_value = match
        format_exc.return_value = "something to do with an exception"

        step.run(self.runner)
        assert step.status == Status.failed
        assert step.error_message == format_exc.return_value
예제 #16
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_sets_status_to_failed_on_exception(self, format_exc):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(Exception('whee'))
        self.runner.step_registry.find_match.return_value = match
        format_exc.return_value = 'something to do with an exception'

        step.run(self.runner)
        eq_(step.status, 'failed')
        eq_(step.error_message, format_exc.return_value)
예제 #17
0
    def test_run_when_quiet_reports_nothing(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        side_effects = (None, raiser(AssertionError('whee')),
                        raiser(Exception('whee')))
        for side_effect in side_effects:
            match.run.side_effect = side_effect
            step.run(self.runner, quiet=True)
            assert not self.formatters[0].match.called
            assert not self.formatters[0].result.called
예제 #18
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_when_quiet_reports_nothing(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        side_effects = (None, raiser(AssertionError('whee')),
                        raiser(Exception('whee')))
        for side_effect in side_effects:
            match.run.side_effect = side_effect
            step.run(self.runner, quiet=True)
            assert not self.formatters[0].match.called
            assert not self.formatters[0].result.called
예제 #19
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_when_not_quiet_reports_match_and_result(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        side_effects = (None, raiser(AssertionError('whee')),
                        raiser(Exception('whee')))
        for side_effect in side_effects:
            match.run.side_effect = side_effect
            step.run(self.runner)
            self.formatters[0].match.assert_called_with(match)
            self.formatters[0].result.assert_called_with(step)
예제 #20
0
    def test_run_when_not_quiet_reports_match_and_result(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        side_effects = (None, raiser(AssertionError('whee')),
                        raiser(Exception('whee')))
        for side_effect in side_effects:
            match.run.side_effect = side_effect
            step.run(self.runner)
            self.formatters[0].match.assert_called_with(match)
            self.formatters[0].result.assert_called_with(step)
예제 #21
0
    def test_run_sets_status_to_failed_on_assertion_error(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        self.runner.context = Context(self.runner)
        self.runner.config.stdout_capture = True
        self.runner.config.log_capture = False
        self.runner.capture_controller = CaptureController(self.runner.config)
        self.runner.capture_controller.setup_capture(self.runner.context)
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(AssertionError('whee'))
        self.runner.step_registry.find_match.return_value = match
        step.run(self.runner)

        eq_(step.status, Status.failed)
        assert step.error_message.startswith('Assertion Failed')
예제 #22
0
    def test_run_sets_status_to_failed_on_assertion_error(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        self.runner.context = Context(self.runner)
        self.runner.config.stdout_capture = True
        self.runner.config.log_capture = False
        self.runner.capture_controller = CaptureController(self.runner.config)
        self.runner.capture_controller.setup_capture(self.runner.context)
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(AssertionError("whee"))
        self.runner.step_registry.find_match.return_value = match
        step.run(self.runner)

        assert step.status == Status.failed
        assert step.error_message.startswith("Assertion Failed")
예제 #23
0
    def test_run_sets_status_to_failed_on_assertion_error(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        self.runner.context = Context(self.runner)
        self.runner.config.stdout_capture = True
        self.runner.config.log_capture = False
        self.runner.capture_controller = CaptureController(self.runner.config)
        self.runner.capture_controller.setup_capture(self.runner.context)
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(AssertionError('whee'))
        self.runner.step_registry.find_match.return_value = match
        step.run(self.runner)

        eq_(step.status, Status.failed)
        assert step.error_message.startswith('Assertion Failed')
예제 #24
0
파일: test_model.py 프로젝트: behave/behave
    def test_run_sets_status_to_failed_on_assertion_error(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        self.runner.context = Context(self.runner)
        self.runner.config.stdout_capture = True
        self.runner.config.log_capture = False
        self.runner.capture_controller = CaptureController(self.runner.config)
        self.runner.capture_controller.setup_capture(self.runner.context)
        step.error_message = None
        match = Mock()
        match.run.side_effect = raiser(AssertionError("whee"))
        self.runner.step_registry.find_match.return_value = match
        step.run(self.runner)

        assert step.status == Status.failed
        assert step.error_message.startswith("Assertion Failed")
예제 #25
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_with_no_match_does_not_touch_formatter_when_quiet(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        self.runner.step_registry.find_match.return_value = None
        assert not step.run(self.runner, quiet=True)

        assert not self.formatters[0].match.called
        assert not self.formatters[0].result.called
예제 #26
0
    def test_run_reports_undefined_step_via_formatter_when_not_quiet(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        self.runner.step_registry.find_match.return_value = None
        assert not step.run(self.runner)

        self.formatters[0].match.assert_called_with(NoMatch())
        self.formatters[0].result.assert_called_with(step)
예제 #27
0
    def test_run_with_no_match_does_not_touch_formatter_when_quiet(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        self.runner.step_registry.find_match.return_value = None
        assert not step.run(self.runner, quiet=True)

        assert not self.formatters[0].match.called
        assert not self.formatters[0].result.called
예제 #28
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_reports_undefined_step_via_formatter_when_not_quiet(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        self.runner.step_registry.find_match.return_value = None
        assert not step.run(self.runner)

        self.formatters[0].match.assert_called_with(NoMatch())
        self.formatters[0].result.assert_called_with(step)
예제 #29
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_appends_step_to_undefined_when_no_match_found(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        self.runner.step_registry.find_match.return_value = None
        self.runner.undefined_steps = []
        assert not step.run(self.runner)

        assert step in self.runner.undefined_steps
        eq_(step.status, 'undefined')
예제 #30
0
파일: test_model.py 프로젝트: behave/behave
    def test_run_appends_step_to_undefined_when_no_match_found(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        self.runner.step_registry.find_match.return_value = None
        self.runner.undefined_steps = []
        assert not step.run(self.runner)

        assert step in self.runner.undefined_steps
        assert step.status == Status.undefined
예제 #31
0
    def test_run_appends_step_to_undefined_when_no_match_found(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        self.runner.step_registry.find_match.return_value = None
        self.runner.undefined_steps = []
        assert not step.run(self.runner)

        assert step in self.runner.undefined_steps
        assert step.status == Status.undefined
예제 #32
0
    def test_run_appends_step_to_undefined_when_no_match_found(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        self.runner.step_registry.find_match.return_value = None
        self.runner.undefined_steps = []
        assert not step.run(self.runner)

        assert step in self.runner.undefined_steps
        eq_(step.status, Status.undefined)
예제 #33
0
    def test_run_captures_stdout_and_logging(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        assert step.run(self.runner)

        self.runner.start_capture.assert_called_with()
        self.runner.stop_capture.assert_called_with()
예제 #34
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_captures_stdout_and_logging(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        assert step.run(self.runner)

        self.runner.start_capture.assert_called_with()
        self.runner.stop_capture.assert_called_with()
예제 #35
0
    def test_run_appends_any_captured_logging_on_failure(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match
        self.log_capture.getvalue.return_value = 'toads'
        match.run.side_effect = raiser(AssertionError('kipper'))

        assert not step.run(self.runner)
        assert 'Captured logging:' in step.error_message
        assert 'toads' in step.error_message
예제 #36
0
    def test_run_appends_any_captured_stdout_on_failure(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match
        self.stdout_capture.getvalue.return_value = 'frogs'
        match.run.side_effect = raiser(Exception('halibut'))

        assert not step.run(self.runner)
        assert 'Captured stdout:' in step.error_message
        assert 'frogs' in step.error_message
예제 #37
0
    def test_run_calculates_duration(self, time_time):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        def time_time_1():
            def time_time_2():
                return 23
            time_time.side_effect = time_time_2
            return 17

        side_effects = (None, raiser(AssertionError('whee')),
                        raiser(Exception('whee')))
        for side_effect in side_effects:
            match.run.side_effect = side_effect
            time_time.side_effect = time_time_1

            step.run(self.runner)
            eq_(step.duration, 23 - 17)
예제 #38
0
파일: test_model.py 프로젝트: behave/behave
    def test_run_appends_any_captured_logging_on_failure(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        match = Mock()
        self.runner.step_registry.find_match.return_value = match
        self.log_capture.getvalue.return_value = "toads"
        match.run.side_effect = raiser(AssertionError("kipper"))

        assert not step.run(self.runner)
        assert "Captured logging:" in step.error_message
        assert "toads" in step.error_message
예제 #39
0
    def test_run_appends_any_captured_stdout_on_failure(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        match = Mock()
        self.runner.step_registry.find_match.return_value = match
        self.stdout_capture.getvalue.return_value = "frogs"
        match.run.side_effect = raiser(Exception("halibut"))

        assert not step.run(self.runner)
        assert "Captured stdout:" in step.error_message
        assert "frogs" in step.error_message
예제 #40
0
    def test_run_appends_any_captured_logging_on_failure(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        match = Mock()
        self.runner.step_registry.find_match.return_value = match
        self.log_capture.getvalue.return_value = "toads"
        match.run.side_effect = raiser(AssertionError("kipper"))

        assert not step.run(self.runner)
        assert "Captured logging:" in step.error_message
        assert "toads" in step.error_message
예제 #41
0
파일: test_model.py 프로젝트: behave/behave
    def test_run_calculates_duration(self, time_time):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        def time_time_1():
            def time_time_2():
                return 23
            time_time.side_effect = time_time_2
            return 17

        side_effects = (None, raiser(AssertionError("whee")),
                        raiser(Exception("whee")))
        for side_effect in side_effects:
            match.run.side_effect = side_effect
            time_time.side_effect = time_time_1

            step.run(self.runner)
            assert step.duration == (23 - 17)
예제 #42
0
파일: test_model.py 프로젝트: behave/behave
    def test_run_appends_any_captured_stdout_on_failure(self):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        match = Mock()
        self.runner.step_registry.find_match.return_value = match
        self.stdout_capture.getvalue.return_value = "frogs"
        match.run.side_effect = raiser(Exception("halibut"))

        assert not step.run(self.runner)
        assert "Captured stdout:" in step.error_message
        assert "frogs" in step.error_message
예제 #43
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_appends_any_captured_stdout_on_failure(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match
        self.stdout_capture.getvalue.return_value = 'frogs'
        match.run.side_effect = raiser(Exception('halibut'))

        assert not step.run(self.runner)
        assert 'Captured stdout:' in step.error_message
        assert 'frogs' in step.error_message
예제 #44
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_appends_any_captured_logging_on_failure(self):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match
        self.log_capture.getvalue.return_value = 'toads'
        match.run.side_effect = raiser(AssertionError('kipper'))

        assert not step.run(self.runner)
        assert 'Captured logging:' in step.error_message
        assert 'toads' in step.error_message
예제 #45
0
    def test_run_calculates_duration(self, time_time):
        step = Step("foo.feature", 17, u"Given", "given", u"foo")
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        def time_time_1():
            def time_time_2():
                return 23

            time_time.side_effect = time_time_2
            return 17

        side_effects = (None, raiser(AssertionError("whee")),
                        raiser(Exception("whee")))
        for side_effect in side_effects:
            match.run.side_effect = side_effect
            time_time.side_effect = time_time_1

            step.run(self.runner)
            assert step.duration == (23 - 17)
예제 #46
0
파일: test_model.py 프로젝트: unklhe/behave
    def test_run_calculates_duration(self, time_time):
        step = Step('foo.feature', 17, u'Given', 'given', u'foo')
        match = Mock()
        self.runner.step_registry.find_match.return_value = match

        def time_time_1():
            def time_time_2():
                return 23

            time_time.side_effect = time_time_2
            return 17

        side_effects = (None, raiser(AssertionError('whee')),
                        raiser(Exception('whee')))
        for side_effect in side_effects:
            match.run.side_effect = side_effect
            time_time.side_effect = time_time_1

            step.run(self.runner)
            eq_(step.duration, 23 - 17)