Skip to content

Commit 4686326

Browse files
committed
tweaks to tests for latest versions of astral and pytest-homeassistant-custom-component
1 parent ccfefd6 commit 4686326

13 files changed

+38
-37
lines changed

tests/test_apps_modules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from ast import literal_eval
44
import asyncio
55
import re
6+
from unittest.mock import patch
67

78
from custom_components.pyscript.const import DOMAIN, FOLDER
89
from mock_open import MockOpen
9-
from pytest_homeassistant_custom_component.async_mock import patch
1010

1111
from homeassistant.const import EVENT_STATE_CHANGED
1212
from homeassistant.setup import async_setup_component

tests/test_config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Tests for pyscript config flow."""
22
import logging
3+
from unittest.mock import patch
34

45
from custom_components.pyscript import PYSCRIPT_SCHEMA
56
from custom_components.pyscript.const import CONF_ALLOW_ALL_IMPORTS, CONF_HASS_IS_GLOBAL, DOMAIN
67
import pytest
7-
from pytest_homeassistant_custom_component.async_mock import patch
88

99
from homeassistant import data_entry_flow
1010
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER

tests/test_decorator_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from ast import literal_eval
33
import asyncio
44
from datetime import datetime as dt
5+
from unittest.mock import mock_open, patch
56

67
from custom_components.pyscript.const import DOMAIN
78
from custom_components.pyscript.function import Function
89
import custom_components.pyscript.trigger as trigger
9-
from pytest_homeassistant_custom_component.async_mock import mock_open, patch
1010

1111
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_STATE_CHANGED
1212
from homeassistant.setup import async_setup_component

tests/test_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from ast import literal_eval
33
import asyncio
44
from datetime import datetime as dt
5+
from unittest.mock import mock_open, patch
56

67
from custom_components.pyscript.const import DOMAIN
78
from custom_components.pyscript.function import Function
89
import custom_components.pyscript.trigger as trigger
9-
from pytest_homeassistant_custom_component.async_mock import mock_open, patch
1010

1111
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_STATE_CHANGED
1212
from homeassistant.setup import async_setup_component

tests/test_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import asyncio
55
from datetime import datetime as dt
66
import re
7+
from unittest.mock import MagicMock, Mock, patch
78

89
from custom_components.pyscript.const import CONF_ALLOW_ALL_IMPORTS, CONF_HASS_IS_GLOBAL, DOMAIN, FOLDER
910
from custom_components.pyscript.function import Function
1011
import custom_components.pyscript.trigger as trigger
1112
from mock_open import MockOpen
1213
import pytest
13-
from pytest_homeassistant_custom_component.async_mock import MagicMock, Mock, patch
1414

1515
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_STATE_CHANGED
1616
from homeassistant.core import Context

tests/test_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import asyncio
44
from datetime import datetime as dt
55
import pathlib
6+
from unittest.mock import mock_open, patch
67

78
from custom_components.pyscript.const import DOMAIN
89
from custom_components.pyscript.event import Event
910
from custom_components.pyscript.function import Function
1011
from custom_components.pyscript.global_ctx import GlobalContextMgr
1112
from custom_components.pyscript.state import State
1213
import custom_components.pyscript.trigger as trigger
13-
from pytest_homeassistant_custom_component.async_mock import mock_open, patch
1414

1515
from homeassistant import loader
1616
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_STATE_CHANGED

tests/test_jupyter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
import hmac
88
import json
99
import re
10+
from unittest.mock import patch
1011
import uuid
1112

1213
from custom_components.pyscript.const import DOMAIN, FOLDER
1314
from custom_components.pyscript.jupyter_kernel import ZmqSocket
1415
import custom_components.pyscript.trigger as trigger
1516
from mock_open import MockOpen
16-
from pytest_homeassistant_custom_component.async_mock import patch
1717

1818
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
1919
from homeassistant.setup import async_setup_component

tests/test_reload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import asyncio
44
import re
5+
from unittest.mock import patch
56

67
from custom_components.pyscript.const import DOMAIN, FOLDER
78
from mock_open import MockOpen
8-
from pytest_homeassistant_custom_component.async_mock import patch
99

1010
from homeassistant.const import EVENT_STATE_CHANGED
1111
from homeassistant.setup import async_setup_component

tests/test_requirements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test requirements helpers."""
22
import logging
3+
from unittest.mock import patch
34

45
from custom_components.pyscript.const import (
56
ATTR_INSTALLED_VERSION,
@@ -14,7 +15,6 @@
1415
)
1516
from custom_components.pyscript.requirements import install_requirements, process_all_requirements
1617
from pytest import fixture
17-
from pytest_homeassistant_custom_component.async_mock import patch
1818
from pytest_homeassistant_custom_component.common import MockConfigEntry
1919

2020
PYSCRIPT_FOLDER = "tests/test_data/test_requirements"

tests/test_state.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test pyscripts test module."""
2+
from unittest.mock import patch
3+
24
from custom_components.pyscript.state import State
3-
from pytest_homeassistant_custom_component.async_mock import patch
45

56
from homeassistant.core import Context
67
from homeassistant.helpers.state import State as HassState

tests/test_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import asyncio
44
import re
5+
from unittest.mock import patch
56

67
from custom_components.pyscript.const import DOMAIN, FOLDER
78
from mock_open import MockOpen
8-
from pytest_homeassistant_custom_component.async_mock import patch
99

1010
from homeassistant.const import EVENT_STATE_CHANGED
1111
from homeassistant.setup import async_setup_component

tests/test_unique.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from ast import literal_eval
33
import asyncio
44
from datetime import datetime as dt
5+
from unittest.mock import mock_open, patch
56

67
from custom_components.pyscript.const import DOMAIN
78
from custom_components.pyscript.function import Function
89
import custom_components.pyscript.trigger as trigger
9-
from pytest_homeassistant_custom_component.async_mock import mock_open, patch
1010

1111
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_STATE_CHANGED
1212
from homeassistant.setup import async_setup_component

tests/test_unit_trigger.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Unit tests for time trigger functions."""
22

33
from datetime import datetime as dt, timedelta
4+
from unittest.mock import patch
45

56
from custom_components.pyscript.function import Function
67
from custom_components.pyscript.trigger import TrigTime
78
import pytest
8-
from pytest_homeassistant_custom_component.async_mock import patch
99

1010
parseDateTimeTests = [
1111
["2019/9/12 13:45", 0, dt(2019, 9, 12, 13, 45, 0, 0)],
@@ -47,17 +47,17 @@
4747
["16:01", 0, dt(2019, 9, 1, 16, 1, 0, 0)],
4848
["14:56", 1, dt(2019, 9, 2, 14, 56, 0, 0)],
4949
["8:00:23.6", 1, dt(2019, 9, 2, 8, 0, 23, 600000)],
50-
["sunrise", 0, dt(2019, 9, 1, 6, 37, 15, 0)],
51-
["sunrise", 1, dt(2019, 9, 2, 6, 38, 6, 0)],
52-
["sunrise", 2, dt(2019, 9, 3, 6, 38, 58, 0)],
53-
["tuesday sunrise", 0, dt(2019, 9, 3, 6, 38, 58, 0)],
54-
["sunrise + 1hr", 0, dt(2019, 9, 1, 7, 37, 15, 0)],
55-
["sunset", 0, dt(2019, 9, 1, 19, 39, 15, 0)],
50+
["sunrise", 0, dt(2019, 9, 1, 6, 37, 58, 0)],
51+
["sunrise", 1, dt(2019, 9, 2, 6, 38, 49, 0)],
52+
["sunrise", 2, dt(2019, 9, 3, 6, 39, 41, 0)],
53+
["tuesday sunrise", 0, dt(2019, 9, 3, 6, 39, 41, 0)],
54+
["sunrise + 1hr", 0, dt(2019, 9, 1, 7, 37, 58, 0)],
55+
["sunset", 0, dt(2019, 9, 1, 19, 37, 23, 0)],
5656
["now", 0, dt(2019, 9, 1, 13, 0, 0, 0)],
5757
["now +1 min", 0, dt(2019, 9, 1, 13, 1, 0, 0)],
5858
["now +1 hours", 0, dt(2019, 9, 1, 14, 0, 0, 0)],
59-
["2019/11/4 sunset + 1min", 0, dt(2019, 11, 4, 17, 7, 56, 0)],
60-
["11/4 sunset + 2min", 0, dt(2019, 11, 4, 17, 8, 56, 0)],
59+
["2019/11/4 sunset + 1min", 0, dt(2019, 11, 4, 17, 6, 37, 0)],
60+
["11/4 sunset + 2min", 0, dt(2019, 11, 4, 17, 7, 37, 0)],
6161
["+5 min", 0, dt(2019, 9, 1, 0, 5, 0, 0)],
6262
]
6363

@@ -166,14 +166,14 @@ async def test_parse_date_time_day_names(hass, caplog):
166166
("not range(20:00, 10:00)", dt(2019, 9, 3, 19, 59, 59, 999999), True),
167167
("not range(20:00, 10:00)", dt(2019, 9, 3, 12, 0, 0, 0), True),
168168
("not range(20:00, 10:00)", dt(2019, 9, 3, 0, 0, 0, 0), False),
169-
("range(sunrise, sunset)", dt(2019, 9, 1, 6, 37, 14, 0), False),
170-
("range(sunrise, sunset)", dt(2019, 9, 1, 6, 37, 16, 0), True),
171-
("range(sunrise, sunset - 20m)", dt(2019, 9, 1, 19, 19, 14, 0), True),
172-
("range(sunrise, sunset - 20m)", dt(2019, 9, 1, 19, 19, 16, 0), False),
173-
("range(sunrise + 20m, sunset)", dt(2019, 9, 2, 6, 58, 5, 0), False),
174-
("range(sunrise + 20m, sunset)", dt(2019, 9, 2, 6, 58, 7, 0), True),
175-
("range(sunrise, sunset + 1m)", dt(2019, 11, 4, 17, 7, 55, 0), True),
176-
("range(sunrise, sunset + 1m)", dt(2019, 11, 4, 17, 7, 57, 0), False),
169+
("range(sunrise, sunset)", dt(2019, 9, 1, 6, 37, 57, 0), False),
170+
("range(sunrise, sunset)", dt(2019, 9, 1, 6, 37, 59, 0), True),
171+
("range(sunrise, sunset - 20m)", dt(2019, 9, 1, 19, 17, 22, 0), True),
172+
("range(sunrise, sunset - 20m)", dt(2019, 9, 1, 19, 17, 24, 0), False),
173+
("range(sunrise + 20m, sunset)", dt(2019, 9, 2, 6, 58, 48, 0), False),
174+
("range(sunrise + 20m, sunset)", dt(2019, 9, 2, 6, 58, 50, 0), True),
175+
("range(sunrise, sunset + 1m)", dt(2019, 11, 4, 17, 6, 36, 0), True),
176+
("range(sunrise, sunset + 1m)", dt(2019, 11, 4, 17, 6, 38, 0), False),
177177
("cron(* * * * *)", dt(2019, 9, 3, 6, 0, 0, 0), True),
178178
("cron(* * * 9 *)", dt(2019, 9, 3, 6, 0, 0, 0), True),
179179
("cron(* * 3 9 *)", dt(2019, 9, 3, 6, 0, 0, 0), True),
@@ -293,14 +293,14 @@ def test_timer_active_check(hass, spec, now, expected):
293293
[
294294
["period(sunset, 4 hours, sunrise)"],
295295
[
296-
dt(2019, 9, 1, 19, 39, 15),
297-
dt(2019, 9, 1, 23, 39, 15),
298-
dt(2019, 9, 2, 3, 39, 15),
299-
dt(2019, 9, 2, 19, 37, 46),
300-
dt(2019, 9, 2, 23, 37, 46),
301-
dt(2019, 9, 3, 3, 37, 46),
302-
dt(2019, 9, 3, 19, 36, 17),
303-
dt(2019, 9, 3, 23, 36, 17),
296+
dt(2019, 9, 1, 19, 37, 23),
297+
dt(2019, 9, 1, 23, 37, 23),
298+
dt(2019, 9, 2, 3, 37, 23),
299+
dt(2019, 9, 2, 19, 35, 53),
300+
dt(2019, 9, 2, 23, 35, 53),
301+
dt(2019, 9, 3, 3, 35, 53),
302+
dt(2019, 9, 3, 19, 34, 23),
303+
dt(2019, 9, 3, 23, 34, 23),
304304
],
305305
],
306306
[

0 commit comments

Comments
 (0)