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

Report what data is available when ModelInfo contains unexpected types

It seems that the data can cointain strings (see issue #62). Let's dump what
data we have available to be able to debug this.
This commit is contained in:
Frederik Gladhorn 2020-01-13 11:42:56 +01:00
parent ad34c8b2fd
commit 5a20b35171
2 changed files with 16 additions and 2 deletions

View File

@ -67,6 +67,10 @@ DATA = {
'type': 'Bit' 'type': 'Bit'
}, },
'Unexpected': {'type': 'Unexpected'}, 'Unexpected': {'type': 'Unexpected'},
'String': {
'type': 'String',
'option': 'some string'
},
}, },
'Course': { 'Course': {
"3": { "3": {
@ -117,6 +121,15 @@ class ModelInfoTest(unittest.TestCase):
self.assertEqual(expected, actual) self.assertEqual(expected, actual)
def test_value_unsupported(self): def test_value_unsupported(self):
data = "{'type': 'Unexpected'}"
with self.assertRaisesRegex( with self.assertRaisesRegex(
ValueError, 'unsupported value type Unexpected'): ValueError,
f"unsupported value type 'Unexpected' data: '{data}'"):
self.model_info.value('Unexpected') self.model_info.value('Unexpected')
def test_value_unsupported_but_data_available(self):
data = "{'type': 'String', 'option': 'some string}'"
with self.assertRaises(
ValueError,
msg=f"unsupported value type 'String' data: '{data}"):
self.model_info.value('String')

View File

@ -340,7 +340,8 @@ class ModelInfo(object):
ref = d['option'][0] ref = d['option'][0]
return ReferenceValue(self.data[ref]) return ReferenceValue(self.data[ref])
else: else:
raise ValueError("unsupported value type {}".format(d['type'])) raise ValueError(
f"unsupported value 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.