Skip to content

Commit 57c0244

Browse files
authored
Fix broken invalid_config tests (home-assistant#148965)
1 parent 414057d commit 57c0244

File tree

7 files changed

+42
-38
lines changed

7 files changed

+42
-38
lines changed

tests/components/counter/test_init.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ async def _storage(items=None, config=None):
7373
return _storage
7474

7575

76-
async def test_config(hass: HomeAssistant) -> None:
76+
@pytest.mark.parametrize(
77+
"invalid_config",
78+
[None, 1, {"name with space": None}],
79+
)
80+
async def test_config(hass: HomeAssistant, invalid_config) -> None:
7781
"""Test config."""
78-
invalid_configs = [None, 1, {}, {"name with space": None}]
7982

80-
for cfg in invalid_configs:
81-
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
83+
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: invalid_config})
8284

8385

8486
async def test_config_options(hass: HomeAssistant) -> None:

tests/components/input_boolean/test_init.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ async def _storage(items=None, config=None):
5454
return _storage
5555

5656

57-
async def test_config(hass: HomeAssistant) -> None:
57+
@pytest.mark.parametrize(
58+
"invalid_config",
59+
[None, 1, {"name with space": None}],
60+
)
61+
async def test_config(hass: HomeAssistant, invalid_config) -> None:
5862
"""Test config."""
59-
invalid_configs = [None, 1, {}, {"name with space": None}]
6063

61-
for cfg in invalid_configs:
62-
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
64+
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: invalid_config})
6365

6466

6567
async def test_methods(hass: HomeAssistant) -> None:

tests/components/input_button/test_init.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ async def _storage(items=None, config=None):
4747
return _storage
4848

4949

50-
async def test_config(hass: HomeAssistant) -> None:
50+
@pytest.mark.parametrize(
51+
"invalid_config",
52+
[None, 1, {"name with space": None}],
53+
)
54+
async def test_config(hass: HomeAssistant, invalid_config) -> None:
5155
"""Test config."""
52-
invalid_configs = [None, 1, {}, {"name with space": None}]
5356

54-
for cfg in invalid_configs:
55-
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
57+
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: invalid_config})
5658

5759

5860
async def test_config_options(hass: HomeAssistant) -> None:

tests/components/input_number/test_init.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,19 @@ async def decrement(hass: HomeAssistant, entity_id: str) -> None:
9898
)
9999

100100

101-
async def test_config(hass: HomeAssistant) -> None:
102-
"""Test config."""
103-
invalid_configs = [
101+
@pytest.mark.parametrize(
102+
"invalid_config",
103+
[
104104
None,
105-
{},
106105
{"name with space": None},
107106
{"test_1": {"min": 50, "max": 50}},
108-
]
109-
for cfg in invalid_configs:
110-
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
107+
{"test_1": {"min": 0, "max": 10, "initial": 11}},
108+
],
109+
)
110+
async def test_config(hass: HomeAssistant, invalid_config) -> None:
111+
"""Test config."""
112+
113+
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: invalid_config})
111114

112115

113116
async def test_set_value(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:

tests/components/input_select/test_init.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ async def _storage(items=None, config=None, minor_version=STORAGE_VERSION_MINOR)
7070
return _storage
7171

7272

73-
async def test_config(hass: HomeAssistant) -> None:
74-
"""Test config."""
75-
invalid_configs = [
73+
@pytest.mark.parametrize(
74+
"invalid_config",
75+
[
7676
None,
77-
{},
7877
{"name with space": None},
7978
{"bad_initial": {"options": [1, 2], "initial": 3}},
80-
]
79+
],
80+
)
81+
async def test_config(hass: HomeAssistant, invalid_config) -> None:
82+
"""Test config."""
8183

82-
for cfg in invalid_configs:
83-
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
84+
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: invalid_config})
8485

8586

8687
async def test_select_option(hass: HomeAssistant) -> None:

tests/components/schedule/test_init.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,11 @@ async def _schedule_setup(
131131
return _schedule_setup
132132

133133

134-
async def test_invalid_config(hass: HomeAssistant) -> None:
134+
@pytest.mark.parametrize("invalid_config", [None, {"name with space": None}])
135+
async def test_invalid_config(hass: HomeAssistant, invalid_config) -> None:
135136
"""Test invalid configs."""
136-
invalid_configs = [
137-
None,
138-
{},
139-
{"name with space": None},
140-
]
141137

142-
for cfg in invalid_configs:
143-
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
138+
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: invalid_config})
144139

145140

146141
@pytest.mark.parametrize(

tests/components/timer/test_init.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ async def _storage(items=None, config=None):
9292
return _storage
9393

9494

95-
async def test_config(hass: HomeAssistant) -> None:
95+
@pytest.mark.parametrize("invalid_config", [None, 1, {"name with space": None}])
96+
async def test_config(hass: HomeAssistant, invalid_config) -> None:
9697
"""Test config."""
97-
invalid_configs = [None, 1, {}, {"name with space": None}]
9898

99-
for cfg in invalid_configs:
100-
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
99+
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: invalid_config})
101100

102101

103102
async def test_config_options(hass: HomeAssistant) -> None:

0 commit comments

Comments
 (0)