Skip to content

Commit d5fef73

Browse files
committed
add source library test
1 parent 64ae7e2 commit d5fef73

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright (c) 2026 Scipp contributors (https://github.com/scipp)
3+
4+
import hashlib
5+
from pathlib import Path
6+
7+
import pooch
8+
9+
from tof.facilities import _BASE_URLS, _source_library
10+
11+
12+
def sha256(p: Path) -> str:
13+
h = hashlib.sha256()
14+
with p.open("rb") as f:
15+
for chunk in iter(lambda: f.read(1024 * 1024), b""):
16+
h.update(chunk)
17+
return h.hexdigest()
18+
19+
20+
def test_source_library_files_identical_on_public_and_github(tmp_path: Path) -> None:
21+
registry = {f["path"]: f["hash"] for f in _source_library.values()}
22+
23+
public = pooch.create(
24+
path=tmp_path / "cache_public", base_url=_BASE_URLS[0], registry=registry
25+
)
26+
27+
gh = pooch.create(
28+
path=tmp_path / "cache_github", base_url=_BASE_URLS[1], registry=registry
29+
)
30+
31+
for name, entry in _source_library.items():
32+
rel = entry["path"]
33+
34+
p_gh = Path(gh.fetch(rel))
35+
p_public = Path(public.fetch(rel))
36+
37+
# registry already verifies md5, but we compare content across hosts:
38+
assert sha256(p_gh) == sha256(p_public), f"Mismatch for {name} ({rel})"

0 commit comments

Comments
 (0)