Rewrite core event tests to pytest tests (#40664)

This commit is contained in:
Franck Nijhof 2020-09-27 15:39:45 +02:00 committed by GitHub
parent 5274b03dc2
commit 0e6d54ea60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -268,49 +268,47 @@ async def test_add_job_with_none(hass):
hass.async_add_job(None, "test_arg") hass.async_add_job(None, "test_arg")
class TestEvent(unittest.TestCase): def test_event_eq():
"""A Test Event class.""" """Test events."""
now = dt_util.utcnow()
data = {"some": "attr"}
context = ha.Context()
event1, event2 = [
ha.Event("some_type", data, time_fired=now, context=context) for _ in range(2)
]
def test_eq(self): assert event1 == event2
"""Test events."""
now = dt_util.utcnow()
data = {"some": "attr"}
context = ha.Context()
event1, event2 = [
ha.Event("some_type", data, time_fired=now, context=context)
for _ in range(2)
]
assert event1 == event2
def test_repr(self): def test_event_repr():
"""Test that repr method works.""" """Test that Event repr method works."""
assert str(ha.Event("TestEvent")) == "<Event TestEvent[L]>" assert str(ha.Event("TestEvent")) == "<Event TestEvent[L]>"
assert ( assert (
str(ha.Event("TestEvent", {"beer": "nice"}, ha.EventOrigin.remote)) str(ha.Event("TestEvent", {"beer": "nice"}, ha.EventOrigin.remote))
== "<Event TestEvent[R]: beer=nice>" == "<Event TestEvent[R]: beer=nice>"
) )
def test_as_dict(self):
"""Test as dictionary."""
event_type = "some_type"
now = dt_util.utcnow()
data = {"some": "attr"}
event = ha.Event(event_type, data, ha.EventOrigin.local, now) def test_event_as_dict():
expected = { """Test as Event as dictionary."""
"event_type": event_type, event_type = "some_type"
"data": data, now = dt_util.utcnow()
"origin": "LOCAL", data = {"some": "attr"}
"time_fired": now,
"context": { event = ha.Event(event_type, data, ha.EventOrigin.local, now)
"id": event.context.id, expected = {
"parent_id": None, "event_type": event_type,
"user_id": event.context.user_id, "data": data,
}, "origin": "LOCAL",
} "time_fired": now,
assert expected == event.as_dict() "context": {
"id": event.context.id,
"parent_id": None,
"user_id": event.context.user_id,
},
}
assert event.as_dict() == expected
class TestEventBus(unittest.TestCase): class TestEventBus(unittest.TestCase):