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

Rewrite parser #395

Draft
wants to merge 65 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
38576fd
Draft rewrite of the parser
youtux Sep 13, 2020
1d8f81e
Move most of the parsing logic to its own module
youtux Sep 13, 2020
4fc0570
Remove Feature.get_feature, in favour of the get_feature function
youtux Sep 13, 2020
59c8e7c
self -> feature
youtux Sep 13, 2020
d6c541f
Fix circular import
youtux Sep 13, 2020
c77ae52
Move all the parsing models to the parser module.
youtux Sep 13, 2020
d47abb7
Merge branch 'refactor-classes' into rewrite-parser
youtux Sep 15, 2020
37a4ce0
Move new parser out of the parser directory
youtux Sep 15, 2020
0d447dc
Basic tests for the new parser!
youtux Sep 15, 2020
25eaebd
Merge branch 'master' into rewrite-parser
youtux Sep 15, 2020
4e0cbb0
Test some real usage of the new parser!
youtux Sep 15, 2020
e43fd15
Step docstrings and datatables!
youtux Sep 15, 2020
f3d363e
Commit something made a long time ago, not sure what the idea was
youtux Jul 3, 2021
7c714f5
Merge remote-tracking branch 'origin/master' into rewrite-parser
youtux Mar 5, 2022
c15669e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 5, 2022
615b247
Fix types
youtux Mar 5, 2022
1494d5a
Fixes after the merge
youtux Mar 5, 2022
275f98d
"And" steps!
youtux Mar 6, 2022
d4e5989
Do not require "\n" at the end of file
youtux Mar 6, 2022
5fedd7d
support comments! and remove docstring and data_table for now
youtux Mar 6, 2022
31af297
support feature background
youtux Mar 8, 2022
559c0f9
tags in feature and scenario
youtux Mar 8, 2022
b24b3b3
feature description!
youtux Mar 9, 2022
ded1189
Fix test
youtux Mar 9, 2022
cbfc24d
Allow arbitrary indentation for the "Feature:" token [skip pre-commit…
youtux Mar 9, 2022
7fac701
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 9, 2022
67d793d
Examples! (still a failing test in case there is an escaped pipe [ski…
youtux Mar 9, 2022
0868325
Merge remote-tracking branch 'origin/rewrite-parser' into rewrite-parser
youtux Mar 9, 2022
8ca8f60
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 9, 2022
c7b00c6
Examples! (still a failing test in case there is an escaped pipe [ski…
youtux Mar 9, 2022
1a3dd4e
Disable trailing-whitespace linter, as it's creating problem when tes…
youtux Mar 9, 2022
10ce8a5
Fix example cells
youtux Mar 10, 2022
ea96c49
Fix typing
youtux Mar 10, 2022
27b7e99
Scenario outline
youtux Mar 10, 2022
cc130b6
Fix tags, and no need for space at the end of the keyword
youtux Mar 10, 2022
e15cebd
Fix wrong examples
youtux Mar 10, 2022
f095b45
According to gherkin specs, comments can only be on a new line
youtux Mar 11, 2022
4778cf5
Fix tests
youtux Mar 11, 2022
cdbf1a5
Add "But " keyword
youtux Mar 11, 2022
9fe746c
Fix tests
youtux Mar 11, 2022
ac11610
Add change
youtux Mar 11, 2022
2f0c851
Fix test
youtux Mar 11, 2022
c3605ec
Fix test
youtux Mar 11, 2022
a6523e0
Use attrs and implement test comprehensively
youtux Mar 11, 2022
99b61fd
More attrs
youtux Mar 11, 2022
260b7f2
Keyword should be without trailing spaces
youtux Mar 11, 2022
ad86cfe
Fix tests
youtux Mar 11, 2022
163a015
Fix tests
youtux Mar 11, 2022
a10e93a
Use dataclass instead of attrs, one less dependency.
youtux Mar 11, 2022
e3e0cff
Require "Scenario Outline" keyword for outlined scenario.
youtux Mar 12, 2022
4bcdba4
Steps and Feature are not hashable, don't attempt to put them in a se…
youtux Mar 12, 2022
f3d383d
Test punctuation in tags
youtux Mar 12, 2022
9c37f09
Step docstrings! (1 test still failing though)
youtux Mar 12, 2022
561b8ed
Finally handle docstrings that have their own indentation level
youtux Mar 12, 2022
ef7d625
Finally handle docstrings that have their own indentation level
youtux Mar 12, 2022
28a58ee
What is that _NL doing there??
youtux Mar 12, 2022
acbd1ee
Add test
youtux Mar 12, 2022
f73efac
Datatables!
youtux Mar 13, 2022
8f9c263
Add some validation logic.
youtux Mar 13, 2022
c9a9aeb
Actually invoke validation in tests
youtux Mar 13, 2022
4ee87fe
Only "Givens" are allowed in "Background"
youtux Mar 13, 2022
350f2ea
Add some error reporting!
youtux Mar 14, 2022
4bffdd2
Docstring errors!
youtux Mar 14, 2022
be0679f
Simplify docstring def
youtux Mar 21, 2022
41c8ce6
Tests for invalid table
youtux Mar 21, 2022
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: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
# disabled because it goes in the way when testing
# gherkin files with weird whitespaces on purpose
# - id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
Expand Down
10 changes: 9 additions & 1 deletion pytest_bdd/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ 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)
from pytest_bdd.scenario import get_from_ini

parser = get_from_ini("bdd_parser", "legacy")
if parser == "legacy":
feature = parse_feature(base_path, filename, encoding=encoding)
elif parser == "2020":
from . import new_parser

feature = new_parser.parse_feature(base_path, filename)
features[full_name] = feature
return feature

Expand Down
5 changes: 3 additions & 2 deletions pytest_bdd/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def print_missing_code(scenarios: list[ScenarioTemplate], steps: list[Step]) ->
tw.line()

features = sorted(
{scenario.feature for scenario in scenarios}, key=lambda feature: feature.name or feature.filename
(scenario.feature for scenario in scenarios), key=lambda feature: feature.name or feature.filename
)
code = generate_code(features, scenarios, steps)
tw.write(code)
Expand Down Expand Up @@ -152,7 +152,8 @@ def parse_feature_files(paths: list[str], **kwargs: Any) -> tuple[list[Feature],
key=lambda scenario: (scenario.feature.name or scenario.feature.filename, scenario.name),
)
steps = sorted(
set(itertools.chain.from_iterable(scenario.steps for scenario in scenarios)), key=lambda step: step.name
(step for scenario in scenarios for step in scenario.steps),
key=lambda step: step.name,
)
return features, scenarios, steps

Expand Down
Loading