Add trace_analysis_script/tests/test_core.py
This commit is contained in:
parent
f9f7dcc40a
commit
c67b74ed2e
1 changed files with 51 additions and 0 deletions
51
trace_analysis_script/tests/test_core.py
Normal file
51
trace_analysis_script/tests/test_core.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import json
|
||||||
|
import math
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from trace_analysis_script import core
|
||||||
|
|
||||||
|
def _create_sample_trace_file(tmp_path: Path) -> Path:
|
||||||
|
data = {
|
||||||
|
'time': np.arange(0, 1, 0.01),
|
||||||
|
'signal': np.sin(2 * np.pi * 5 * np.arange(0, 1, 0.01)) * 0.5 + 0.5
|
||||||
|
}
|
||||||
|
df = pd.DataFrame(data)
|
||||||
|
file_path = tmp_path / 'sample_trace.csv'
|
||||||
|
df.to_csv(file_path, index=False)
|
||||||
|
return file_path
|
||||||
|
|
||||||
|
def test_analyze_trace_returns_dict_with_expected_keys(tmp_path):
|
||||||
|
trace_file = _create_sample_trace_file(tmp_path)
|
||||||
|
result = core.analyze_trace(str(trace_file))
|
||||||
|
|
||||||
|
assert isinstance(result, dict)
|
||||||
|
expected_keys = {'peak_amplitude', 'median_bandpower', 'crosscorr_with_clockevents'}
|
||||||
|
assert set(result.keys()) == expected_keys
|
||||||
|
|
||||||
|
for key in expected_keys:
|
||||||
|
assert isinstance(result[key], (float, int))
|
||||||
|
|
||||||
|
|
||||||
|
def test_peak_amplitude_value_is_reasonable(tmp_path):
|
||||||
|
trace_file = _create_sample_trace_file(tmp_path)
|
||||||
|
result = core.analyze_trace(str(trace_file))
|
||||||
|
assert 0.4 <= result['peak_amplitude'] <= 0.6
|
||||||
|
|
||||||
|
|
||||||
|
def test_crosscorr_with_clockevents_is_numeric(tmp_path):
|
||||||
|
trace_file = _create_sample_trace_file(tmp_path)
|
||||||
|
result = core.analyze_trace(str(trace_file))
|
||||||
|
val = result['crosscorr_with_clockevents']
|
||||||
|
assert isinstance(val, (float, int))
|
||||||
|
assert -1.0 <= val <= 1.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_handles_invalid_input_file_gracefully(tmp_path):
|
||||||
|
invalid_path = tmp_path / 'nonexistent.csv'
|
||||||
|
with pytest.raises((FileNotFoundError, ValueError)):
|
||||||
|
_ = core.analyze_trace(str(invalid_path))
|
||||||
Loading…
Reference in a new issue