mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-04-23 04:26:36 +00:00
test(e2e): add SHA256-verified dataset downloader + EuRoC registry entry
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
"""Dataset downloader — URL registry + SHA256 verification."""
|
||||
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from gps_denied.testing.download import (
|
||||
DATASET_REGISTRY,
|
||||
DatasetSpec,
|
||||
verify_sha256,
|
||||
download_dataset,
|
||||
)
|
||||
|
||||
|
||||
def test_registry_has_euroc():
|
||||
assert "euroc_mh01" in DATASET_REGISTRY
|
||||
spec = DATASET_REGISTRY["euroc_mh01"]
|
||||
assert isinstance(spec, DatasetSpec)
|
||||
assert spec.url.startswith("http")
|
||||
assert len(spec.sha256) == 64
|
||||
|
||||
|
||||
def test_verify_sha256_matches(tmp_path: Path):
|
||||
data = b"hello world"
|
||||
f = tmp_path / "x.bin"
|
||||
f.write_bytes(data)
|
||||
expected = hashlib.sha256(data).hexdigest()
|
||||
assert verify_sha256(f, expected) is True
|
||||
|
||||
|
||||
def test_verify_sha256_mismatch(tmp_path: Path):
|
||||
f = tmp_path / "x.bin"
|
||||
f.write_bytes(b"hello world")
|
||||
assert verify_sha256(f, "0" * 64) is False
|
||||
|
||||
|
||||
def test_download_skip_if_present(tmp_path: Path, monkeypatch):
|
||||
f = tmp_path / "cached.zip"
|
||||
f.write_bytes(b"cached")
|
||||
spec = DatasetSpec(
|
||||
url="http://example.invalid/cached.zip",
|
||||
sha256=hashlib.sha256(b"cached").hexdigest(),
|
||||
target_subdir="cached",
|
||||
)
|
||||
# Should return the path without hitting the network
|
||||
called = {"n": 0}
|
||||
|
||||
def fake_get(*args, **kwargs):
|
||||
called["n"] += 1
|
||||
raise AssertionError("download should have been skipped")
|
||||
|
||||
monkeypatch.setattr("urllib.request.urlretrieve", fake_get)
|
||||
result = download_dataset(spec, f)
|
||||
assert result == f
|
||||
assert called["n"] == 0
|
||||
Reference in New Issue
Block a user