예제 #1
0
    def test_after_each_step_failed(self):
        """
            Test after.each_step from extension console_writer with failed step
        """
        data = threading.local()
        data.console = None

        def patched_write(text):
            text = re.sub(r"\x1b[^m]*m", "", text)
            data.console = text

        scenario_mock = Mock()
        scenario_mock.parent = None
        step = Step(1, "I test the console writer", "somefile.feature", 3, scenario_mock, False)
        step.parent = MagicMock()
        step.parent.id = 1
        step.parent.parent = Mock(spec=Feature)
        step.parent.parent.id = 1
        step.state = step.State.FAILED
        try:
            assert False, "Some assertion happend"
        except AssertionError as e:
            step.failure = utils.Failure(e)

        with patch("radish.extensions.console_writer.write", side_effect=patched_write):
            HookRegistry().call("after", "each_step", step)

            data.console.should.be.equal("""\rI test the console writer
          AssertionError: Some assertion happend""")
예제 #2
0
    def test_running_a_feature(self):
        """
            Test running a feature
        """
        data = threading.local()
        data.step_was_called = False

        def some_step(step):
            data.step_was_called = True

        feature = Feature(1, "Feature", "Some feature", "somefile.feature", 1)

        scenario = Scenario(1, 1, "Scenario", "Some scenario", "somefile.feature", 2, feature)
        feature.scenarios.append(scenario)

        step = Step(1, "Some step", "somefile.feature", 3, scenario, True)
        step.definition_func = some_step
        step.arguments = tuple()
        step.keyword_arguments = {}
        scenario.steps.append(step)

        hook_mock = Mock()
        hook_mock.call.return_value = True
        runner = Runner(hook_mock)
        runner.run_feature(feature)
        step.state.should.be.equal(Step.State.PASSED)
        data.step_was_called.should.be.true
예제 #3
0
파일: test_step.py 프로젝트: fliiiix/radish
    def test_run_step_with_keyword_arguments_passed(self):
        """
            Test running a passing step with keyword arguments
        """
        data = threading.local()
        data.step_was_run = False
        data.number = None
        data.string = None

        def step_passed(step, number, string):
            data.step_was_run = True
            data.number = int(number)
            data.string = string

        step = Step(1, "I call a passing step with string argument 'Tschau' and number argument 42", "somefile.feature", 3, None, True)
        step.definition_func = step_passed
        match = re.search("I call a passing step with string argument '(?P<string>.*?)' and number argument (?P<number>\d+)", step.sentence)
        step.arguments = match.groups()
        step.keyword_arguments = match.groupdict()

        step.state.should.be.equal(Step.State.UNTESTED)
        step.run.when.called_with().should.return_value(Step.State.PASSED)
        data.step_was_run.should.be.true
        data.number.should.be.equal(42)
        data.string.should.be.equal("Tschau")
예제 #4
0
파일: test_step.py 프로젝트: fliiiix/radish
    def test_run_step_passed(self):
        """
            Test running a passing step
        """
        data = threading.local()
        data.step_was_run = False

        def step_passed(step):
            data.step_was_run = True

        step = Step(1, "I call a passing step", "somefile.feature", 3, None, True)
        step.definition_func = step_passed
        step.arguments = re.search(step.sentence, step.sentence).groups()

        step.state.should.be.equal(Step.State.UNTESTED)
        step.run.when.called_with().should.return_value(Step.State.PASSED)
        data.step_was_run.should.be.true
예제 #5
0
파일: test_step.py 프로젝트: fliiiix/radish
    def test_run_step_failed(self):
        """
            Test running a failing step
        """
        data = threading.local()
        data.step_was_run = False

        def step_failed(step):
            data.step_was_run = True
            assert False, "This step fails by design"

        step = Step(1, "I call a failing step", "somefile.feature", 3, None, True)
        step.definition_func = step_failed
        step.arguments = re.search(step.sentence, step.sentence).groups()

        step.state.should.be.equal(Step.State.UNTESTED)
        step.run.when.called_with().should.return_value(Step.State.FAILED)
        step.failure.shouldnt.be.none
        step.failure.reason.should.be.equal("This step fails by design")
        data.step_was_run.should.be.true
예제 #6
0
    def test_running_a_step(self):
        """
            Test running a step
        """
        data = threading.local()
        data.step_was_called = False

        def some_step(step):
            data.step_was_called = True

        step = Step(1, "Some step", "somefile.feature", 3, None, True)
        step.definition_func = some_step
        step.arguments = tuple()
        step.keyword_arguments = {}

        hook_mock = Mock()
        hook_mock.call.return_value = True
        runner = Runner(hook_mock)
        runner.run_step(step)
        step.state.should.be.equal(Step.State.PASSED)
        data.step_was_called.should.be.true
예제 #7
0
    def test_after_each_step(self):
        """
            Test after.each_step from extension console_writer
        """
        data = threading.local()
        data.console = None

        def patched_write(text):
            text = re.sub(r"\x1b[^m]*m", "", text)
            data.console = text

        scenario_mock = Mock()
        scenario_mock.parent = None
        step = Step(1, "I test the console writer", "somefile.feature", 3, scenario_mock, False)
        step.parent = Mock()
        step.parent.id = 1
        step.parent.parent = Mock(spec=Feature)
        step.parent.parent.id = 1

        with patch("radish.extensions.console_writer.write", side_effect=patched_write):
            HookRegistry().call("after", "each_step", step)

            data.console.should.be.equal("\rI test the console writer")