1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add return type to tests without arguments (#87613)

* Add return type to tests without arguments

* Black

* Cancel fixture amends
This commit is contained in:
epenet
2023-02-07 14:20:06 +01:00
committed by GitHub
parent fb4c0b4b7a
commit 4142f0d15d
99 changed files with 473 additions and 459 deletions

View File

@@ -48,7 +48,7 @@ from .common import async_capture_events, async_mock_service
PST = dt_util.get_time_zone("America/Los_Angeles")
def test_split_entity_id():
def test_split_entity_id() -> None:
"""Test split_entity_id."""
assert ha.split_entity_id("domain.object_id") == ("domain", "object_id")
with pytest.raises(ValueError):
@@ -63,7 +63,7 @@ def test_split_entity_id():
ha.split_entity_id(".empty_domain")
def test_async_add_hass_job_schedule_callback():
def test_async_add_hass_job_schedule_callback() -> None:
"""Test that we schedule coroutines and add jobs to the job pool."""
hass = MagicMock()
job = MagicMock()
@@ -74,7 +74,7 @@ def test_async_add_hass_job_schedule_callback():
assert len(hass.add_job.mock_calls) == 0
def test_async_add_hass_job_schedule_partial_callback():
def test_async_add_hass_job_schedule_partial_callback() -> None:
"""Test that we schedule partial coros and add jobs to the job pool."""
hass = MagicMock()
job = MagicMock()
@@ -114,7 +114,7 @@ def test_async_add_hass_job_schedule_partial_coroutinefunction(event_loop):
assert len(hass.add_job.mock_calls) == 0
def test_async_add_job_add_hass_threaded_job_to_pool():
def test_async_add_job_add_hass_threaded_job_to_pool() -> None:
"""Test that we schedule coroutines and add jobs to the job pool."""
hass = MagicMock()
@@ -140,7 +140,7 @@ def test_async_create_task_schedule_coroutine(event_loop):
assert len(hass.add_job.mock_calls) == 0
def test_async_run_hass_job_calls_callback():
def test_async_run_hass_job_calls_callback() -> None:
"""Test that the callback annotation is respected."""
hass = MagicMock()
calls = []
@@ -153,7 +153,7 @@ def test_async_run_hass_job_calls_callback():
assert len(hass.async_add_job.mock_calls) == 0
def test_async_run_hass_job_delegates_non_async():
def test_async_run_hass_job_delegates_non_async() -> None:
"""Test that the callback annotation is respected."""
hass = MagicMock()
calls = []
@@ -322,7 +322,7 @@ async def test_add_job_with_none(hass):
hass.async_add_job(None, "test_arg")
def test_event_eq():
def test_event_eq() -> None:
"""Test events."""
now = dt_util.utcnow()
data = {"some": "attr"}
@@ -334,7 +334,7 @@ def test_event_eq():
assert event1.as_dict() == event2.as_dict()
def test_event_repr():
def test_event_repr() -> None:
"""Test that Event repr method works."""
assert str(ha.Event("TestEvent")) == "<Event TestEvent[L]>"
@@ -344,7 +344,7 @@ def test_event_repr():
)
def test_event_as_dict():
def test_event_as_dict() -> None:
"""Test an Event as dictionary."""
event_type = "some_type"
now = dt_util.utcnow()
@@ -367,7 +367,7 @@ def test_event_as_dict():
assert event.as_dict() == expected
def test_state_as_dict():
def test_state_as_dict() -> None:
"""Test a State as dictionary."""
last_time = datetime(1984, 12, 8, 12, 0, 0)
state = ha.State(
@@ -399,7 +399,7 @@ def test_state_as_dict():
assert state.as_dict() is as_dict_1
def test_state_as_compressed_state():
def test_state_as_compressed_state() -> None:
"""Test a State as compressed state."""
last_time = datetime(1984, 12, 8, 12, 0, 0, tzinfo=dt_util.UTC)
state = ha.State(
@@ -424,7 +424,7 @@ def test_state_as_compressed_state():
assert state.as_compressed_state() is as_compressed_state
def test_state_as_compressed_state_unique_last_updated():
def test_state_as_compressed_state_unique_last_updated() -> None:
"""Test a State as compressed state where last_changed is not last_updated."""
last_changed = datetime(1984, 12, 8, 11, 0, 0, tzinfo=dt_util.UTC)
last_updated = datetime(1984, 12, 8, 12, 0, 0, tzinfo=dt_util.UTC)
@@ -648,7 +648,7 @@ async def test_eventbus_max_length_exceeded(hass):
assert exc_info.value.value == long_evt_name
def test_state_init():
def test_state_init() -> None:
"""Test state.init."""
with pytest.raises(InvalidEntityFormatError):
ha.State("invalid_entity_format", "test_state")
@@ -657,38 +657,38 @@ def test_state_init():
ha.State("domain.long_state", "t" * 256)
def test_state_domain():
def test_state_domain() -> None:
"""Test domain."""
state = ha.State("some_domain.hello", "world")
assert state.domain == "some_domain"
def test_state_object_id():
def test_state_object_id() -> None:
"""Test object ID."""
state = ha.State("domain.hello", "world")
assert state.object_id == "hello"
def test_state_name_if_no_friendly_name_attr():
def test_state_name_if_no_friendly_name_attr() -> None:
"""Test if there is no friendly name."""
state = ha.State("domain.hello_world", "world")
assert state.name == "hello world"
def test_state_name_if_friendly_name_attr():
def test_state_name_if_friendly_name_attr() -> None:
"""Test if there is a friendly name."""
name = "Some Unique Name"
state = ha.State("domain.hello_world", "world", {ATTR_FRIENDLY_NAME: name})
assert state.name == name
def test_state_dict_conversion():
def test_state_dict_conversion() -> None:
"""Test conversion of dict."""
state = ha.State("domain.hello", "world", {"some": "attr"})
assert state.as_dict() == ha.State.from_dict(state.as_dict()).as_dict()
def test_state_dict_conversion_with_wrong_data():
def test_state_dict_conversion_with_wrong_data() -> None:
"""Test conversion with wrong data."""
assert ha.State.from_dict(None) is None
assert ha.State.from_dict({"state": "yes"}) is None
@@ -705,7 +705,7 @@ def test_state_dict_conversion_with_wrong_data():
assert wrong_context.context.id == "123"
def test_state_repr():
def test_state_repr() -> None:
"""Test state.repr."""
assert (
str(ha.State("happy.happy", "on", last_changed=datetime(1984, 12, 8, 12, 0, 0)))
@@ -813,7 +813,7 @@ async def test_statemachine_force_update(hass):
assert len(events) == 1
def test_service_call_repr():
def test_service_call_repr() -> None:
"""Test ServiceCall repr."""
call = ha.ServiceCall("homeassistant", "start")
assert str(call) == f"<ServiceCall homeassistant.start (c:{call.context.id})>"
@@ -1216,7 +1216,7 @@ async def test_service_call_event_contains_original_data(hass):
assert calls[0].context is context
def test_context():
def test_context() -> None:
"""Test context init."""
c = ha.Context()
assert c.user_id is None
@@ -1290,7 +1290,7 @@ async def test_cancel_service_task(hass, cancel_call):
assert service_cancelled
def test_valid_entity_id():
def test_valid_entity_id() -> None:
"""Test valid entity ID."""
for invalid in [
"_light.kitchen",