Пример #1
0
def test_compiles_a_scenario():
    feature_text = textwrap.dedent(
        """\
        Feature: f
          Scenario: s
            Given passing
        """)
    id_generator = IdGenerator()
    gherkin_document = Parser(AstBuilder(id_generator)).parse(feature_text)
    gherkin_document['uri'] = 'uri'
    pickle = Compiler(id_generator).compile(gherkin_document)
    expected_pickle = textwrap.dedent(
        """\
        [
          {
            "id": "3",
            "astNodeIds": ["1"],
            "name": "s",
            "language": "en",
            "steps": [
              {
                "id": "2",
                "astNodeIds": ["0"],
                "type": "Context",
                "text": "passing"
              }
            ],
            "tags": [],
            "uri": "uri"
          }
        ]
        """
    )

    assert pickle == json.loads(expected_pickle)
Пример #2
0
class GherkinEvents:
    def __init__(self, options):
        self.options = options
        self.id_generator = IdGenerator()
        self.parser = Parser(ast_builder=AstBuilder(self.id_generator))
        self.compiler = Compiler(self.id_generator)

    def enum(self, source_event):
        uri = source_event['source']['uri']
        source = source_event['source']['data']

        try:
            gherkin_document = self.parser.parse(source)
            gherkin_document['uri'] = uri

            if (self.options.print_source):
                yield source_event

            if (self.options.print_ast):
                yield {'gherkinDocument': gherkin_document}

            if (self.options.print_pickles):
                pickles = self.compiler.compile(gherkin_document)
                for pickle in pickles:
                    yield {'pickle': pickle}
        except CompositeParserException as e:
            for event in create_errors(e.errors, uri):
                yield event
        except ParserError as e:
            for event in create_errors([e], uri):
                yield event
Пример #3
0
def test_compiles_a_scenario_outline_with_i18n_characters():
    feature_text = textwrap.dedent("""\
        Feature: f
          Scenario Outline: with 'é' in title
            Given <with-é>
            Examples:
            | with-é  |
            | passing |
        """)
    id_generator = IdGenerator()
    gherkin_document = Parser(AstBuilder(id_generator)).parse(feature_text)
    gherkin_document['uri'] = 'uri'
    pickle = Compiler(id_generator).compile(gherkin_document)
    expected_pickle = textwrap.dedent("""\
        [
          {
            "id": "6",
            "astNodeIds": ["4", "2"],
            "name": "with 'é' in title",
            "language": "en",
            "steps": [
              {
                "id": "5",
                "astNodeIds": ["0", "2"],
                "text": "passing"
              }
            ],
            "tags": [],
            "uri": "uri"
          }
        ]
        """)

    assert_equals(pickle, json.loads(expected_pickle))
Пример #4
0
 def __init__(self, options):
     self.options = options
     self.id_generator = IdGenerator()
     self.parser = Parser(ast_builder=AstBuilder(self.id_generator))
     self.compiler = Compiler(self.id_generator)