Parse the feature file and return a Feature object with its backgrounds, rules, and scenarios.
(self)
| 479 | return get_gherkin_document(self.abs_filename, self.encoding) |
| 480 | |
| 481 | def parse(self) -> Feature: |
| 482 | """Parse the feature file and return a Feature object with its backgrounds, rules, and scenarios.""" |
| 483 | gherkin_doc: GherkinDocument = self._parse_feature_file() |
| 484 | feature_data: GherkinFeature = gherkin_doc.feature |
| 485 | feature = Feature( |
| 486 | scenarios=OrderedDict(), |
| 487 | keyword=feature_data.keyword, |
| 488 | filename=self.abs_filename, |
| 489 | rel_filename=self.rel_filename, |
| 490 | name=feature_data.name, |
| 491 | tags=get_tag_names(feature_data.tags), |
| 492 | background=None, |
| 493 | line_number=feature_data.location.line, |
| 494 | description=textwrap.dedent(feature_data.description), |
| 495 | language=feature_data.language, |
| 496 | ) |
| 497 | |
| 498 | for child in feature_data.children: |
| 499 | if child.background: |
| 500 | feature.background = self.parse_background(child.background) |
| 501 | elif child.rule: |
| 502 | self._parse_and_add_rule(child.rule, feature) |
| 503 | elif child.scenario: |
| 504 | self._parse_and_add_scenario(child.scenario, feature) |
| 505 | |
| 506 | return feature |
| 507 | |
| 508 | def _parse_and_add_rule(self, rule_data: GherkinRule, feature: Feature) -> None: |
| 509 | """Parse a rule, including its background and scenarios, and add to the feature.""" |
no test coverage detected