1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-27 20:40:18 -07:00

When ModelInfo contains yet unknown values, also report the name

Then we at least have some idea (hopefully) what kind of data we are
going to ignore. See issue #62.
This commit is contained in:
Frederik Gladhorn 2020-01-13 17:17:07 +01:00
parent cc3d60f882
commit 72040db991
2 changed files with 10 additions and 7 deletions

View File

@ -67,7 +67,7 @@ DATA = {
'type': 'Bit'
},
'Unexpected': {'type': 'Unexpected'},
'String': {
'StringOption': {
'type': 'String',
'option': 'some string'
},
@ -124,12 +124,14 @@ class ModelInfoTest(unittest.TestCase):
data = "{'type': 'Unexpected'}"
with self.assertRaisesRegex(
ValueError,
f"unsupported value type 'Unexpected' data: '{data}'"):
f"unsupported value name: 'Unexpected' type: 'Unexpected' "
f"data: '{data}'"):
self.model_info.value('Unexpected')
def test_value_unsupported_but_data_available(self):
data = "{'type': 'String', 'option': 'some string}'"
with self.assertRaises(
data = "{'type': 'String', 'option': 'some string'}"
with self.assertRaisesRegex(
ValueError,
msg=f"unsupported value type 'String' data: '{data}"):
self.model_info.value('String')
f"unsupported value name: 'StringOption'"
f" type: 'String' data: '{data}"):
self.model_info.value('StringOption')

View File

@ -341,7 +341,8 @@ class ModelInfo(object):
return ReferenceValue(self.data[ref])
else:
raise ValueError(
f"unsupported value type '{str(d['type'])}' data: '{str(d)}'")
f"unsupported value name: '{name}'"
f" type: '{str(d['type'])}' data: '{str(d)}'")
def default(self, name):
"""Get the default value, if it exists, for a given value.