Skip to content

Commit 05674e7

Browse files
committed
remove unused patches and variables in tests
1 parent 84e9a8e commit 05674e7

File tree

5 files changed

+23
-84
lines changed

5 files changed

+23
-84
lines changed

tests/test_decorator_errors.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
from ast import literal_eval
33
import asyncio
44
from datetime import datetime as dt
5-
import pathlib
65

76
from custom_components.pyscript.const import DOMAIN
87
import custom_components.pyscript.trigger as trigger
98
from pytest_homeassistant.async_mock import mock_open, patch
109

11-
from homeassistant import loader
1210
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_STATE_CHANGED
1311
from homeassistant.setup import async_setup_component
1412

@@ -18,18 +16,10 @@ async def setup_script(hass, notify_q, now, source):
1816
scripts = [
1917
"/some/config/dir/pyscripts/hello.py",
2018
]
21-
integration = loader.Integration(
22-
hass,
23-
"custom_components.pyscript",
24-
pathlib.Path("custom_components/pyscript"),
25-
{"name": "pyscript", "dependencies": [], "requirements": [], "domain": "automation"},
26-
)
2719

28-
with patch("homeassistant.loader.async_get_integration", return_value=integration), patch(
29-
"custom_components.pyscript.os.path.isdir", return_value=True
30-
), patch("custom_components.pyscript.glob.iglob", return_value=scripts), patch(
31-
"custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,
32-
), patch(
20+
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
21+
"custom_components.pyscript.glob.iglob", return_value=scripts
22+
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,), patch(
3323
"custom_components.pyscript.trigger.dt_now", return_value=now
3424
):
3525
assert await async_setup_component(hass, "pyscript", {DOMAIN: {}})

tests/test_function.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from ast import literal_eval
33
import asyncio
44
from datetime import datetime as dt
5-
import pathlib
65
import time
76

87
from custom_components.pyscript.const import DOMAIN
@@ -11,7 +10,6 @@
1110
import pytest
1211
from pytest_homeassistant.async_mock import MagicMock, Mock, mock_open, patch
1312

14-
from homeassistant import loader
1513
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_STATE_CHANGED
1614
from homeassistant.setup import async_setup_component
1715

@@ -104,18 +102,10 @@ async def setup_script(hass, notify_q, now, source):
104102
scripts = [
105103
"/some/config/dir/pyscripts/hello.py",
106104
]
107-
integration = loader.Integration(
108-
hass,
109-
"custom_components.pyscript",
110-
pathlib.Path("custom_components/pyscript"),
111-
{"name": "pyscript", "dependencies": [], "requirements": [], "domain": "automation"},
112-
)
113105

114-
with patch("homeassistant.loader.async_get_integration", return_value=integration), patch(
115-
"custom_components.pyscript.os.path.isdir", return_value=True
116-
), patch("custom_components.pyscript.glob.iglob", return_value=scripts), patch(
117-
"custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,
118-
), patch(
106+
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
107+
"custom_components.pyscript.glob.iglob", return_value=scripts
108+
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,), patch(
119109
"custom_components.pyscript.trigger.dt_now", return_value=now
120110
):
121111
assert await async_setup_component(hass, "pyscript", {DOMAIN: {}})

tests/test_init.py

+11-32
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,10 @@ async def setup_script(hass, notify_q, now, source):
2424
scripts = [
2525
"/some/config/dir/pyscript/hello.py",
2626
]
27-
integration = loader.Integration(
28-
hass,
29-
"custom_components.pyscript",
30-
pathlib.Path("custom_components/pyscript"),
31-
{"name": "pyscript", "dependencies": [], "requirements": [], "domain": "automation"},
32-
)
3327

34-
with patch("homeassistant.loader.async_get_integration", return_value=integration), patch(
35-
"custom_components.pyscript.os.path.isdir", return_value=True
36-
), patch("custom_components.pyscript.glob.iglob", return_value=scripts), patch(
37-
"custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,
38-
), patch(
28+
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
29+
"custom_components.pyscript.glob.iglob", return_value=scripts
30+
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,), patch(
3931
"custom_components.pyscript.trigger.dt_now", return_value=now
4032
), patch(
4133
"homeassistant.config.load_yaml_config_file", return_value={}
@@ -67,16 +59,9 @@ async def wait_until_done(notify_q):
6759

6860
async def test_setup_makedirs_on_no_dir(hass, caplog):
6961
"""Test setup calls os.makedirs when no dir found."""
70-
integration = loader.Integration(
71-
hass,
72-
"custom_components.pyscript",
73-
pathlib.Path("custom_components/pyscript"),
74-
{"name": "pyscript", "dependencies": [], "requirements": [], "domain": "automation"},
75-
)
76-
77-
with patch("homeassistant.loader.async_get_integration", return_value=integration), patch(
78-
"custom_components.pyscript.os.path.isdir", return_value=False
79-
), patch("custom_components.pyscript.os.makedirs") as makedirs_call:
62+
with patch("custom_components.pyscript.os.path.isdir", return_value=False), patch(
63+
"custom_components.pyscript.os.makedirs"
64+
) as makedirs_call:
8065
res = await async_setup_component(hass, "pyscript", {DOMAIN: {}})
8166

8267
assert res
@@ -237,7 +222,7 @@ def func_yaml_doc_string(param2=None, param3=None):
237222
{"name": "pyscript", "dependencies": [], "requirements": [], "domain": "automation"},
238223
)
239224

240-
with patch("homeassistant.loader.async_get_integration", return_value=integration), patch(
225+
with patch(
241226
"homeassistant.loader.async_get_custom_components", return_value={"pyscript": integration},
242227
):
243228
descriptions = await async_get_all_descriptions(hass)
@@ -442,16 +427,10 @@ def func5(var_name=None, value=None):
442427
scripts = [
443428
"/some/config/dir/pyscript/hello.py",
444429
]
445-
integration = loader.Integration(
446-
hass,
447-
"custom_components.pyscript",
448-
pathlib.Path("custom_components/pyscript"),
449-
{"name": "pyscript", "dependencies": [], "requirements": [], "domain": "automation"},
450-
)
451-
452-
with patch("homeassistant.loader.async_get_integration", return_value=integration), patch(
453-
"custom_components.pyscript.os.path.isdir", return_value=True
454-
), patch("custom_components.pyscript.glob.iglob", return_value=scripts), patch(
430+
431+
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
432+
"custom_components.pyscript.glob.iglob", return_value=scripts
433+
), patch(
455434
"custom_components.pyscript.global_ctx.open", mock_open(read_data=next_source), create=True,
456435
), patch(
457436
"custom_components.pyscript.trigger.dt_now", return_value=now

tests/test_jupyter.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
import hashlib
77
import hmac
88
import json
9-
import pathlib
109
import uuid
1110

1211
from custom_components.pyscript.const import DOMAIN
1312
from custom_components.pyscript.jupyter_kernel import ZmqSocket
1413
import custom_components.pyscript.trigger as trigger
1514
from pytest_homeassistant.async_mock import mock_open, patch
1615

17-
from homeassistant import loader
1816
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
1917
from homeassistant.setup import async_setup_component
2018

@@ -112,18 +110,10 @@ async def setup_script(hass, now, source, no_connect=False):
112110
scripts = [
113111
"/some/config/dir/pyscripts/hello.py",
114112
]
115-
integration = loader.Integration(
116-
hass,
117-
"custom_components.pyscript",
118-
pathlib.Path("custom_components/pyscript"),
119-
{"name": "pyscript", "dependencies": [], "requirements": [], "domain": "automation"},
120-
)
121113

122-
with patch("homeassistant.loader.async_get_integration", return_value=integration,), patch(
123-
"custom_components.pyscript.os.path.isdir", return_value=True
124-
), patch("custom_components.pyscript.glob.iglob", return_value=scripts), patch(
125-
"custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,
126-
), patch(
114+
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
115+
"custom_components.pyscript.glob.iglob", return_value=scripts
116+
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,), patch(
127117
"custom_components.pyscript.trigger.dt_now", return_value=now
128118
):
129119
assert await async_setup_component(hass, "pyscript", {DOMAIN: {}})

tests/test_unique.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
from ast import literal_eval
33
import asyncio
44
from datetime import datetime as dt
5-
import pathlib
65

76
from custom_components.pyscript.const import DOMAIN
87
import custom_components.pyscript.trigger as trigger
98
from pytest_homeassistant.async_mock import mock_open, patch
109

11-
from homeassistant import loader
1210
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_STATE_CHANGED
1311
from homeassistant.setup import async_setup_component
1412

@@ -18,18 +16,10 @@ async def setup_script(hass, notify_q, now, source):
1816
scripts = [
1917
"/some/config/dir/pyscripts/hello.py",
2018
]
21-
integration = loader.Integration(
22-
hass,
23-
"custom_components.pyscript",
24-
pathlib.Path("custom_components/pyscript"),
25-
{"name": "pyscript", "dependencies": [], "requirements": [], "domain": "automation"},
26-
)
2719

28-
with patch("homeassistant.loader.async_get_integration", return_value=integration), patch(
29-
"custom_components.pyscript.os.path.isdir", return_value=True
30-
), patch("custom_components.pyscript.glob.iglob", return_value=scripts), patch(
31-
"custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,
32-
), patch(
20+
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
21+
"custom_components.pyscript.glob.iglob", return_value=scripts
22+
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source), create=True,), patch(
3323
"custom_components.pyscript.trigger.dt_now", return_value=now
3424
):
3525
assert await async_setup_component(hass, "pyscript", {DOMAIN: {}})

0 commit comments

Comments
 (0)