Add data_analysis/tests/test_core.py
This commit is contained in:
parent
d5a27e1ee5
commit
e22f644d22
1 changed files with 57 additions and 0 deletions
57
data_analysis/tests/test_core.py
Normal file
57
data_analysis/tests/test_core.py
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
import json
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import src.data_analysis.core as core
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def sample_data(tmp_path):
|
||||||
|
# Create a temporary CSV to simulate realistic temperature data
|
||||||
|
csv_path = tmp_path / "test_temperature_data.csv"
|
||||||
|
data = [
|
||||||
|
["Beton", 18.5, 0.95, "2024-08-01T22:00:00"],
|
||||||
|
["Wasser", 17.1, 0.98, "2024-08-01T22:00:00"],
|
||||||
|
["Luft", 19.0, 0.99, "2024-08-01T22:00:00"],
|
||||||
|
["Beton", 17.8, 0.95, "2024-08-01T23:00:00"],
|
||||||
|
["Wasser", 16.9, 0.98, "2024-08-01T23:00:00"],
|
||||||
|
["Luft", 19.3, 0.99, "2024-08-01T23:00:00"],
|
||||||
|
]
|
||||||
|
df = pd.DataFrame(data, columns=["surface", "temperature_c", "emissivity", "timestamp"])
|
||||||
|
df.to_csv(csv_path, index=False)
|
||||||
|
return pd.read_csv(csv_path)
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_temperature_data_returns_analysisresult(sample_data):
|
||||||
|
result = core.analyze_temperature_data(sample_data)
|
||||||
|
assert isinstance(result, core.AnalysisResult)
|
||||||
|
assert hasattr(result, "temperature_differences")
|
||||||
|
assert hasattr(result, "pattern_recognition")
|
||||||
|
|
||||||
|
|
||||||
|
def test_analysisresult_to_json_valid(sample_data):
|
||||||
|
result = core.analyze_temperature_data(sample_data)
|
||||||
|
json_output = result.to_json()
|
||||||
|
parsed = json.loads(json_output)
|
||||||
|
assert isinstance(parsed, dict)
|
||||||
|
assert "temperature_differences" in parsed
|
||||||
|
assert "pattern_recognition" in parsed
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_temperature_data_edge_empty_dataframe():
|
||||||
|
empty_df = pd.DataFrame(columns=["surface", "temperature_c", "emissivity", "timestamp"])
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
core.analyze_temperature_data(empty_df)
|
||||||
|
|
||||||
|
|
||||||
|
def test_analysisresult_strict_type_validation():
|
||||||
|
# Ensure that AnalysisResult enforces correct types or fails gracefully
|
||||||
|
with pytest.raises((TypeError, ValueError)):
|
||||||
|
_ = core.AnalysisResult(temperature_differences="wrong_type", pattern_recognition=123)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pattern_recognition_nonempty(sample_data):
|
||||||
|
result = core.analyze_temperature_data(sample_data)
|
||||||
|
assert isinstance(result.pattern_recognition, str)
|
||||||
|
assert len(result.pattern_recognition) > 0
|
||||||
Loading…
Reference in a new issue