Skip to content

Commit

Permalink
unit tests check of default value fits in data type
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpdx committed Sep 15, 2024
1 parent 4fcec8d commit a5402f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion oresat_configs/base/c3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ objects:

- subindex: 0x3
name: pre_attempt_timeout
data_type: uint8
data_type: uint16
description: timeout before trying to deploy the antennas
access_type: const
default: 300 # 5 minutes
Expand Down
17 changes: 17 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
from oresat_configs import Consts, OreSatConfig
from oresat_configs._yaml_to_od import OD_DATA_TYPES, TPDO_COMM_START, TPDO_PARA_START

INT_MIN_MAX = {
canopen.objectdictionary.INTEGER8: (-(2**7), 2**7 - 1),
canopen.objectdictionary.INTEGER16: (-(2**15), 2**15 - 1),
canopen.objectdictionary.INTEGER32: (-(2**31), 2**31 - 1),
canopen.objectdictionary.INTEGER64: (-(2**63), 2**63 - 1),
canopen.objectdictionary.UNSIGNED8: (0, 2**8 - 1),
canopen.objectdictionary.UNSIGNED16: (0, 2**16 - 1),
canopen.objectdictionary.UNSIGNED32: (0, 2**32 - 1),
canopen.objectdictionary.UNSIGNED64: (0, 2**64 - 1),
}


class TestConfig(unittest.TestCase):
"""Base class to test a OreSat OD databases."""
Expand Down Expand Up @@ -124,6 +135,12 @@ def _test_variable(self, obj: canopen.objectdictionary.Variable) -> None:
int,
f"{node_name} object 0x{obj.index:X} 0x{obj.subindex:02X} was not a int",
)
int_min, int_max = INT_MIN_MAX[obj.data_type]
self.assertTrue(
int_min <= obj.default <= int_max,
f"{node_name} object 0x{obj.index:X} 0x{obj.subindex:02X} default of {obj.default}"
f" not between {int_min} and {int_max}",
)
elif obj.data_type in canopen.objectdictionary.FLOAT_TYPES:
self.assertIsInstance(
obj.default,
Expand Down

0 comments on commit a5402f4

Please sign in to comment.