Skip to content

Commit

Permalink
style: black tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Feb 10, 2024
1 parent d76f64f commit 3c52a67
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 29 deletions.
10 changes: 7 additions & 3 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common methods used across tests for Tesla."""

from datetime import datetime
from unittest.mock import patch

Expand Down Expand Up @@ -80,9 +81,12 @@ async def setup_platform(hass: HomeAssistant, platform: str) -> MockConfigEntry:

mock_entry.add_to_hass(hass)

with patch("custom_components.tesla_custom.PLATFORMS", [platform]), patch(
"custom_components.tesla_custom.TeslaAPI", autospec=True
) as mock_controller:
with (
patch("custom_components.tesla_custom.PLATFORMS", [platform]),
patch(
"custom_components.tesla_custom.TeslaAPI", autospec=True
) as mock_controller,
):
setup_mock_controller(mock_controller)
assert await async_setup_component(hass, TESLA_DOMIN, {})
await hass.async_block_till_done()
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Global fixtures for integration_blueprint integration."""

# Fixtures allow you to replace functions with a Mock object. You can perform
# many options via the Mock to reflect a particular behavior from the original
# function that you want to see without going through the function's actual logic.
Expand Down
1 change: 1 addition & 0 deletions tests/test_button.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla button."""

from unittest.mock import patch

from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN
Expand Down
17 changes: 9 additions & 8 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla climate."""

from unittest.mock import patch

from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
Expand Down Expand Up @@ -85,10 +86,9 @@ async def test_set_preset_mode(hass: HomeAssistant) -> None:
"""Tests car setting HVAC mode."""
await setup_platform(hass, CLIMATE_DOMAIN)

with patch(
"teslajsonpy.car.TeslaCar.set_max_defrost"
) as mock_set_max_defrost, patch(
"teslajsonpy.car.TeslaCar.defrost_mode", return_value=1
with (
patch("teslajsonpy.car.TeslaCar.set_max_defrost") as mock_set_max_defrost,
patch("teslajsonpy.car.TeslaCar.defrost_mode", return_value=1),
):
# Test set preset_mode "Normal" with defrost_mode != 0
await hass.services.async_call(
Expand All @@ -102,10 +102,11 @@ async def test_set_preset_mode(hass: HomeAssistant) -> None:
)
mock_set_max_defrost.assert_awaited_once_with(False)

with patch(
"teslajsonpy.car.TeslaCar.set_climate_keeper_mode"
) as mock_set_climate_keeper_mode, patch(
"teslajsonpy.car.TeslaCar.climate_keeper_mode", return_value="on"
with (
patch(
"teslajsonpy.car.TeslaCar.set_climate_keeper_mode"
) as mock_set_climate_keeper_mode,
patch("teslajsonpy.car.TeslaCar.climate_keeper_mode", return_value="on"),
):
# Test set preset_mode "Normal" with climate_keeper_mode != 0
await hass.services.async_call(
Expand Down
29 changes: 17 additions & 12 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the Tesla config flow."""

import datetime
from http import HTTPStatus
from unittest.mock import patch
Expand Down Expand Up @@ -47,18 +48,22 @@ async def test_form(hass):
assert result["type"] == "form"
assert result["errors"] == {}

with patch(
"custom_components.tesla_custom.config_flow.TeslaAPI.connect",
return_value={
"refresh_token": TEST_TOKEN,
CONF_ACCESS_TOKEN: TEST_ACCESS_TOKEN,
CONF_EXPIRATION: TEST_VALID_EXPIRATION,
},
), patch(
"custom_components.tesla_custom.async_setup", return_value=True
) as mock_setup, patch(
"custom_components.tesla_custom.async_setup_entry", return_value=True
) as mock_setup_entry:
with (
patch(
"custom_components.tesla_custom.config_flow.TeslaAPI.connect",
return_value={
"refresh_token": TEST_TOKEN,
CONF_ACCESS_TOKEN: TEST_ACCESS_TOKEN,
CONF_EXPIRATION: TEST_VALID_EXPIRATION,
},
),
patch(
"custom_components.tesla_custom.async_setup", return_value=True
) as mock_setup,
patch(
"custom_components.tesla_custom.async_setup_entry", return_value=True
) as mock_setup_entry,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_TOKEN: TEST_TOKEN, CONF_USERNAME: "[email protected]"}
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_cover.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla cover."""

from unittest.mock import patch

from homeassistant.components.cover import DOMAIN as COVER_DOMAIN
Expand Down
1 change: 1 addition & 0 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla lock."""

from unittest.mock import patch

from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
Expand Down
1 change: 1 addition & 0 deletions tests/test_number.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla number."""

from unittest.mock import patch

from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN
Expand Down
1 change: 1 addition & 0 deletions tests/test_select.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla select."""

from unittest.mock import patch

from homeassistant.components.select import DOMAIN as SELECT_DOMAIN
Expand Down
16 changes: 10 additions & 6 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla switch."""

from unittest.mock import patch

from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
Expand Down Expand Up @@ -71,12 +72,15 @@ async def test_heated_steering(hass: HomeAssistant) -> None:
entity_id = "switch.my_model_s_heated_steering"

# We need to enable the switch for Testing.
with patch(
"custom_components.tesla_custom.switch.TeslaCarHeatedSteeringWheel.entity_registry_enabled_default",
return_value=True,
), patch(
"teslajsonpy.car.TeslaCar.set_heated_steering_wheel"
) as mock_seat_heated_steering_wheel:
with (
patch(
"custom_components.tesla_custom.switch.TeslaCarHeatedSteeringWheel.entity_registry_enabled_default",
return_value=True,
),
patch(
"teslajsonpy.car.TeslaCar.set_heated_steering_wheel"
) as mock_seat_heated_steering_wheel,
):
await setup_platform(hass, SWITCH_DOMAIN)

# Test switch on
Expand Down
1 change: 1 addition & 0 deletions tests/test_update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla update."""

from unittest.mock import patch

from homeassistant.components.update import DOMAIN as UPDATE_DOMAIN
Expand Down

0 comments on commit 3c52a67

Please sign in to comment.