|
| 1 | +import numpy as np |
| 2 | +from os import PathLike |
| 3 | +from pathlib import Path |
| 4 | +from dataclasses import dataclass |
| 5 | +from typing import Iterable, Optional, Type, Union |
| 6 | +from harp.model import Model |
| 7 | + |
| 8 | +datapath = Path(__file__).parent |
| 9 | + |
| 10 | + |
| 11 | +@dataclass |
| 12 | +class DataFileParam: |
| 13 | + path: Union[str, PathLike] |
| 14 | + expected_rows: int |
| 15 | + expected_cols: Optional[Iterable[str]] = None |
| 16 | + expected_address: Optional[int] = None |
| 17 | + expected_dtype: Optional[np.dtype] = None |
| 18 | + expected_length: Optional[int] = None |
| 19 | + expected_error: Optional[Type[BaseException]] = None |
| 20 | + keep_type: bool = False |
| 21 | + |
| 22 | + def __post_init__(self): |
| 23 | + self.path = datapath / self.path |
| 24 | + |
| 25 | + |
| 26 | +@dataclass |
| 27 | +class DeviceSchemaParam: |
| 28 | + path: Union[str, PathLike] |
| 29 | + expected_whoAmI: int |
| 30 | + expected_device: Optional[int] = None |
| 31 | + expected_registers: Optional[Iterable[str]] = None |
| 32 | + expected_error: Optional[Type[BaseException]] = None |
| 33 | + |
| 34 | + def __post_init__(self): |
| 35 | + self.path = datapath / self.path |
| 36 | + |
| 37 | + def assert_schema(self, device: Model): |
| 38 | + assert device.whoAmI == self.expected_whoAmI |
| 39 | + if self.expected_registers: |
| 40 | + for register in self.expected_registers: |
| 41 | + assert register in device.registers |
0 commit comments