-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_reader.py
More file actions
43 lines (36 loc) · 1.3 KB
/
test_reader.py
File metadata and controls
43 lines (36 loc) · 1.3 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
import pandas as pd
from pytest import mark
from harp.data.io import REFERENCE_EPOCH, MessageType
from harp.data.reader import create_reader
from tests.params import DeviceSchemaParam
testdata = [
DeviceSchemaParam(
path="data",
expected_whoAmI=0,
expected_registers=["AnalogData"],
),
DeviceSchemaParam(
path="data/device.yml",
expected_whoAmI=0,
expected_registers=["AnalogData"],
),
DeviceSchemaParam(
path="data/device.yml",
expected_whoAmI=0,
expected_registers=["AnalogDataPayloadSpec"],
),
]
@mark.parametrize("schemaFile", testdata)
def test_create_reader(schemaFile: DeviceSchemaParam):
reader = create_reader(schemaFile.path, epoch=REFERENCE_EPOCH)
schemaFile.assert_schema(reader.device)
whoAmI = reader.WhoAmI.read()
assert reader.device.whoAmI == whoAmI.iloc[0, 0]
assert isinstance(whoAmI.index, pd.DatetimeIndex)
whoAmI = reader.WhoAmI.read(epoch=None, keep_type=True)
assert isinstance(whoAmI.index, pd.Index)
assert whoAmI.iloc[0, -1] == MessageType.READ.name
if schemaFile.expected_registers:
for register_name in schemaFile.expected_registers:
data = reader.registers[register_name].read()
assert isinstance(data.index, pd.DatetimeIndex)