Add artifact.1/tests/test_core.py

This commit is contained in:
Mika 2026-02-01 03:11:13 +00:00
parent da20aa3715
commit 42ebafcad4

View file

@ -0,0 +1,41 @@
import pytest
import pandas as pd
import os
from pathlib import Path
import matplotlib.figure as figure
from artifact_1.core import generate_signal_plot
def _create_test_csv(tmp_path: Path) -> Path:
data = [
{"timestamp": "2024-01-01T00:00:00Z", "frequency_MHz": 87.5, "signal_dB": -40.0, "noise_dB": -90.0, "lat": 48.5, "lon": 13.5},
{"timestamp": "2024-01-01T00:00:01Z", "frequency_MHz": 88.0, "signal_dB": -35.0, "noise_dB": -85.0, "lat": 48.5, "lon": 13.5},
{"timestamp": "2024-01-01T00:00:02Z", "frequency_MHz": 88.5, "signal_dB": -30.0, "noise_dB": -80.0, "lat": 48.5, "lon": 13.5},
]
df = pd.DataFrame(data)
csv_path = tmp_path / "test_sample.csv"
df.to_csv(csv_path, index=False)
return csv_path
def test_generate_signal_plot_valid(tmp_path):
csv_path = _create_test_csv(tmp_path)
fig = generate_signal_plot(str(csv_path))
assert isinstance(fig, figure.Figure)
assert len(fig.axes) > 0, "Figure should contain at least one axis"
# Check if axis title or labels contain frequency or signal
ax = fig.axes[0]
assert any('Frequency' in (label or '') for label in [ax.get_xlabel(), ax.get_ylabel(), ax.get_title()]), 'Labels should mention frequency or signal'
def test_generate_signal_plot_invalid_path():
with pytest.raises((FileNotFoundError, pd.errors.EmptyDataError, ValueError)):
generate_signal_plot('nonexistent.csv')
def test_generate_signal_plot_empty_file(tmp_path):
empty_csv = tmp_path / 'empty.csv'
empty_csv.write_text('')
with pytest.raises((pd.errors.EmptyDataError, ValueError)):
generate_signal_plot(str(empty_csv))