Improve bad JSON data reporting (#47932)

* Improve bad data reporting

* Fix tests

Co-authored-by: Erik <erik@montnemery.com>
This commit is contained in:
Paulus Schoutsen 2021-03-15 02:41:25 -07:00 committed by GitHub
parent 9ec4c07753
commit 7fe3c472e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 10 deletions

View file

@ -153,7 +153,7 @@ def test_find_unserializable_data():
[State("mock_domain.mock_entity", "on", {"bad": bad_data})],
dump=partial(dumps, cls=MockJSONEncoder),
)
== {"$[0](state: mock_domain.mock_entity).attributes.bad": bad_data}
== {"$[0](State: mock_domain.mock_entity).attributes.bad": bad_data}
)
assert (
@ -161,5 +161,20 @@ def test_find_unserializable_data():
[Event("bad_event", {"bad_attribute": bad_data})],
dump=partial(dumps, cls=MockJSONEncoder),
)
== {"$[0](event: bad_event).data.bad_attribute": bad_data}
== {"$[0](Event: bad_event).data.bad_attribute": bad_data}
)
class BadData:
def __init__(self):
self.bla = bad_data
def as_dict(self):
return {"bla": self.bla}
assert (
find_paths_unserializable_data(
BadData(),
dump=partial(dumps, cls=MockJSONEncoder),
)
== {"$(BadData).bla": bad_data}
)