Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor parse test result logics #720

Merged
merged 9 commits into from
Jan 12, 2024
Merged

Conversation

Konboi
Copy link
Contributor

@Konboi Konboi commented Jan 11, 2024

Current parse logic is a little difficult to read and understand.
So, renamed and defined some methods for easy to read and understand

I didn't edit any test codes, so the result might not changed.

@Konboi Konboi force-pushed the update-scenario-hook branch 2 times, most recently from 7d24e90 to 6727695 Compare January 11, 2024 07:19
@Konboi Konboi force-pushed the update-scenario-hook branch from 6727695 to e31c077 Compare January 11, 2024 07:22
@Konboi
Copy link
Contributor Author

Konboi commented Jan 11, 2024

@Konboi Konboi requested a review from ono-max January 11, 2024 07:33
@Konboi
Copy link
Contributor Author

Konboi commented Jan 11, 2024

@ono-max Not rush, What do you think my change??

@@ -256,16 +257,16 @@ def parse_func(self, report_file: str) -> Generator[CaseEventType, None, None]:
{"type": "testcase", "name": test_case},
]

for step in test_case_info.steps:
for step in test_case_info.steps():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt we can defined this logic as a method

for d in data:
file_name = d.get("uri", "")
class_name = d.get("name", "")
# cucumber can define multiple Background steps
Copy link
Contributor

@ono-max ono-max Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? I don't think we can have multiple Background in this context.

You can only have one set of Background steps per Feature or Rule. If you need different Background steps for different scenarios, consider breaking up your set of scenarios into more Rules or more Features.

https://cucumber.io/docs/gherkin/reference/#background

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I have to write “multiple steps of a Background “

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I still don't understand what you said. In which case do we need to unify Background durations?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@ono-max ono-max Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus, I believe that there is no case that we need to unify Background durations. Can you please tell me if I am missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood what you wanted to say. I'll update it, please wait my fixing

super().__init__(statuses=statuses, duration_nano_sec=duration_nano_sec, error_message=stderr)


def _parse_hook_from_element(element: Dict[str, List]) -> TestCaseHookInfo:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be too magical, so it's up to you. However, we can write like this.

def _parse_hook_from_element(element: Dict[str, List]) -> TestCaseHookInfo:
    duration_nano_sec = 0
    statuses = []
    stderr = []
    def _parse_step_result(step: Dict[str, Dict]):
        result = step.get("result", None)
        if result:
            nonlocal duration_nano_sec
            duration_nano_sec += result.get("duration", 0)
            statuses.append(result.get("status"))
            if result.get("error_message", None):
                stderr.append(result["error_message"])
    for step in element.get("before", []):
        _parse_step_result(step)
    for step in element.get("after", []):
        _parse_step_result(step)

    return TestCaseHookInfo(
        duration_nano_sec=duration_nano_sec,
        statuses=statuses,
        stderr=stderr
    )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I apply it

@Konboi Konboi requested a review from ono-max January 12, 2024 05:18
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@ono-max ono-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent refactoring! Thanks!

@Konboi Konboi merged commit ab447e3 into scenario-hook Jan 12, 2024
15 checks passed
@Konboi Konboi deleted the update-scenario-hook branch January 12, 2024 05:32
@github-actions github-actions bot mentioned this pull request Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants