1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-29 13:30:26 -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' 'type': 'Bit'
}, },
'Unexpected': {'type': 'Unexpected'}, 'Unexpected': {'type': 'Unexpected'},
'String': { 'StringOption': {
'type': 'String', 'type': 'String',
'option': 'some string' 'option': 'some string'
}, },
@ -124,12 +124,14 @@ class ModelInfoTest(unittest.TestCase):
data = "{'type': 'Unexpected'}" data = "{'type': 'Unexpected'}"
with self.assertRaisesRegex( with self.assertRaisesRegex(
ValueError, ValueError,
f"unsupported value type 'Unexpected' data: '{data}'"): f"unsupported value name: 'Unexpected' type: 'Unexpected' "
f"data: '{data}'"):
self.model_info.value('Unexpected') self.model_info.value('Unexpected')
def test_value_unsupported_but_data_available(self): def test_value_unsupported_but_data_available(self):
data = "{'type': 'String', 'option': 'some string}'" data = "{'type': 'String', 'option': 'some string'}"
with self.assertRaises( with self.assertRaisesRegex(
ValueError, ValueError,
msg=f"unsupported value type 'String' data: '{data}"): f"unsupported value name: 'StringOption'"
self.model_info.value('String') f" type: 'String' data: '{data}"):
self.model_info.value('StringOption')

View File

@ -341,7 +341,8 @@ class ModelInfo(object):
return ReferenceValue(self.data[ref]) return ReferenceValue(self.data[ref])
else: else:
raise ValueError( 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): def default(self, name):
"""Get the default value, if it exists, for a given value. """Get the default value, if it exists, for a given value.