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,23 +268,20 @@ 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."""
def test_eq(self):
"""Test events.""" """Test events."""
now = dt_util.utcnow() now = dt_util.utcnow()
data = {"some": "attr"} data = {"some": "attr"}
context = ha.Context() context = ha.Context()
event1, event2 = [ event1, event2 = [
ha.Event("some_type", data, time_fired=now, context=context) ha.Event("some_type", data, time_fired=now, context=context) for _ in range(2)
for _ in range(2)
] ]
assert event1 == event2 assert event1 == event2
def test_repr(self):
"""Test that repr method works.""" def test_event_repr():
"""Test that Event repr method works."""
assert str(ha.Event("TestEvent")) == "<Event TestEvent[L]>" assert str(ha.Event("TestEvent")) == "<Event TestEvent[L]>"
assert ( assert (
@ -292,8 +289,9 @@ class TestEvent(unittest.TestCase):
== "<Event TestEvent[R]: beer=nice>" == "<Event TestEvent[R]: beer=nice>"
) )
def test_as_dict(self):
"""Test as dictionary.""" def test_event_as_dict():
"""Test as Event as dictionary."""
event_type = "some_type" event_type = "some_type"
now = dt_util.utcnow() now = dt_util.utcnow()
data = {"some": "attr"} data = {"some": "attr"}
@ -310,7 +308,7 @@ class TestEvent(unittest.TestCase):
"user_id": event.context.user_id, "user_id": event.context.user_id,
}, },
} }
assert expected == event.as_dict() assert event.as_dict() == expected
class TestEventBus(unittest.TestCase): class TestEventBus(unittest.TestCase):