Skip to content

Commit f65f17c

Browse files
authored
Update internal tests (#202)
* mock `known_good.json` input * centralize fixtures
1 parent c11b14f commit f65f17c

4 files changed

Lines changed: 257 additions & 147 deletions

File tree

scripts/tooling/tests/conftest.py

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
"""Shared pytest fixtures and test utilities."""
14+
15+
import json
16+
from pathlib import Path
17+
18+
import pytest
19+
from lib.known_good import KnownGood, Module, load_known_good
20+
21+
# ---------------------------------------------------------------------------
22+
# Constants
23+
# ---------------------------------------------------------------------------
24+
25+
MINIMAL_JSON = {
26+
"modules": {
27+
"target_sw": {
28+
"score_baselibs": {
29+
"repo": "https://github.com/eclipse-score/baselibs.git",
30+
"hash": "abc123",
31+
}
32+
}
33+
},
34+
"timestamp": "2026-01-01T00:00:00+00:00Z",
35+
}
36+
37+
FULL_JSON = {
38+
"modules": {
39+
"target_sw": {
40+
"score_baselibs": {
41+
"repo": "https://github.com/eclipse-score/baselibs.git",
42+
"hash": "158fe6a7b791c58f6eac5f7e4662b8db0cf9ac6e",
43+
"bazel_patches": ["//patches/baselibs:003-acl-fixes-for-aarch64.patch"],
44+
"metadata": {
45+
"extra_test_config": [
46+
"//score/json:base_library=nlohmann",
47+
"//score/memory/shared/flags:use_typedshmd=False",
48+
],
49+
"exclude_test_targets": [
50+
"//score/language/safecpp/aborts_upon_exception:abortsuponexception_toolchain_test",
51+
"//score/containers:dynamic_array_test",
52+
"//score/mw/log/configuration:*",
53+
"//score/json/examples:*",
54+
],
55+
"langs": ["cpp"],
56+
},
57+
},
58+
"score_persistency": {
59+
"repo": "https://github.com/eclipse-score/persistency.git",
60+
"hash": "438bf9b5c447fd41ad43b321679dd3d1b3a6c737",
61+
"metadata": {"code_root_path": "//src/..."},
62+
},
63+
},
64+
"tooling": {
65+
"score_crates": {
66+
"repo": "https://github.com/eclipse-score/score-crates.git",
67+
"hash": "90539da0fd3e7e23e01f2b4de1679f7dfadd3b6b",
68+
},
69+
"score_itf": {
70+
"repo": "https://github.com/eclipse-score/itf.git",
71+
"hash": "44c75debab696a9c967455110a2c32f201159cdd",
72+
},
73+
},
74+
},
75+
"timestamp": "2026-01-01T00:00:00+00:00Z",
76+
}
77+
78+
KNOWN_GOOD_JSON = Path(__file__).parents[3] / "known_good.json"
79+
80+
81+
# ---------------------------------------------------------------------------
82+
# Helper functions
83+
# ---------------------------------------------------------------------------
84+
85+
86+
def make_known_good(**overrides) -> KnownGood:
87+
"""Build a minimal KnownGood with one module.
88+
89+
Args:
90+
**overrides: Additional fields to override in the module data.
91+
92+
Returns:
93+
KnownGood instance with a single module in target_sw group.
94+
"""
95+
module_data = {
96+
"repo": "https://github.com/eclipse-score/baselibs.git",
97+
"hash": "abc123def456abc123def456abc123def456abc123",
98+
**overrides,
99+
}
100+
module = Module.from_dict("score_baselibs", module_data)
101+
return KnownGood(
102+
modules={"target_sw": {"score_baselibs": module}},
103+
timestamp="2026-01-01T00:00:00+00:00Z",
104+
)
105+
106+
107+
# ---------------------------------------------------------------------------
108+
# Fixtures - File-based
109+
# ---------------------------------------------------------------------------
110+
111+
112+
@pytest.fixture
113+
def minimal_json_file(tmp_path: Path) -> Path:
114+
"""Create a temporary JSON file with minimal known good data."""
115+
p = tmp_path / "known_good.json"
116+
p.write_text(json.dumps(MINIMAL_JSON))
117+
return p
118+
119+
120+
@pytest.fixture
121+
def full_json_file(tmp_path: Path) -> Path:
122+
"""Create a temporary JSON file with full known good data."""
123+
p = tmp_path / "known_good.json"
124+
p.write_text(json.dumps(FULL_JSON))
125+
return p
126+
127+
128+
# ---------------------------------------------------------------------------
129+
# Fixtures - KnownGood objects
130+
# ---------------------------------------------------------------------------
131+
132+
133+
@pytest.fixture
134+
def minimal_known_good() -> KnownGood:
135+
"""Create a minimal KnownGood instance."""
136+
return make_known_good()
137+
138+
139+
@pytest.fixture
140+
def multi_group_known_good() -> KnownGood:
141+
"""Create a KnownGood instance with multiple groups."""
142+
m1 = Module.from_dict(
143+
"score_baselibs",
144+
{
145+
"repo": "https://github.com/eclipse-score/baselibs.git",
146+
"hash": "aaa",
147+
},
148+
)
149+
m2 = Module.from_dict(
150+
"score_crates",
151+
{
152+
"repo": "https://github.com/eclipse-score/score-crates.git",
153+
"hash": "bbb",
154+
},
155+
)
156+
return KnownGood(
157+
modules={
158+
"target_sw": {"score_baselibs": m1},
159+
"tooling": {"score_crates": m2},
160+
},
161+
timestamp="2026-02-01T00:00:00+00:00Z",
162+
)
163+
164+
165+
@pytest.fixture
166+
def real_known_good() -> KnownGood:
167+
"""Load the actual known_good.json from the repository root."""
168+
return load_known_good(KNOWN_GOOD_JSON)
169+
170+
171+
# ---------------------------------------------------------------------------
172+
# Fixtures - Test data for check_approvals
173+
# ---------------------------------------------------------------------------
174+
175+
176+
@pytest.fixture
177+
def modules_maintainers():
178+
"""Sample modules and maintainers for testing."""
179+
return {
180+
"module_a": [
181+
{
182+
"name": "Alice Developer",
183+
"email": "alice@example.com",
184+
"github": "alice",
185+
"github_user_id": 100,
186+
},
187+
{
188+
"name": "Bob Developer",
189+
"email": "bob@example.com",
190+
"github": "bob",
191+
"github_user_id": 101,
192+
},
193+
],
194+
"module_b": [
195+
{
196+
"name": "Charlie Developer",
197+
"email": "charlie@example.com",
198+
"github": "charlie",
199+
"github_user_id": 102,
200+
}
201+
],
202+
"module_c": [
203+
{
204+
"name": "Diana Developer",
205+
"email": "diana@example.com",
206+
"github": "diana",
207+
"github_user_id": 103,
208+
},
209+
{
210+
"name": "Eve Developer",
211+
"email": "eve@example.com",
212+
"github": "eve",
213+
"github_user_id": 104,
214+
},
215+
],
216+
}

scripts/tooling/tests/test_check_approvals.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,6 @@
1818
from scripts.tooling.cli.release.check_approvals import check_pr_reviews
1919

2020

21-
@pytest.fixture
22-
def modules_maintainers():
23-
"""Sample modules and maintainers for testing."""
24-
return {
25-
"module_a": [
26-
{
27-
"name": "Alice Developer",
28-
"email": "alice@example.com",
29-
"github": "alice",
30-
"github_user_id": 100,
31-
},
32-
{
33-
"name": "Bob Developer",
34-
"email": "bob@example.com",
35-
"github": "bob",
36-
"github_user_id": 101,
37-
},
38-
],
39-
"module_b": [
40-
{
41-
"name": "Charlie Developer",
42-
"email": "charlie@example.com",
43-
"github": "charlie",
44-
"github_user_id": 102,
45-
}
46-
],
47-
"module_c": [
48-
{
49-
"name": "Diana Developer",
50-
"email": "diana@example.com",
51-
"github": "diana",
52-
"github_user_id": 103,
53-
},
54-
{
55-
"name": "Eve Developer",
56-
"email": "eve@example.com",
57-
"github": "eve",
58-
"github_user_id": 104,
59-
},
60-
],
61-
}
62-
63-
6421
def _create_mock_review(user_id: int, username: str, state: str, submitted_at: datetime) -> Mock:
6522
"""Create a mock GitHub review object.
6623

scripts/tooling/tests/test_known_good.py

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,11 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
import json
14-
import pytest
1514
from pathlib import Path
1615

16+
import pytest
1717
from lib.known_good import KnownGood, Metadata, Module, load_known_good
1818

19-
20-
KNOWN_GOOD_JSON = Path(__file__).parents[3] / "known_good.json"
21-
22-
MINIMAL_JSON = {
23-
"modules": {
24-
"target_sw": {
25-
"score_baselibs": {
26-
"repo": "https://github.com/eclipse-score/baselibs.git",
27-
"hash": "abc123",
28-
}
29-
}
30-
},
31-
"timestamp": "2026-01-01T00:00:00+00:00Z",
32-
}
33-
34-
35-
# ---------------------------------------------------------------------------
36-
# Fixtures
37-
# ---------------------------------------------------------------------------
38-
39-
40-
@pytest.fixture
41-
def minimal_json_file(tmp_path: Path) -> Path:
42-
p = tmp_path / "known_good.json"
43-
p.write_text(json.dumps(MINIMAL_JSON))
44-
return p
45-
46-
47-
@pytest.fixture
48-
def full_json_file(tmp_path: Path) -> Path:
49-
"""Copy the real known_good.json into a temp location."""
50-
content = KNOWN_GOOD_JSON.read_text(encoding="utf-8")
51-
p = tmp_path / "known_good.json"
52-
p.write_text(content)
53-
return p
54-
55-
5619
# ---------------------------------------------------------------------------
5720
# load_known_good – happy path
5821
# ---------------------------------------------------------------------------
@@ -100,12 +63,11 @@ def test_module_field_values(self, minimal_json_file: Path):
10063

10164

10265
# ---------------------------------------------------------------------------
103-
# load_known_good – real file
66+
# load_known_good – full file
10467
# ---------------------------------------------------------------------------
10568

10669

107-
@pytest.mark.skipif(not KNOWN_GOOD_JSON.exists(), reason="known_good.json not found")
108-
class TestLoadKnownGoodRealFile:
70+
class TestLoadKnownGoodFullFile:
10971
def test_loads_without_error(self, full_json_file: Path):
11072
load_known_good(full_json_file)
11173

@@ -136,6 +98,42 @@ def test_owner_repo_property(self, full_json_file: Path):
13698
m = load_known_good(full_json_file).modules["target_sw"]["score_baselibs"]
13799
assert m.owner_repo == "eclipse-score/baselibs"
138100

101+
def test_metadata_extra_test_config(self, full_json_file: Path):
102+
known_good = load_known_good(full_json_file)
103+
baselibs = known_good.modules["target_sw"]["score_baselibs"]
104+
persistency = known_good.modules["target_sw"]["score_persistency"]
105+
assert baselibs.metadata.extra_test_config == [
106+
"//score/json:base_library=nlohmann",
107+
"//score/memory/shared/flags:use_typedshmd=False",
108+
]
109+
assert persistency.metadata.extra_test_config == []
110+
111+
def test_metadata_exclude_test_targets(self, full_json_file: Path):
112+
known_good = load_known_good(full_json_file)
113+
baselibs = known_good.modules["target_sw"]["score_baselibs"]
114+
persistency = known_good.modules["target_sw"]["score_persistency"]
115+
assert baselibs.metadata.exclude_test_targets == [
116+
"//score/language/safecpp/aborts_upon_exception:abortsuponexception_toolchain_test",
117+
"//score/containers:dynamic_array_test",
118+
"//score/mw/log/configuration:*",
119+
"//score/json/examples:*",
120+
]
121+
assert persistency.metadata.exclude_test_targets == []
122+
123+
def test_metadata_code_root_path(self, full_json_file: Path):
124+
known_good = load_known_good(full_json_file)
125+
baselibs = known_good.modules["target_sw"]["score_baselibs"]
126+
persistency = known_good.modules["target_sw"]["score_persistency"]
127+
assert baselibs.metadata.code_root_path == "//score/..."
128+
assert persistency.metadata.code_root_path == "//src/..."
129+
130+
def test_metadata_langs(self, full_json_file: Path):
131+
known_good = load_known_good(full_json_file)
132+
baselibs = known_good.modules["target_sw"]["score_baselibs"]
133+
persistency = known_good.modules["target_sw"]["score_persistency"]
134+
assert baselibs.metadata.langs == ["cpp"]
135+
assert persistency.metadata.langs == ["cpp", "rust"]
136+
139137

140138
# ---------------------------------------------------------------------------
141139
# Metadata defaults

0 commit comments

Comments
 (0)