Skip to content

Commit cb00c3b

Browse files
committed
test to cover added warning logs
1 parent aa5257a commit cb00c3b

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

test/test_eds.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import unittest
3+
from configparser import RawConfigParser
34

45
import canopen
56
from canopen.objectdictionary.eds import _signed_int_from_hex
@@ -173,6 +174,25 @@ def test_signed_int_from_hex_rejects_out_of_range(self):
173174
with self.assertRaises(ValueError):
174175
_signed_int_from_hex("-129", 8) # below minimum for 8-bit signed
175176

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+
176196
def test_array_compact_subobj(self):
177197
array = self.od[0x1003]
178198
self.assertIsInstance(array, canopen.objectdictionary.ODArray)

0 commit comments

Comments
 (0)