Skip to content

Commit 0a37b2b

Browse files
committed
Add regression tests for reference epoch
1 parent 7f10063 commit 0a37b2b

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

tests/params.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dataclasses import dataclass
2+
from datetime import datetime
23
from os import PathLike
34
from pathlib import Path
45
from typing import Iterable, Optional, Type, Union
@@ -20,6 +21,7 @@ class DataFileParam:
2021
expected_length: Optional[int] = None
2122
expected_error: Optional[Type[BaseException]] = None
2223
repeat_data: Optional[int] = None
24+
epoch: Optional[datetime] = None
2325
keep_type: bool = False
2426

2527
def __post_init__(self):

tests/test_io.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from contextlib import nullcontext
22

33
import numpy as np
4+
import pandas as pd
45
import pytest
56
from pytest import mark
67

7-
from harp.io import MessageType, format, parse, read
8+
from harp.io import REFERENCE_EPOCH, MessageType, format, parse, read
89
from tests.params import DataFileParam
910

1011
testdata = [
@@ -30,6 +31,7 @@
3031
DataFileParam(path="data/write_0.bin", expected_address=0, expected_rows=4),
3132
DataFileParam(path="data/write_0.bin", expected_address=0, expected_rows=4, keep_type=True),
3233
DataFileParam(path="data/device_0.bin", expected_rows=300, repeat_data=300),
34+
DataFileParam(path="data/device_0.bin", expected_rows=1, epoch=REFERENCE_EPOCH),
3335
]
3436

3537

@@ -46,6 +48,7 @@ def test_read(dataFile: DataFileParam):
4648
address=dataFile.expected_address,
4749
dtype=dataFile.expected_dtype,
4850
length=dataFile.expected_length,
51+
epoch=dataFile.epoch,
4952
keep_type=dataFile.keep_type,
5053
)
5154
else:
@@ -54,9 +57,11 @@ def test_read(dataFile: DataFileParam):
5457
address=dataFile.expected_address,
5558
dtype=dataFile.expected_dtype,
5659
length=dataFile.expected_length,
60+
epoch=dataFile.epoch,
5761
keep_type=dataFile.keep_type,
5862
)
5963
assert len(data) == dataFile.expected_rows
64+
assert isinstance(data.index, pd.DatetimeIndex if dataFile.epoch else pd.Index)
6065
if dataFile.keep_type:
6166
assert MessageType.__name__ in data.columns and data[MessageType.__name__].dtype == "category"
6267

0 commit comments

Comments
 (0)