Skip to content

Commit

Permalink
fix(GherkinParser): fix lineno in hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
d-biehl committed Feb 4, 2024
1 parent cba43de commit 07ad49c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
4 changes: 3 additions & 1 deletion examples/simple/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
results/
results/
_*
.*
15 changes: 15 additions & 0 deletions examples/simple/features/Bladerunner.feature
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions examples/simple/features/Minimal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,5 +25,5 @@ Feature: Minimal

Examples:
| FirstName | MiddleName | LastName |
| Daniel | D | Biehl |
| Philip | K | Dick |
| Daniel | D | Biehl |
| Philip | K | Dick |
3 changes: 1 addition & 2 deletions examples/simple/features/steps/hooks.resource
Original file line number Diff line number Diff line change
Expand Up @@ -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}=
Expand Down
9 changes: 7 additions & 2 deletions src/GherkinParser/Library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = []
Expand All @@ -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:
Expand Down
10 changes: 1 addition & 9 deletions src/GherkinParser/gherkin_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
SectionHeader,
Tags,
TestTags,
TestSetup,
TestTeardown,
SuiteSetup,
SuiteTeardown,
)
from robot.utils.filereader import FileReader

Expand Down Expand Up @@ -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(
Expand All @@ -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):
Expand Down

0 comments on commit 07ad49c

Please sign in to comment.