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