|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +from collections import OrderedDict |
3 | 4 | from pathlib import Path
|
4 | 5 |
|
| 6 | +from pytest_bdd.parser import Examples, Feature, ScenarioTemplate, Step |
5 | 7 | from src.pytest_bdd.gherkin_parser import (
|
6 | 8 | Background,
|
7 | 9 | Cell,
|
|
10 | 12 | DataTable,
|
11 | 13 | DocString,
|
12 | 14 | ExamplesTable,
|
13 |
| - Feature, |
14 | 15 | GherkinDocument,
|
15 | 16 | Location,
|
16 | 17 | Row,
|
17 | 18 | Rule,
|
18 | 19 | Scenario,
|
19 |
| - Step, |
20 | 20 | Tag,
|
21 | 21 | get_gherkin_document,
|
22 | 22 | )
|
@@ -1092,3 +1092,81 @@ def test_parser():
|
1092 | 1092 | )
|
1093 | 1093 |
|
1094 | 1094 | 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