Add geiger_counter_visualizer/tests/test_core.py
This commit is contained in:
parent
32829c31c6
commit
9c56e2c359
1 changed files with 53 additions and 0 deletions
53
geiger_counter_visualizer/tests/test_core.py
Normal file
53
geiger_counter_visualizer/tests/test_core.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import pytest
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
from geiger_counter_visualizer import core
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_data_points():
|
||||
return [
|
||||
core.DataPoint(timestamp="2024-01-01T00:00:00", count=10, frequency=1.2),
|
||||
core.DataPoint(timestamp="2024-01-01T00:00:01", count=15, frequency=1.4),
|
||||
core.DataPoint(timestamp="2024-01-01T00:00:02", count=9, frequency=1.1)
|
||||
]
|
||||
|
||||
|
||||
def test_datapoint_initialization(sample_data_points):
|
||||
dp = sample_data_points[0]
|
||||
assert isinstance(dp.timestamp, str)
|
||||
assert dp.count == 10
|
||||
assert dp.frequency == pytest.approx(1.2)
|
||||
# Valid ISO timestamp
|
||||
parsed = datetime.fromisoformat(dp.timestamp)
|
||||
assert isinstance(parsed, datetime)
|
||||
|
||||
|
||||
def test_datapoint_type_validation():
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
core.DataPoint(timestamp=123, count="a", frequency="b")
|
||||
|
||||
|
||||
def test_visualize_data_monkeypatch(sample_data_points, monkeypatch):
|
||||
calls = {}
|
||||
|
||||
def fake_show():
|
||||
calls["called"] = True
|
||||
monkeypatch.setattr("matplotlib.pyplot.show", fake_show)
|
||||
|
||||
result = core.visualize_data(sample_data_points)
|
||||
assert result is None
|
||||
assert calls.get("called", False) is True
|
||||
|
||||
|
||||
def test_visualize_data_empty(monkeypatch):
|
||||
monkeypatch.setattr("matplotlib.pyplot.show", lambda: None)
|
||||
# visualize_data should handle empty list gracefully
|
||||
result = core.visualize_data([])
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_visualize_data_invalid_input(monkeypatch):
|
||||
monkeypatch.setattr("matplotlib.pyplot.show", lambda: None)
|
||||
with pytest.raises((AssertionError, TypeError)):
|
||||
core.visualize_data([{"timestamp": "2024-01-01", "count": 3, "frequency": 0.5}])
|
||||
Loading…
Reference in a new issue