Skip to content

Commit 328045b

Browse files
add tests
1 parent 7a50961 commit 328045b

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

tests/test_datamanage.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,127 @@ def test__get(self):
11191119
),
11201120
]
11211121
)
1122+
1123+
def test__get_warm_storage(self):
1124+
# Mock the drio_client
1125+
drio_client = Mock()
1126+
drio_client.get_samples_aggregate.return_value = pd.Series(
1127+
data=[1.1, 1.2, 1.3], index=[1.0, 2.0, 3.0]
1128+
)
1129+
1130+
# Labels to request
1131+
labels = {
1132+
"a": "timeseriesid-a",
1133+
"b": "timeseriesid-b",
1134+
"c": "timeseriesid-c",
1135+
}
1136+
1137+
# Instantiate DrioDataSource with storage="warm" and constructor kwargs
1138+
source = DrioDataSource(
1139+
drio_client,
1140+
labels,
1141+
storage="warm",
1142+
convert_date=True,
1143+
raise_empty=False,
1144+
aggregation_period="1h",
1145+
aggregation_function="min",
1146+
)
1147+
1148+
# Call _get (no kwargs allowed per your current design)
1149+
data_out = source._get("<start-time>", "<end-time>")
1150+
1151+
# Expected output
1152+
data_expect = {
1153+
"a": pd.Series(data=[1.1, 1.2, 1.3], index=[1.0, 2.0, 3.0]),
1154+
"b": pd.Series(data=[1.1, 1.2, 1.3], index=[1.0, 2.0, 3.0]),
1155+
"c": pd.Series(data=[1.1, 1.2, 1.3], index=[1.0, 2.0, 3.0]),
1156+
}
1157+
1158+
# Assert returned data is correct
1159+
assert data_out.keys() == data_expect.keys()
1160+
for key, series_expect in data_expect.items():
1161+
pd.testing.assert_series_equal(series_expect, data_out[key])
1162+
1163+
# Assert get_samples_aggregate called with correct parameters
1164+
drio_client.get_samples_aggregate.assert_has_calls(
1165+
[
1166+
call(
1167+
"timeseriesid-a",
1168+
start="<start-time>",
1169+
end="<end-time>",
1170+
aggregation_period="1h",
1171+
aggregation_function="min"
1172+
),
1173+
call(
1174+
"timeseriesid-b",
1175+
start="<start-time>",
1176+
end="<end-time>",
1177+
aggregation_period="1h",
1178+
aggregation_function="min"
1179+
),
1180+
call(
1181+
"timeseriesid-c",
1182+
start="<start-time>",
1183+
end="<end-time>",
1184+
aggregation_period="1h",
1185+
aggregation_function="min"
1186+
),
1187+
]
1188+
)
1189+
1190+
def test__get_warm_defaults(self):
1191+
# Mock the drio_client
1192+
drio_client = Mock()
1193+
drio_client.get_samples_aggregate.return_value = pd.Series(
1194+
data=[10, 20, 30], index=[1, 2, 3]
1195+
)
1196+
1197+
labels = {
1198+
"x": "ts-x",
1199+
"y": "ts-y",
1200+
}
1201+
1202+
# Instantiate DrioDataSource with storage="warm", no overrides
1203+
source = DrioDataSource(
1204+
drio_client,
1205+
labels,
1206+
storage="warm",
1207+
convert_date=True,
1208+
raise_empty=False
1209+
)
1210+
1211+
# Call _get with defaults
1212+
data_out = source._get("<start>", "<end>")
1213+
1214+
# Expected series
1215+
expected = pd.Series([10, 20, 30], index=[1, 2, 3])
1216+
1217+
# Assert keys and values
1218+
assert data_out.keys() == labels.keys()
1219+
for key in labels:
1220+
pd.testing.assert_series_equal(data_out[key], expected)
1221+
1222+
# Assert get_samples_aggregate called with default aggregation values
1223+
drio_client.get_samples_aggregate.assert_has_calls(
1224+
[
1225+
call(
1226+
"ts-x",
1227+
start="<start>",
1228+
end="<end>",
1229+
aggregation_period="tick",
1230+
aggregation_function="mean"
1231+
),
1232+
call(
1233+
"ts-y",
1234+
start="<start>",
1235+
end="<end>",
1236+
aggregation_period="tick",
1237+
aggregation_function="mean"
1238+
),
1239+
]
1240+
)
1241+
1242+
11221243

11231244

11241245
class Test_NullDataSource:

0 commit comments

Comments
 (0)