mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 05:05:09 +02:00
Improve JSONEncoder test coverage (#47935)
This commit is contained in:
@@ -11,11 +11,17 @@ def test_json_encoder(hass):
|
||||
ha_json_enc = JSONEncoder()
|
||||
state = core.State("test.test", "hello")
|
||||
|
||||
# Test serializing a datetime
|
||||
now = dt_util.utcnow()
|
||||
assert ha_json_enc.default(now) == now.isoformat()
|
||||
|
||||
# Test serializing a set()
|
||||
data = {"milk", "beer"}
|
||||
assert sorted(ha_json_enc.default(data)) == sorted(list(data))
|
||||
|
||||
# Test serializing an object which implements as_dict
|
||||
assert ha_json_enc.default(state) == state.as_dict()
|
||||
|
||||
# Default method raises TypeError if non HA object
|
||||
with pytest.raises(TypeError):
|
||||
ha_json_enc.default(1)
|
||||
|
||||
now = dt_util.utcnow()
|
||||
assert ha_json_enc.default(now) == now.isoformat()
|
||||
|
Reference in New Issue
Block a user