Ejemplo n.º 1
0
    def enum(self, source_event):
        uri = source_event['uri']
        source = source_event['data']

        events = []

        try:
            gherkin_document = self.parser.parse(source)

            if (self.options.print_source):
                events.append(source_event)

            if (self.options.print_ast):
                events.append({
                    'type': 'gherkin-document',
                    'uri': uri,
                    'document': gherkin_document
                })

            if (self.options.print_pickles):
                pickles = compile(gherkin_document)
                for pickle in pickles:
                    events.append({
                        'type': 'pickle',
                        'uri': uri,
                        'pickle': pickle
                    })
        except CompositeParserException as e:
            add_errors(events, e.errors, uri)
        except ParserError as e:
            add_errors(events, [e], uri)

        return events
Ejemplo n.º 2
0
    def enum(self, source_event):
        uri = source_event['uri']
        source = source_event['data']

        events = []

        try:
            gherkin_document = self.parser.parse(source)

            if (self.options.print_source):
                events.append(source_event)

            if (self.options.print_ast):
                events.append({
                    'type': 'gherkin-document',
                    'uri': uri,
                    'document': gherkin_document
                })

            if (self.options.print_pickles):
                pickles = compile(gherkin_document)
                for pickle in pickles:
                    events.append({
                        'type': 'pickle',
                        'uri': uri,
                        'pickle': pickle
                    })
        except CompositeParserException as e:
            add_errors(events, e.errors, uri)
        except ParserError as e:
            add_errors(events, [e], uri)

        return events
Ejemplo n.º 3
0
    def _read_gherkin(self, gherkin_document):
        try:
            pickles = compile(gherkin_document)
            feature = gherkin_document['feature']
            self._read_gherkin_feature(pickles, feature)

        except KeyError:
            pass
Ejemplo n.º 4
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 |
        """)
    output = Parser().parse(feature_text)
    pickle = compiler.compile(output, 'features/hello.feature')
    expected_pickle = textwrap.dedent(
        """\
        [
          {
            "name": "with 'é' in title",
            "steps": [
              {
                "text": "passing",
                "arguments": [],
                "locations": [
                  {
                    "line": 6,
                    "column": 5,
                    "path": "features/hello.feature"
                  },
                  {
                    "line": 3,
                    "column": 11,
                    "path": "features/hello.feature"
                  }
                ]
              }
            ],
            "tags": [],
            "locations": [
              {
                "line": 6,
                "column": 5,
                "path": "features/hello.feature"
              },
              {
                "line": 2,
                "column": 3,
                "path": "features/hello.feature"
              }
            ]
          }
        ]
        """
    )

    assert_equals(
        pickle,
        json.loads(expected_pickle)
    )
 def __init__(self, file=None, raw_text=None):
     self.raw_text = raw_text
     self.file = file
     parser = Parser()
     scanner = TokenScanner(self.file)
     try:
         self.gherkin_document = parser.parse(scanner)
         self.pickles = compiler.compile(self.gherkin_document)
         if len(self.pickles) < 1:
             raise GherkinError("no pickles found!")
     except Exception as e:
         raise GherkinError("unable to parse / pickle doc {doc}".format(
             doc=self.file)) from e
Ejemplo n.º 6
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 |
        """)
    output = Parser().parse(feature_text)
    pickle = compiler.compile(output, 'features/hello.feature')
    expected_pickle = textwrap.dedent("""\
        [
          {
            "name": "Scenario: with 'é' in title",
            "steps": [
              {
                "text": "passing",
                "arguments": [],
                "locations": [
                  {
                    "line": 6,
                    "column": 5,
                    "path": "features/hello.feature"
                  },
                  {
                    "line": 3,
                    "column": 11,
                    "path": "features/hello.feature"
                  }
                ]
              }
            ],
            "tags": [],
            "locations": [
              {
                "line": 6,
                "column": 5,
                "path": "features/hello.feature"
              },
              {
                "line": 2,
                "column": 3,
                "path": "features/hello.feature"
              }
            ]
          }
        ]
        """)

    assert_equals(pickle, json.loads(expected_pickle))
Ejemplo n.º 7
0
    def __init__(self, file=None, path=None, **defaults):
        if file is None:
            file = self
        if path is None:
            path = file.path
        super().__init__(path=path, **defaults)

        self.file = file
        self.path = file.path
        parser = Parser()
        scanner = TokenScanner(self.path)
        try:
            self.gherkin_document = parser.parse(scanner)
            self.pickles = compiler.compile(self.gherkin_document)
        except Exception as e:
            raise GherkinError("unable to parse / pickle doc {doc}".format(
                doc=self.path)) from e
Ejemplo n.º 8
0
def test_compiles_a_scenario():
    feature_text = textwrap.dedent(
        """\
        Feature: f
          Scenario: s
            Given passing
        """)
    output = Parser().parse(feature_text)
    pickle = compiler.compile(output, 'features/hello.feature')
    expected_pickle = textwrap.dedent(
        """\
        [
          {
            "name": "s",
            "steps": [
              {
                "text": "passing",
                "arguments": [],
                "locations": [
                  {
                    "line": 3,
                    "column": 11,
                    "path": "features/hello.feature"
                  }
                ]
              }
            ],
            "tags": [],
            "locations": [
              {
                "line": 2,
                "column": 3,
                "path": "features/hello.feature"
              }
            ]
          }
        ]
        """
    )

    assert_equals(
        pickle,
        json.loads(expected_pickle)
    )
Ejemplo n.º 9
0
def test_compiles_a_scenario():
    feature_text = textwrap.dedent("""\
        Feature: f
          Scenario: s
            Given passing
        """)
    output = Parser().parse(feature_text)
    pickle = compiler.compile(output, 'features/hello.feature')
    expected_pickle = textwrap.dedent("""\
        [
          {
            "name": "Scenario: s",
            "steps": [
              {
                "text": "passing",
                "arguments": [],
                "locations": [
                  {
                    "line": 3,
                    "column": 11,
                    "path": "features/hello.feature"
                  }
                ]
              }
            ],
            "tags": [],
            "locations": [
              {
                "line": 2,
                "column": 3,
                "path": "features/hello.feature"
              }
            ]
          }
        ]
        """)

    assert_equals(pickle, json.loads(expected_pickle))