From 0016818beb155f2a603f6f5477302c4d419cf176 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sun, 28 Aug 2022 14:13:33 -0700 Subject: [PATCH] Fix TZ test --- .github/workflows/ci.yaml | 1 - setup.cfg | 11 +++++++++++ tests/test_switch.py | 17 ++++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 setup.cfg diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 33dc1d6d..3067ec99 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,7 +29,6 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - pip install --upgrade pip pip install -r core/requirements.txt pip install -r core/requirements_test.txt pip install -e core/ diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..284326f5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,11 @@ +[isort] +force_sort_within_sections=True +profile=black + +[flake8] +ignore = E203, E266, W503 +max-line-length = 100 +max-complexity = 18 +select = B,C,E,F,W,T4,B9 +per-file-ignores = + code_example.py: E402, E501 diff --git a/tests/test_switch.py b/tests/test_switch.py index e2bb19bd..adfed407 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -3,8 +3,7 @@ import asyncio import datetime from random import randint - -import pytest +from unittest.mock import patch from homeassistant.components.adaptive_lighting.const import ( ADAPT_BRIGHTNESS_SWITCH, @@ -45,9 +44,9 @@ from homeassistant.components.light import ( ATTR_BRIGHTNESS_PCT, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, - DOMAIN as LIGHT_DOMAIN, - SERVICE_TURN_OFF, ) +from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN +from homeassistant.components.light import SERVICE_TURN_OFF from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN import homeassistant.config as config_util from homeassistant.const import ( @@ -62,8 +61,8 @@ from homeassistant.const import ( from homeassistant.core import Context, State from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util +import pytest -from unittest.mock import patch from tests.common import MockConfigEntry from tests.components.demo.test_light import ENTITY_LIGHT @@ -247,10 +246,10 @@ async def test_adaptive_lighting_time_zones_and_sun_settings( context = switch.create_context("test") # needs to be passed to update method min_color_temp = switch._sun_light_settings.min_color_temp - sunset = hass.config.time_zone.localize(SUNSET).astimezone(dt_util.UTC) + sunset = SUNSET.replace(tzinfo=dt_util.DEFAULT_TIME_ZONE).astimezone(dt_util.UTC) before_sunset = sunset - datetime.timedelta(hours=1) after_sunset = sunset + datetime.timedelta(hours=1) - sunrise = hass.config.time_zone.localize(SUNRISE).astimezone(dt_util.UTC) + sunrise = SUNRISE.replace(tzinfo=dt_util.DEFAULT_TIME_ZONE).astimezone(dt_util.UTC) before_sunrise = sunrise - datetime.timedelta(hours=1) after_sunrise = sunrise + datetime.timedelta(hours=1) @@ -333,10 +332,10 @@ async def test_light_settings(hass): await hass.async_block_till_done() # Test with different times - sunset = hass.config.time_zone.localize(SUNSET).astimezone(dt_util.UTC) + sunset = SUNSET.replace(tzinfo=dt_util.DEFAULT_TIME_ZONE).astimezone(dt_util.UTC) before_sunset = sunset - datetime.timedelta(hours=1) after_sunset = sunset + datetime.timedelta(hours=1) - sunrise = hass.config.time_zone.localize(SUNRISE).astimezone(dt_util.UTC) + sunrise = SUNRISE.replace(tzinfo=dt_util.DEFAULT_TIME_ZONE).astimezone(dt_util.UTC) before_sunrise = sunrise - datetime.timedelta(hours=1) after_sunrise = sunrise + datetime.timedelta(hours=1)