Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 0 additions & 102 deletions src/rust/rust_kvs/tests/cit_supported_datatypes.rs

This file was deleted.

69 changes: 69 additions & 0 deletions tests/python_test_cases/tests/common_scenario.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from pathlib import Path
import pytest
from testing_utils import Scenario, LogContainer


class CommonScenario(Scenario):
@pytest.fixture(scope="class")
def logs_target(self, target_path: Path, logs: LogContainer) -> LogContainer:
"""
Logs with messages generated strictly by the tested code.

Parameters
----------
target_path : Path
Path to test scenario executable.
logs : LogContainer
Unfiltered logs.
"""
return logs.get_logs_by_field(field="target", pattern=f"{target_path.name}.*")

@pytest.fixture(scope="class")
def logs_info_level(self, logs_target: LogContainer) -> LogContainer:
"""
Logs with messages with INFO level.

Parameters
----------
logs_target : LogContainer
Logs with messages generated strictly by the tested code.
"""
return logs_target.get_logs_by_field(field="level", value="INFO")

@pytest.fixture(autouse=True)
def print_to_report(
self,
request: pytest.FixtureRequest,
logs: LogContainer,
logs_target: LogContainer,
) -> None:
"""
Print traces to stdout.

Allowed "--traces" values:
- "none" - show no traces.
- "target" - show traces generated by test code.
- "all" - show all traces.

Parameters
----------
request : FixtureRequest
Test request built-in fixture.
logs : LogContainer
Test scenario execution logs.
logs_target : LogContainer
Logs with messages generated strictly by the tested code.
"""
traces_param = request.config.getoption("--traces")
match traces_param:
case "all":
traces = logs
case "target":
traces = logs_target
case "none":
traces = LogContainer()
case _:
raise RuntimeError(f'Invalid "--traces" value: {traces_param}')

for trace in traces:
print(trace)
58 changes: 2 additions & 56 deletions tests/python_test_cases/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
Smoke test for Rust-C++ tests.
"""

from pathlib import Path
from typing import Any

import pytest
from testing_utils import (
BazelTools,
BuildTools,
LogContainer,
Scenario,
ScenarioResult,
)
from common_scenario import CommonScenario


class TestBasic(Scenario):
class TestBasic(CommonScenario):
@pytest.fixture(scope="class")
def scenario_name(self, *_, **__) -> str:
return "basic.basic"
Expand All @@ -24,58 +22,6 @@ def scenario_name(self, *_, **__) -> str:
def test_config(self, *_, **__) -> dict[str, Any]:
return {"kvs_parameters": {"instance_id": 2, "flush_on_exit": False}}

@pytest.fixture(scope="class")
def logs_target(self, target_path: Path, logs: LogContainer) -> LogContainer:
"""
Logs with messages generated strictly by the tested code.

Parameters
----------
target_path : Path
Path to test scenario executable.
logs : LogContainer
Unfiltered logs.
"""
return logs.get_logs_by_field(field="target", pattern=f"{target_path.name}.*")

@pytest.fixture(autouse=True)
def print_to_report(
self,
request: pytest.FixtureRequest,
logs: LogContainer,
logs_target: LogContainer,
) -> None:
"""
Print traces to stdout.

Allowed "--traces" values:
- "none" - show no traces.
- "target" - show traces generated by test code.
- "all" - show all traces.

Parameters
----------
request : FixtureRequest
Test request built-in fixture.
logs : LogContainer
Test scenario execution logs.
logs_target : LogContainer
Logs with messages generated strictly by the tested code.
"""
traces_param = request.config.getoption("--traces")
match traces_param:
case "all":
traces = logs
case "target":
traces = logs_target
case "none":
traces = LogContainer()
case _:
raise RuntimeError(f'Invalid "--traces" value: {traces_param}')

for trace in traces:
print(trace)

def test_returncode_ok(self, results: ScenarioResult):
assert results.return_code == 0

Expand Down
Loading