Skip to content

Commit adf93fe

Browse files
committed
testing: improve test env selection
- Add common build tools method to base class. - Add `Clone` to `KvsParameters`. - Add common return codes. - Bump testing-utils version.
1 parent f0cd9dc commit adf93fe

File tree

5 files changed

+34
-44
lines changed

5 files changed

+34
-44
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
testing-utils @ git+https://github.com/qorix-group/testing_tools.git@v0.2.0
1+
testing-utils @ git+https://github.com/qorix-group/testing_tools.git@v0.2.2

tests/python_test_cases/tests/common_scenario.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
from pathlib import Path
22
import pytest
3-
from testing_utils import Scenario, LogContainer
3+
from testing_utils import Scenario, LogContainer, BuildTools, BazelTools
4+
5+
6+
class ResultCode:
7+
"""
8+
Test scenario exit codes.
9+
"""
10+
11+
SUCCESS = 0
12+
PANIC = 101
13+
SIGKILL = -9
14+
SIGABRT = -6
415

516

617
class CommonScenario(Scenario):
18+
@pytest.fixture(scope="class")
19+
def build_tools(self, version: str) -> BuildTools:
20+
assert version in ("cpp", "rust")
21+
return BazelTools(option_prefix=version)
22+
723
@pytest.fixture(scope="class")
824
def logs_target(self, target_path: Path, logs: LogContainer) -> LogContainer:
925
"""
@@ -16,7 +32,7 @@ def logs_target(self, target_path: Path, logs: LogContainer) -> LogContainer:
1632
logs : LogContainer
1733
Unfiltered logs.
1834
"""
19-
return logs.get_logs_by_field(field="target", pattern=f"{target_path.name}.*")
35+
return logs.get_logs(field="target", pattern=f"{target_path.name}.*")
2036

2137
@pytest.fixture(scope="class")
2238
def logs_info_level(self, logs_target: LogContainer) -> LogContainer:
@@ -28,7 +44,7 @@ def logs_info_level(self, logs_target: LogContainer) -> LogContainer:
2844
logs_target : LogContainer
2945
Logs with messages generated strictly by the tested code.
3046
"""
31-
return logs_target.get_logs_by_field(field="level", value="INFO")
47+
return logs_target.get_logs(field="level", value="INFO")
3248

3349
@pytest.fixture(autouse=True)
3450
def print_to_report(

tests/python_test_cases/tests/test_basic.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44

55
from typing import Any
66
import pytest
7-
from testing_utils import (
8-
BazelTools,
9-
BuildTools,
10-
LogContainer,
11-
ScenarioResult,
12-
)
13-
from common_scenario import CommonScenario
7+
from testing_utils import LogContainer, ScenarioResult
8+
from common_scenario import CommonScenario, ResultCode
149

1510

11+
@pytest.mark.parametrize("version", ["cpp", "rust"], scope="class")
1612
class TestBasic(CommonScenario):
1713
@pytest.fixture(scope="class")
1814
def scenario_name(self, *_, **__) -> str:
@@ -23,20 +19,8 @@ def test_config(self, *_, **__) -> dict[str, Any]:
2319
return {"kvs_parameters": {"instance_id": 2, "flush_on_exit": False}}
2420

2521
def test_returncode_ok(self, results: ScenarioResult):
26-
assert results.return_code == 0
22+
assert results.return_code == ResultCode.SUCCESS
2723

2824
def test_trace_ok(self, logs_target: LogContainer):
29-
lc = logs_target.get_logs_by_field("example_key", value="example_value")
25+
lc = logs_target.get_logs("example_key", value="example_value")
3026
assert len(lc) == 1
31-
32-
33-
class TestBasicCpp(TestBasic):
34-
@pytest.fixture(scope="class")
35-
def build_tools(self, *_, **__) -> BuildTools:
36-
return BazelTools(option_prefix="cpp")
37-
38-
39-
class TestBasicRust(TestBasic):
40-
@pytest.fixture(scope="class")
41-
def build_tools(self, *_, **__) -> BuildTools:
42-
return BazelTools(option_prefix="rust")

tests/python_test_cases/tests/test_cit_supported_datatypes.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from typing import Any
44

55
import pytest
6-
from common_scenario import CommonScenario
7-
from testing_utils import BazelTools, BuildTools, LogContainer, ScenarioResult
6+
from common_scenario import CommonScenario, ResultCode
7+
from testing_utils import ScenarioResult, LogContainer
8+
9+
pytestmark = pytest.mark.parametrize("version", ["rust"], scope="class")
810

911

1012
@pytest.mark.PartiallyVerifies(
@@ -25,15 +27,10 @@ def scenario_name(self) -> str:
2527
def test_config(self) -> dict[str, Any]:
2628
return {"kvs_parameters": {"instance_id": 1, "flush_on_exit": False}}
2729

28-
@pytest.fixture(scope="class", params=["rust"])
29-
def build_tools(self, request: pytest.FixtureRequest) -> BuildTools:
30-
version = request.param
31-
return BazelTools(option_prefix=version)
32-
3330
def test_ok(self, results: ScenarioResult, logs_info_level: LogContainer) -> None:
34-
assert results.return_code == 0
31+
assert results.return_code == ResultCode.SUCCESS
3532

36-
logs = logs_info_level.get_logs_by_field(field="key", pattern=".*").get_logs()
33+
logs = logs_info_level.get_logs(field="key")
3734
act_keys = set(map(lambda x: x.key, logs))
3835
exp_keys = {"example", "emoji ✅❗😀", "greek ημα"}
3936

@@ -70,18 +67,11 @@ def scenario_name(self) -> str:
7067
def test_config(self) -> dict[str, Any]:
7168
return {"kvs_parameters": {"instance_id": 1, "flush_on_exit": False}}
7269

73-
@pytest.fixture(scope="class", params=["rust"])
74-
def build_tools(self, request: pytest.FixtureRequest) -> BuildTools:
75-
version = request.param
76-
return BazelTools(option_prefix=version)
77-
7870
def test_ok(self, results: ScenarioResult, logs_info_level: LogContainer) -> None:
79-
assert results.return_code == 0
71+
assert results.return_code == ResultCode.SUCCESS
8072

8173
# Get log containing type and value.
82-
logs = logs_info_level.get_logs_by_field(
83-
field="key", value=self.exp_key()
84-
).get_logs()
74+
logs = logs_info_level.get_logs(field="key", value=self.exp_key())
8575
assert len(logs) == 1
8676
log = logs[0]
8777

tests/rust_test_scenarios/src/helpers/kvs_parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde_json::Value;
66
use std::path::PathBuf;
77

88
/// KVS parameters in serde-compatible format.
9-
#[derive(Deserialize, Debug)]
9+
#[derive(Deserialize, Debug, Clone)]
1010
pub struct KvsParameters {
1111
#[serde(deserialize_with = "deserialize_instance_id")]
1212
pub instance_id: InstanceId,

0 commit comments

Comments
 (0)