forked from UBC-MDS/Capstone_SatCast_Trilemma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_plot_series.py
More file actions
59 lines (52 loc) · 1.74 KB
/
Copy pathtest_plot_series.py
File metadata and controls
59 lines (52 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
test_plot_series.py
Unit tests for plot_series.py
"""
import numpy as np
import pandas as pd
import sys
from pathlib import Path
current_file = Path(__file__).resolve()
project_root = current_file.parents[1]
src_path = project_root / "src"
sys.path.insert(0, str(src_path))
from plot_series import plot_series
import pytest
from datetime import datetime
def test_plot_series_success():
"""
Test that plot_series generates a plot with the expected title when given
a valid DataFrame for a known series_id. Confirms standard visualization behavior.
"""
df = pd.DataFrame({
"series_id": ["A"] * 5,
"timestamp": pd.date_range("2025-01-01", periods=5, freq="15min"),
"y_true": np.arange(5),
"y_pred": np.arange(5) + 1
})
ax = plot_series(df, sid="A")
assert ax.get_title().startswith("Series A")
def test_plot_series_fail_missing_cols():
"""
Test that plot_series raises a ValueError when required columns ('y_true' or 'y_pred') are missing.
Validates input validation and informative error messaging for incomplete data.
"""
df = pd.DataFrame({
"series_id": ["A"],
"timestamp": [datetime.now()]
})
with pytest.raises(ValueError, match="missing"):
plot_series(df, sid="A")
def test_plot_series_fail_unknown_sid():
"""
Test that plot_series raises a ValueError when the provided series_id is not found in the DataFrame.
Ensures robust filtering and proper error reporting for invalid series requests.
"""
df = pd.DataFrame({
"series_id": ["B"],
"timestamp": [datetime.now()],
"y_true": [10],
"y_pred": [12]
})
with pytest.raises(ValueError, match="No data found"):
plot_series(df, sid="A")