From 07ad49c203f489e6c8a96e5ef96261de4b155418 Mon Sep 17 00:00:00 2001 From: Daniel Biehl Date: Mon, 5 Feb 2024 01:50:18 +0200 Subject: [PATCH] fix(GherkinParser): fix lineno in hooks --- examples/simple/.gitignore | 4 +++- examples/simple/features/Bladerunner.feature | 15 +++++++++++++++ examples/simple/features/Minimal.feature | 7 +++---- examples/simple/features/steps/hooks.resource | 3 +-- src/GherkinParser/Library.py | 9 +++++++-- src/GherkinParser/gherkin_builder.py | 10 +--------- 6 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 examples/simple/features/Bladerunner.feature diff --git a/examples/simple/.gitignore b/examples/simple/.gitignore index 68bcbc9..df7a638 100644 --- a/examples/simple/.gitignore +++ b/examples/simple/.gitignore @@ -1 +1,3 @@ -results/ \ No newline at end of file +results/ +_* +.* \ No newline at end of file diff --git a/examples/simple/features/Bladerunner.feature b/examples/simple/features/Bladerunner.feature new file mode 100644 index 0000000..d300764 --- /dev/null +++ b/examples/simple/features/Bladerunner.feature @@ -0,0 +1,15 @@ +Feature: Android Detection System + As a security officer + I want to ensure that only humans gain access + + Scenario: A human attempts to gain access + Given An individual reaches the security checkpoint + And The individual is a human + When The detection system is activated + Then The individual should be granted access + + Scenario: An android attempts to gain access + Given An individual reaches the security checkpoint + And The individual is an android + When The detection system is activated + Then The individual should be denied access diff --git a/examples/simple/features/Minimal.feature b/examples/simple/features/Minimal.feature index 6d4734a..d78d826 100644 --- a/examples/simple/features/Minimal.feature +++ b/examples/simple/features/Minimal.feature @@ -9,8 +9,7 @@ Feature: Minimal Scenario: another one Given do something in the maximal way - @another - @slow + @another @slow Scenario: another one1 Given the minimalism @@ -26,5 +25,5 @@ Feature: Minimal Examples: | FirstName | MiddleName | LastName | - | Daniel | D | Biehl | - | Philip | K | Dick | + | Daniel | D | Biehl | + | Philip | K | Dick | diff --git a/examples/simple/features/steps/hooks.resource b/examples/simple/features/steps/hooks.resource index 24db31e..5f7e7cc 100644 --- a/examples/simple/features/steps/hooks.resource +++ b/examples/simple/features/steps/hooks.resource @@ -3,13 +3,12 @@ before_test [Arguments] ${context}= ${test}= [Tags] hook:before-test Log before test - Fail har har test + # Fail har har test before_suite [Arguments] ${context}= ${suite}= [Tags] hook:before-suite Log hook before suite - #Fail hahar suite before_keyword [Arguments] ${context}= ${suite}= diff --git a/src/GherkinParser/Library.py b/src/GherkinParser/Library.py index ead924c..1c89d0d 100644 --- a/src/GherkinParser/Library.py +++ b/src/GherkinParser/Library.py @@ -2,10 +2,9 @@ from typing import Any, Iterator, List, Tuple, Union from robot import result, running -from robot.api.deco import keyword, library +from robot.api.deco import library from robot.api.interfaces import ListenerV3 from robot.libraries.BuiltIn import EXECUTION_CONTEXTS, BuiltIn -from robot.model import Keyword @library( @@ -81,17 +80,21 @@ def _create_setup_and_teardown( kws.append("AND") kws.append(name) + lineno = data.lineno if isinstance(data, running.TestCase) else 1 + if kws: if data.setup.name: data.setup.config( name="BuiltIn.Run Keywords", args=(*kws, "AND", data.setup.name, *data.setup.args), + lineno = lineno ) else: data.setup.config( name="BuiltIn.Run Keywords", args=(*kws,), + lineno = lineno ) kws = [] @@ -106,12 +109,14 @@ def _create_setup_and_teardown( data.setup.config( name="BuiltIn.Run Keywords", args=(*kws, "AND", data.teardown.name, *data.teardown.args), + lineno = lineno ) else: data.teardown.config( name="BuiltIn.Run Keywords", args=(*kws,), + lineno = lineno ) def start_suite(self, data: running.TestSuite, result: result.TestSuite) -> None: diff --git a/src/GherkinParser/gherkin_builder.py b/src/GherkinParser/gherkin_builder.py index 26dc39b..3712622 100644 --- a/src/GherkinParser/gherkin_builder.py +++ b/src/GherkinParser/gherkin_builder.py @@ -23,10 +23,6 @@ SectionHeader, Tags, TestTags, - TestSetup, - TestTeardown, - SuiteSetup, - SuiteTeardown, ) from robot.utils.filereader import FileReader @@ -152,10 +148,6 @@ def build_gherkin_model(source: PathLike[str], content: Optional[str] = None) -> if feature_tags else [] ), - # SuiteSetup.from_params("GherkinParser.Library.BeforeSuite"), - # SuiteTeardown.from_params("GherkinParser.Library.AfterSuite"), - # TestSetup.from_params("GherkinParser.Library.BeforeTest"), - # TestTeardown.from_params("GherkinParser.Library.AfterTest"), ] file = File( @@ -172,7 +164,7 @@ def build_gherkin_model(source: PathLike[str], content: Optional[str] = None) -> source=str(path), ) - file.save(path.with_suffix(".robot").with_stem("_" + path.name)) + # file.save(path.with_suffix(".robot").with_stem("_" + path.name)) return file, gherkin_document["feature"]["name"] except (SystemExit, KeyboardInterrupt):