Ejemplo n.º 1
0
 def parse_scenario_outline(self, json_element):
     """
     self.add_feature_element({
         'keyword': scenario_outline.keyword,
         'name': scenario_outline.name,
         'tags': scenario_outline.tags,
         'location': scenario_outline.location,
         'steps': [],
         'examples': [],
     })
     """
     keyword = json_element.get("keyword", u"")
     name    = json_element.get("name", u"")
     description = json_element.get("description", [])
     tags    = json_element.get("tags", [])
     location = json_element.get("location", u"")
     json_steps = json_element.get("steps", [])
     json_examples = json_element.get("examples", [])
     steps = self.parse_steps(json_steps)
     examples = []
     if json_examples:
         examples = self.parse_examples(json_examples)
     filename, line = location.split(":")
     scenario_outline = model.ScenarioOutline(filename, line, keyword, name,
                             tags=tags, steps=steps, examples=examples)
     scenario_outline.description = description
     return scenario_outline
Ejemplo n.º 2
0
    def action_steps(self, line):
        stripped = line.lstrip()
        if stripped.startswith('"""') or stripped.startswith("'''"):
            self.state = 'multiline'
            self.multiline_start = self.line
            self.multiline_terminator = stripped[:3]
            self.multiline_leading = line.index(stripped[0])
            return True

        line = line.strip()

        step = self.parse_step(line)
        if step:
            self.statement.steps.append(step)
            return True

        if line.startswith('@'):
            self.tags.extend([model.Tag(tag.strip(), self.line)
                for tag in line[1:].split('@')])
            return True

        scenario_kwd = self.match_keyword('scenario', line)
        if scenario_kwd:
            name = line[len(scenario_kwd) + 1:].strip()
            self.statement = model.Scenario(self.filename, self.line,
                                            scenario_kwd, name, tags=self.tags)
            self.tags = []
            self.feature.add_scenario(self.statement)
            return True

        scenario_outline_kwd = self.match_keyword('scenario_outline', line)
        if scenario_outline_kwd:
            name = line[len(scenario_outline_kwd) + 1:].strip()
            self.statement = model.ScenarioOutline(self.filename, self.line,
                                                   scenario_outline_kwd, name,
                                                   tags=self.tags)
            self.tags = []
            self.feature.add_scenario(self.statement)
            self.state = 'steps'
            return True

        examples_kwd = self.match_keyword('examples', line)
        if examples_kwd:
            if not isinstance(self.statement, model.ScenarioOutline):
                message = 'Examples must only appear inside scenario outline'
                raise ParserError(message, self.line)
            name = line[len(examples_kwd) + 1:].strip()
            self.examples = model.Examples(self.filename, self.line,
                                           examples_kwd, name)
            self.statement.examples.append(self.examples)
            self.state = 'table'
            return True

        if line.startswith('|'):
            self.state = 'table'
            return self.action_table(line)

        return False
Ejemplo n.º 3
0
 def _build_scenario_outline_statement(self, keyword, line):
     # pylint: disable=C0103
     #   C0103   Invalid name "build_scenario_outline_statement", too long.
     name = line[len(keyword) + 1:].strip()
     self.statement = model.ScenarioOutline(self.filename, self.line,
                                            keyword, name, tags=self.tags)
     self.feature.add_scenario(self.statement)
     # -- RESET STATE:
     self.tags = []
Ejemplo n.º 4
0
    def test_run_calls_run_on_each_generated_scenario(self):
        outline = model.ScenarioOutline('foo.featuer', 17, u'Scenario Outline',
                                        u'foo')
        outline._scenarios = [Mock(), Mock()]
        for scenario in outline._scenarios:
            scenario.run.return_value = False

        runner = Mock()
        runner.context = Mock()

        outline.run(runner)

        [s.run.assert_called_with(runner) for s in outline._scenarios]
Ejemplo n.º 5
0
    def test_run_should_pass_when_all_examples_pass(self):
        outline = model.ScenarioOutline('foo.feature', 17, u'Scenario Outline',
                                        u'foo')
        outline._scenarios = [Mock(), Mock(), Mock()]
        for scenario in outline._scenarios:
            scenario.run.return_value = False

        runner = Mock()
        context = runner.context = Mock()
        config = runner.config = Mock()
        config.stop = True

        resultFailed = outline.run(runner)
        eq_(resultFailed, False)
Ejemplo n.º 6
0
    def test_run_stops_on_first_failure_if_requested(self):
        outline = model.ScenarioOutline('foo.featuer', 17, u'Scenario Outline',
                                        u'foo')
        outline._scenarios = [Mock(), Mock()]
        outline._scenarios[0].run.return_value = True

        runner = Mock()
        runner.context = Mock()
        config = runner.config = Mock()
        config.stop = True

        outline.run(runner)

        outline._scenarios[0].run.assert_called_with(runner)
        assert not outline._scenarios[1].run.called
Ejemplo n.º 7
0
    def test_run_should_fail_when_last_examples_fails(self):
        outline = model.ScenarioOutline('foo.feature', 17, u'Scenario Outline',
                                        u'foo')
        failed = True
        outline._scenarios = [Mock(), Mock()]
        outline._scenarios[0].run.return_value = not failed
        outline._scenarios[1].run.return_value = failed

        runner = Mock()
        context = runner.context = Mock()
        config = runner.config = Mock()
        config.stop = True

        resultFailed = outline.run(runner)
        eq_(resultFailed, True)
Ejemplo n.º 8
0
    def action_feature(self, line):
        line = line.strip()

        if line.startswith('@'):
            self.tags.extend(self.parse_tags(line))
            return True

        background_kwd = self.match_keyword('background', line)
        if background_kwd:
            name = line[len(background_kwd) + 1:].strip()
            self.statement = model.Background(self.filename, self.line,
                                              background_kwd, name)
            self.feature.background = self.statement
            self.state = 'steps'
            return True

        scenario_kwd = self.match_keyword('scenario', line)
        if scenario_kwd:
            name = line[len(scenario_kwd) + 1:].strip()
            self.statement = model.Scenario(self.filename,
                                            self.line,
                                            scenario_kwd,
                                            name,
                                            tags=self.tags)
            self.tags = []
            self.feature.add_scenario(self.statement)
            self.state = 'steps'
            return True

        scenario_outline_kwd = self.match_keyword('scenario_outline', line)
        if scenario_outline_kwd:
            name = line[len(scenario_outline_kwd) + 1:].strip()
            self.statement = model.ScenarioOutline(self.filename,
                                                   self.line,
                                                   scenario_outline_kwd,
                                                   name,
                                                   tags=self.tags)
            self.tags = []
            self.feature.add_scenario(self.statement)
            self.state = 'steps'
            return True

        self.feature.description.append(line)
        return True
Ejemplo n.º 9
0
    def test_run_sets_context_variable_for_outline(self):
        outline = model.ScenarioOutline('foo.featuer', 17, u'Scenario Outline',
                                        u'foo')
        outline._scenarios = [Mock(), Mock(), Mock()]
        for scenario in outline._scenarios:
            scenario.run.return_value = False

        runner = Mock()
        context = runner.context = Mock()
        config = runner.config = Mock()
        config.stop = True

        outline.run(runner)

        eq_(context._set_root_attribute.call_args_list, [
            (('active_outline', outline._scenarios[0]._row), {}),
            (('active_outline', outline._scenarios[1]._row), {}),
            (('active_outline', outline._scenarios[2]._row), {}),
            (('active_outline', None), {}),
        ])