Skip to content

Commit 312283f

Browse files
committed
perf: Avoid downloading needs.json
This costs ~700ms x 15+ tests. Also, network access is not a good thing for tests.
1 parent 84b3bea commit 312283f

4 files changed

Lines changed: 44 additions & 7 deletions

File tree

src/extensions/score_metamodel/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ score_pytest(
8686
name = "file_based_tests_attributes",
8787
size = "medium",
8888
srcs = ["tests/test_rules_file_based.py"],
89-
data = glob(["tests/rst/attributes/*.rst"]) + ["tests/rst/conf.py"],
89+
data = glob(["tests/rst/attributes/*.rst"]) + ["tests/rst/conf.py", "tests/rst/attributes/needs.json"],
9090
pytest_config = "//:pyproject.toml",
9191
deps = [":score_metamodel"],
9292
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"current_version": "1.0",
3+
"project": "test",
4+
"project_url": "https://eclipse-score.github.io/process_description/main/",
5+
"versions": {
6+
"1.0": {
7+
"needs": {
8+
"doc_getstrt__req__process": {
9+
"docname": "getting_started",
10+
"id": "doc_getstrt__req__process",
11+
"lineno": 1,
12+
"status": "valid",
13+
"title": "Process requirement (stub for tests)",
14+
"type": "doc_req",
15+
"type_name": "doc_req"
16+
},
17+
"gd_guidl__req__engineering": {
18+
"docname": "guidelines",
19+
"id": "gd_guidl__req__engineering",
20+
"lineno": 1,
21+
"status": "valid",
22+
"title": "Engineering guideline requirement (stub for tests)",
23+
"type": "gd_req",
24+
"type_name": "gd_req"
25+
}
26+
}
27+
}
28+
}
29+
}

src/extensions/score_metamodel/tests/rst/conf.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
"score_metamodel",
2222
]
2323

24-
needs_external_needs = [
25-
{
26-
"base_url": "https://eclipse-score.github.io/process_description/main/",
27-
"json_url": "https://eclipse-score.github.io/process_description/main/needs.json",
28-
}
29-
]
3024
# We add these suppress_warnings here to ease the load of the warnings
3125
# In the future we might want to check if ANY warnings comes in the document
3226
# And then ensure that we error, as this could also be parsing errors etc.

src/extensions/score_metamodel/tests/test_rules_file_based.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,20 @@ def test_rst_files(
287287

288288
# Build the documentation with the enabled checks
289289
app.config.score_metamodel_checks = rst_data.enabled_checks
290+
291+
# Replace any network json_url with a local json_path to avoid network I/O in tests
292+
local_needs = RST_DIR / Path(rst_file).parent / "needs.json"
293+
if local_needs.exists():
294+
shutil.copy(local_needs, app.srcdir)
295+
app.config.needs_external_needs = [
296+
{k: v for k, v in ext.items() if k != "json_url"} | {"json_path": "needs.json"}
297+
if "json_url" in ext
298+
else ext
299+
for ext in (app.config.needs_external_needs or [])
300+
]
301+
else:
302+
app.config.needs_external_needs = []
303+
290304
app.build()
291305

292306
# Collect the warnings

0 commit comments

Comments
 (0)