Skip to content

Commit a2a00e5

Browse files
author
Ludovic CHAPELET
committed
tests: add test for parsing
1 parent 014ec83 commit a2a00e5

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

tests/parser/test_parser.py

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
22

3+
from collections import OrderedDict
34
from pathlib import Path
45

6+
from pytest_bdd.parser import Examples, Feature, ScenarioTemplate, Step
57
from src.pytest_bdd.gherkin_parser import (
68
Background,
79
Cell,
@@ -10,13 +12,11 @@
1012
DataTable,
1113
DocString,
1214
ExamplesTable,
13-
Feature,
1415
GherkinDocument,
1516
Location,
1617
Row,
1718
Rule,
1819
Scenario,
19-
Step,
2020
Tag,
2121
get_gherkin_document,
2222
)
@@ -1092,3 +1092,81 @@ def test_parser():
10921092
)
10931093

10941094
assert gherkin_doc == expected_document
1095+
1096+
1097+
def test_render_scenario_with_example_tags():
1098+
# Mock feature and context
1099+
feature = Feature(
1100+
scenarios=OrderedDict(),
1101+
filename="test.feature",
1102+
rel_filename="test.feature",
1103+
language="en",
1104+
keyword="Feature",
1105+
name="Test Feature",
1106+
tags=set(),
1107+
background=None,
1108+
line_number=1,
1109+
description="A test feature",
1110+
)
1111+
context = {"username": "user123", "password": "incorrect", "error_message": "Invalid username or password"}
1112+
1113+
# Mock examples with tags
1114+
examples = Examples(
1115+
line_number=10,
1116+
name="Example with tags",
1117+
example_params=["username", "password", "error_message"],
1118+
examples=[
1119+
["user123", "incorrect", "Invalid username or password"],
1120+
],
1121+
tags={"example_tag_1", "example_tag_2"},
1122+
)
1123+
1124+
# Mock steps
1125+
steps = [
1126+
Step(
1127+
name="Given the user enters <username> as username",
1128+
type="given",
1129+
indent=0,
1130+
line_number=2,
1131+
keyword="Given",
1132+
),
1133+
Step(
1134+
name="And the user enters <password> as password",
1135+
type="and",
1136+
indent=0,
1137+
line_number=3,
1138+
keyword="And",
1139+
),
1140+
Step(
1141+
name="Then the user should see an error message <error_message>",
1142+
type="then",
1143+
indent=0,
1144+
line_number=4,
1145+
keyword="Then",
1146+
),
1147+
]
1148+
1149+
# Create a ScenarioTemplate
1150+
scenario_template = ScenarioTemplate(
1151+
feature=feature,
1152+
keyword="Scenario Outline",
1153+
name="Test Scenario with Example Tags",
1154+
line_number=2,
1155+
templated=True,
1156+
description="A test scenario with example tags",
1157+
tags={"scenario_tag"},
1158+
examples=[examples],
1159+
)
1160+
for step in steps:
1161+
scenario_template.add_step(step)
1162+
1163+
# Render the scenario
1164+
rendered_scenario = scenario_template.render(context)
1165+
1166+
# Assertions
1167+
assert rendered_scenario.name == "Test Scenario with Example Tags"
1168+
assert len(rendered_scenario.steps) == 3
1169+
assert rendered_scenario.steps[0].name == "Given the user enters user123 as username"
1170+
assert rendered_scenario.steps[1].name == "And the user enters incorrect as password"
1171+
assert rendered_scenario.steps[2].name == "Then the user should see an error message Invalid username or password"
1172+
assert rendered_scenario.tags == {"scenario_tag", "example_tag_1", "example_tag_2"}

0 commit comments

Comments
 (0)