Skip to content

Commit

Permalink
Linting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffy2 committed Dec 8, 2024
1 parent 0cfce17 commit 186f78f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
14 changes: 7 additions & 7 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Helpers for tests."""

import asyncio
from datetime import datetime
import functools as ft
import os
import time
from unittest.mock import patch

from datetime import datetime
from homeassistant import core as ha
from homeassistant.core import HomeAssistant
from homeassistant.util.async_ import run_callback_threadsafe
import homeassistant.util.dt as date_util
import homeassistant.util.dt as dt_util


def load_fixture(filename):
Expand Down Expand Up @@ -52,13 +52,13 @@ def threadsafe(*args, **kwargs):

@ha.callback
def async_fire_time_changed(
hass: HomeAssistant, datetime_: datetime = None, fire_all: bool = False
hass: HomeAssistant, datetime_: datetime | None = None, fire_all: bool = False
) -> None:
"""Fire a time changed event."""
if datetime_ is None:
datetime_ = date_util.utcnow()
datetime_ = dt_util.utcnow()

for task in list(hass.loop._scheduled):
for task in list(hass.loop._scheduled): # noqa: SLF001
if not isinstance(task, asyncio.TimerHandle):
continue
if task.cancelled():
Expand All @@ -70,9 +70,9 @@ def async_fire_time_changed(
if fire_all or mock_seconds_into_future >= future_seconds:
with patch(
"homeassistant.helpers.event.time_tracker_utcnow",
return_value=date_util.as_utc(datetime_),
return_value=dt_util.as_utc(datetime_),
):
task._run()
task._run() # noqa: SLF001
task.cancel()


Expand Down
18 changes: 7 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Fixtures for keymaster tests. """
"""Fixtures for keymaster tests."""

import asyncio
import copy
Expand All @@ -18,7 +18,8 @@

@pytest.fixture(autouse=True)
def auto_enable_custom_integrations(enable_custom_integrations):
yield
"""Enable custom integrations defined in the test dir."""
return


@pytest.fixture(name="skip_notifications", autouse=True)
Expand All @@ -31,7 +32,7 @@ def skip_notifications_fixture():
yield


@pytest.fixture()
@pytest.fixture
def mock_get_entities():
"""Mock email data update class values."""
with patch(
Expand Down Expand Up @@ -95,7 +96,7 @@ def mock_osmakedir():

@pytest.fixture
def mock_os_path_join():
"""Fixture to mock splitext"""
"""Fixture to mock path join."""
with patch("os.path.join"):
yield

Expand Down Expand Up @@ -144,7 +145,7 @@ async def connect():
async def listen(driver_ready: asyncio.Event) -> None:
driver_ready.set()
await asyncio.sleep(30)
assert False, "Listen wasn't canceled!"
pytest.fail("Listen wasn't canceled!")

async def disconnect():
client.connected = False
Expand Down Expand Up @@ -236,7 +237,7 @@ async def mock_zwavejs_set_usercode():

@pytest.fixture
async def mock_using_zwavejs():
"""Fixture to mock using_zwavejs in helpers"""
"""Fixture to mock using_zwavejs in helpers."""
with patch(
"custom_components.keymaster.helpers.async_using_zwave_js",
return_value=True,
Expand All @@ -255,8 +256,3 @@ def immediate_call(hass, delay, callback):

mock.side_effect = immediate_call
yield mock


def pytest_runtest_protocol(item, nextitem):
print(f"Starting test: {item.nodeid}")
return None
2 changes: 1 addition & 1 deletion tests/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Constants for tests. """
"""Constants for tests."""

CONFIG_DATA = {
"alarm_level_or_user_code_entity_id": "sensor.kwikset_touchpad_electronic_deadbolt_alarm_level_frontdoor",
Expand Down

0 comments on commit 186f78f

Please sign in to comment.