|
1 | 1 | import os |
2 | 2 | import unittest |
| 3 | +from configparser import RawConfigParser |
3 | 4 |
|
4 | 5 | import canopen |
5 | 6 | from canopen.objectdictionary.eds import _signed_int_from_hex |
@@ -173,6 +174,25 @@ def test_signed_int_from_hex_rejects_out_of_range(self): |
173 | 174 | with self.assertRaises(ValueError): |
174 | 175 | _signed_int_from_hex("-129", 8) # below minimum for 8-bit signed |
175 | 176 |
|
| 177 | + def test_build_variable_range_warnings(self): |
| 178 | + eds = RawConfigParser() |
| 179 | + cases = [ |
| 180 | + ("2003", "LowLimit", str(-0xFFFF)), # INTEGER16 < signed min |
| 181 | + ("2003", "HighLimit", "0x10000"), # INTEGER16 > unsigned max |
| 182 | + ("2001", "DefaultValue", "SOMETHING"), # BOOLEAN non-numeric |
| 183 | + ("2003", "DefaultValue", "SOMETHING"), # INTEGER16 non-numeric |
| 184 | + ("2006", "ParameterValue", ""), # UNSIGNED16 empty |
| 185 | + ] |
| 186 | + for index, option, value in cases: |
| 187 | + with self.subTest(index=index, option=option, value=value): |
| 188 | + # Fresh version for mutating temporarily |
| 189 | + eds.clear() |
| 190 | + eds.read(DATATYPES_EDS) |
| 191 | + eds[index][option] = value |
| 192 | + with self.assertLogs(level="WARN") as cm: |
| 193 | + build_variable(eds, index, 42, objectcodes.VAR, int(index, 16)) |
| 194 | + self.assertRegex(cm.output[0], option) |
| 195 | + |
176 | 196 | def test_array_compact_subobj(self): |
177 | 197 | array = self.od[0x1003] |
178 | 198 | self.assertIsInstance(array, canopen.objectdictionary.ODArray) |
|
0 commit comments