Add drift_data_collection/tests/test_core.py
This commit is contained in:
parent
7306182a4e
commit
06def8ca31
1 changed files with 51 additions and 0 deletions
51
drift_data_collection/tests/test_core.py
Normal file
51
drift_data_collection/tests/test_core.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import json
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from drift_data_collection import core
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_run_ids(tmp_path: Path):
|
||||
file = tmp_path / "run_ids.json"
|
||||
data = ["run_001", "run_002", "run_003"]
|
||||
file.write_text(json.dumps(data))
|
||||
return file, data
|
||||
|
||||
|
||||
def test_collect_frozen_runs_returns_list(sample_run_ids):
|
||||
_, run_ids = sample_run_ids
|
||||
result = core.collect_frozen_runs(run_ids)
|
||||
assert isinstance(result, list)
|
||||
# Ensure structure consistency
|
||||
for item in result:
|
||||
assert isinstance(item, dict)
|
||||
assert set(["run_id", "status", "timestamp", "pinned_state", "metrics"]).issubset(item.keys())
|
||||
|
||||
|
||||
def test_collect_frozen_runs_content_valid(sample_run_ids):
|
||||
_, run_ids = sample_run_ids
|
||||
result = core.collect_frozen_runs(run_ids)
|
||||
valid_statuses = {"PASS", "WARN", "FAIL"}
|
||||
for run_data in result:
|
||||
# Validate run_id
|
||||
assert run_data["run_id"] in run_ids
|
||||
# Validate allowed statuses
|
||||
assert run_data["status"] in valid_statuses
|
||||
# Validate timestamp format
|
||||
ts = datetime.fromisoformat(run_data["timestamp"])
|
||||
assert isinstance(ts, datetime)
|
||||
# Validate pinned_state
|
||||
assert isinstance(run_data["pinned_state"], bool)
|
||||
# Validate metrics field
|
||||
assert isinstance(run_data["metrics"], str)
|
||||
|
||||
|
||||
def test_collect_frozen_runs_empty_input():
|
||||
result = core.collect_frozen_runs([])
|
||||
assert result == []
|
||||
|
||||
|
||||
def test_collect_frozen_runs_invalid_input_type():
|
||||
with pytest.raises((TypeError, AssertionError)):
|
||||
core.collect_frozen_runs(None) # type: ignore
|
||||
Loading…
Reference in a new issue