diff --git a/artifact.001/tests/test_core.py b/artifact.001/tests/test_core.py new file mode 100644 index 0000000..cd29f65 --- /dev/null +++ b/artifact.001/tests/test_core.py @@ -0,0 +1,71 @@ +import json +import os +from pathlib import Path +import pytest + +# We assume the code under test is in src/artifact_001/core.py +import sys +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'src')) + +from artifact_001 import core + +@pytest.fixture +def sample_meteor_event(): + return core.MeteorEvent(timestamp='2024-06-01T23:59:59', intensity=2.5, exposure_time=500.0) + + +def test_capture_meteors_returns_list_of_meteorevent(monkeypatch): + # Simulate a deterministic set of meteor events + def fake_now(): + from datetime import datetime + return datetime(2024, 1, 1, 0, 0, 0) + + from datetime import datetime + monkeypatch.setattr(core.datetime, 'datetime', type('FakeDatetime', (), {'now': staticmethod(fake_now)})) + + events = core.capture_meteors(500.0) + assert isinstance(events, list) + assert all(isinstance(e, core.MeteorEvent) for e in events) + assert all(e.exposure_time == 500.0 for e in events) + assert all(hasattr(e, 'timestamp') and hasattr(e, 'intensity') for e in events) + + +def test_log_data_creates_json_file(tmp_path, sample_meteor_event): + test_file = tmp_path / 'meteor_events.json' + data = [sample_meteor_event] + + # Patch output path in core module + monkey_output = tmp_path / 'meteor_events.json' + core.LOG_OUTPUT_PATH = monkey_output + + # Log data + core.log_data(data) + + assert monkey_output.exists() + with open(monkey_output, 'r', encoding='utf-8') as f: + content = json.load(f) + assert isinstance(content, list) + assert all(isinstance(item, dict) for item in content) + assert content[0]['exposure_time'] == pytest.approx(500.0) + assert 'timestamp' in content[0] + assert 'intensity' in content[0] + + +def test_log_data_with_empty_list(tmp_path): + monkey_output = tmp_path / 'empty.json' + core.LOG_OUTPUT_PATH = monkey_output + core.log_data([]) + assert monkey_output.exists() + with open(monkey_output, 'r', encoding='utf-8') as f: + content = json.load(f) + assert content == [] + + +def test_meteor_event_fields(sample_meteor_event): + event = sample_meteor_event + assert isinstance(event.timestamp, str) + assert isinstance(event.intensity, float) + assert isinstance(event.exposure_time, float) + # Integrity check + assert event.intensity > 0 + assert event.exposure_time > 0 \ No newline at end of file