8000 impl: reworked implementation by arkjedrz · Pull Request #49 · qorix-group/testing_tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

impl: reworked implementation #49

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

arkjedrz
Copy link
Collaborator
  • Simplified usage.
  • Added hang and return_code to LogContainer.
  • Added parametrized timeouts.
  • Implemented automatic paths detection based on cargo metadata.
    • Expected binary name is parametrized, with rust_test_scenario as default value.
  • Added type hints.
  • Small README fixes.
  • More flexible add_log method.

Resolve #48

- Simplified usage.
- Added `hang` and `return_code` to `LogContainer`.
- Added parametrized timeouts.
- Implemented automatic paths detection based on `cargo metadata`.
  - Expected binary name is parametrized, with `rust_test_scenario` as
    default value.
- Added type hints.
- Small README fixes.
- More flexible `add_log` method.
@arkjedrz arkjedrz self-assigned this Jul 10, 2025
p = Popen(command, stdout=PIPE, stdin=PIPE, stderr=PIPE, text=True)
try:
outs, errs = p.communicate(test_config_json, EXECUTE_TIMEOUT_S)
stdout, _ = p.communicate(test_config_str, execution_timeout)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to see stderr data in case of some error, e.g. panics are written there

messages.sort(key=lambda m: m["timestamp"])

return messages
# Convert to list of ResultEntry.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Leave only comments for not obvious steps. I would go for more functions, less comments.


def execute(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fragment to more, shorter functions



def build_test_scenarios(
rust_scenarios_bin_name: str | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Set default values in the arguments directly, no need for None handling

True if execution hanged.
"""
self._logs = entries or []
self._return_code = return_code
Copy link
Collaborator
@igorostrowskiq igorostrowskiq Jul 10, 2025

Choose a reason for hiding this comment

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

Not sure if it is a good place to store other data than logs. This class often goes thru transformation LogContainer -> List[ResultEntry] -> LogContainer and this data will be lost. IMO return code should be delivered in a separate fixture if test wants to explicitly check that. Hang indicator has no value to the test body itself as it will fail in the tt.unfiltered_test_results.

hang : bool | None
True if execution hanged.
"""
self._logs = entries or []
Copy link
Collaborator

Choose a reason for hiding this comment

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

Its not pythonic - better define an empty list as default in arguments

def __init__(self):
self.logs = []
def __init__(
self, entries: list[ResultEntry] | None = None, return_code: int | None = None, hang: bool | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of all those | None = None you can

from typing import Optional
return_code: Optional[int] 


def group_by(self, attribute: str) -> Dict[str, "LogContainer"]:
def group_by(self, attribute: str) -> dict[str, "LogContainer"]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is incorrect, it should be Dict from typing for type annotations

raise FileNotFoundError(
f"Cargo.toml not found at {path_to_manifest}. Please provide a valid path to the rust test scenarios."
# Set default timeout.
metadata_timeout = cargo_metadata_timeout_s or 10.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

define default directly in the function definition

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.

Recognize rust scenarios exit codes
3 participants
0