Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the official gherkin parser #698

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1a2baff
First commit for using the official gherkin parser (trying to maintai…
jsa34 Sep 5, 2024
65c06e4
Improve docstrings in parser.py
jsa34 Sep 5, 2024
abe5e79
Improve docstrings in parser.py
jsa34 Sep 5, 2024
240ac6d
Fix issues and create a FeatureParser class to consolidate parsing logic
jsa34 Sep 5, 2024
e7b5326
Forgot to go back and implement the templated bool
jsa34 Sep 6, 2024
2f3e029
Remove unused import
jsa34 Sep 6, 2024
cc9b37f
Move Gherkin parsing to pydantic models for easier future reference o…
jsa34 Sep 6, 2024
4e17ccb
Move the calculating of given/when/then to pydantic models, as well a…
jsa34 Sep 6, 2024
57b9e55
Fix silly mistakes
jsa34 Sep 6, 2024
ff1a926
Fix type hints for py3.8
jsa34 Sep 6, 2024
21afdb1
Response to feedback
jsa34 Sep 8, 2024
fec8270
Another grammar fix
jsa34 Sep 8, 2024
6676692
Use dataclasses and not attr
jsa34 Sep 8, 2024
becfed2
Response to feedback
jsa34 Sep 12, 2024
2c8455b
Response to feedback
jsa34 Sep 12, 2024
c3008c1
Couple of tidy ups
jsa34 Sep 12, 2024
9c12dbf
Forgot to fix background in steps and revert test that was skipped
jsa34 Sep 12, 2024
93a11ae
Fix import (Python < 3.11 compat)
youtux Sep 14, 2024
fee0eb9
Remove default to None
youtux Sep 14, 2024
7cbfc47
Revert string literals to their original form
youtux Sep 15, 2024
2f3acbd
Response to feedback and make mypy happy.
jsa34 Sep 15, 2024
9b45269
Merge remote-tracking branch 'origin/gherkin-official-parser' into gh…
jsa34 Sep 15, 2024
a3a5195
Do not fail the CI job if we can't upload to Codecov.
youtux Sep 16, 2024
656c7ce
Ignore py3.13 failures for now
youtux Sep 16, 2024
d11096f
Fix matching result in case there are warnings
youtux Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Changelog

Unreleased
----------
- Use `gherkin-official` parser to replace custom parsing logic.
- Multiline steps must now always use triple-quotes for the additional lines.
- All feature files must now use the keyword `Feature:` to be considered valid.
- Tags can no longer have spaces (e.g. "@tag one" "@tag two" are no longer valid).

7.2.0
----------
Expand Down
367 changes: 199 additions & 168 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ parse-type = "*"
pytest = ">=6.2.0"
typing-extensions = "*"
packaging = "*"
gherkin-official = "^29.0.0"

[tool.poetry.group.dev.dependencies]
tox = ">=4.11.3"
Expand Down
59 changes: 53 additions & 6 deletions src/pytest_bdd/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,58 @@ class NoScenariosFound(Exception):
"""No scenarios found."""


class FeatureError(Exception):
"""Feature parse error."""
class GherkinParseError(Exception):
"""Base class for all Gherkin parsing errors."""

message = "{0}.\nLine number: {1}.\nLine: {2}.\nFile: {3}"
def __init__(self, message, line, line_content, filename):
super().__init__(message)
self.message = message
self.line = line
self.line_content = line_content
self.filename = filename
self.line = line
self.line_content = line_content
self.filename = filename

def __str__(self) -> str:
"""String representation."""
return self.message.format(*self.args)
def __str__(self):
return f"{self.__class__.__name__}: {self.message}\nLine number: {self.line}\nLine: {self.line_content}\nFile: {self.filename}"


class FeatureError(GherkinParseError):
pass


class BackgroundError(GherkinParseError):
pass


class ScenarioOutlineError(GherkinParseError):
pass


class ScenarioError(GherkinParseError):
pass


class ExamplesError(GherkinParseError):
pass


class StepError(GherkinParseError):
pass


class TagError(GherkinParseError):
pass


class RuleError(GherkinParseError):
pass


class DocStringError(GherkinParseError):
pass


class TokenError(GherkinParseError):
pass
4 changes: 2 additions & 2 deletions src/pytest_bdd/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import glob
import os.path

from .parser import Feature, parse_feature
from .parser import Feature, FeatureParser

# Global features dictionary
features: dict[str, Feature] = {}
Expand All @@ -52,7 +52,7 @@ def get_feature(base_path: str, filename: str, encoding: str = "utf-8") -> Featu
full_name = os.path.abspath(os.path.join(base_path, filename))
feature = features.get(full_name)
if not feature:
feature = parse_feature(base_path, filename, encoding=encoding)
feature = FeatureParser(base_path, filename, encoding).parse()
features[full_name] = feature
return feature

Expand Down
Loading
Loading