Skip to content

Commit

Permalink
Merge pull request #43 from nicke46/nicke/params
Browse files Browse the repository at this point in the history
move _get_parameters to also utilize active_outline
  • Loading branch information
HardNorth authored Oct 24, 2023
2 parents 97d1945 + 0fa4699 commit ce1bdea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
16 changes: 5 additions & 11 deletions behave_reportportal/behave_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def start_scenario(self, context, scenario, **kwargs):
parent_item_id=self._feature_id,
code_ref=self._code_ref(scenario),
attributes=self._attributes(scenario),
parameters=self._get_parameters(scenario),
parameters=self._get_parameters(context),
description=self._item_description(context, scenario),
test_case_id=self._test_case_id(scenario),
**kwargs,
Expand Down Expand Up @@ -413,16 +413,10 @@ def _item_description(context, item):
return desc

@staticmethod
def _get_parameters(scenario):
# noinspection PyProtectedMember
return (
scenario._row
and {
r[0]: r[1]
for r in zip(scenario._row.headings, scenario._row.cells)
}
or None
)
def _get_parameters(context):
if context.active_outline:
return {r[0]: r[1] for r in zip(context.active_outline.headings, context.active_outline.cells)}
return None

@staticmethod
def _code_ref(item):
Expand Down
2 changes: 1 addition & 1 deletion behave_reportportal/behave_agent.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ class BehaveAgent:
def _code_ref(item: BasicStatement) -> Optional[str]: ...

@staticmethod
def _get_parameters(scenario: Scenario) -> Optional[
def _get_parameters(context: Context) -> Optional[
Dict[str, Any]]: ...
19 changes: 9 additions & 10 deletions tests/units/test_rp_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,19 @@ def test_code_ref():


def test_get_parameters():
mock_item = mock.Mock()
mock_item._row = None
mock_context = mock.Mock()
mock_context.active_outline = None
expect(
BehaveAgent._get_parameters(mock_item) is None,
BehaveAgent._get_parameters(mock_context) is None,
"parameters is not None",
)
mock_row = mock.Mock()
mock_row.headings = ["A", "B"]
mock_row.cells = [1, 2]
mock_item._row = mock_row
mock_context.active_outline = mock.Mock()
mock_context.active_outline.headings = ["A", "B"]
mock_context.active_outline.cells = [1, 2]
expect(
BehaveAgent._get_parameters(mock_item) == {"A": 1, "B": 2},
BehaveAgent._get_parameters(mock_context) == {"A": 1, "B": 2},
f"parameters are incorrect:\n"
f"Actual: {BehaveAgent._get_parameters(mock_item)}\n"
f"Actual: {BehaveAgent._get_parameters(mock_context)}\n"
f"Expected: {{'A': 1, 'B': 2}}",
)
assert_expectations()
Expand Down Expand Up @@ -467,7 +466,7 @@ def verify_start_scenario(mock_scenario, config):
parent_item_id="feature_id",
description=BehaveAgent._item_description(mock_context, mock_scenario),
code_ref=BehaveAgent._code_ref(mock_scenario),
parameters=BehaveAgent._get_parameters(mock_scenario),
parameters=BehaveAgent._get_parameters(mock_context),
attributes=ba._attributes(mock_scenario),
test_case_id=ba._test_case_id(mock_scenario),
some_key="some_value",
Expand Down

0 comments on commit ce1bdea

Please sign in to comment.