mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix tests
This commit is contained in:
parent
9c09a98c9e
commit
b7607ff472
@ -90,7 +90,7 @@ class TestSetup:
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
def test_validate_platform_config(self):
|
def test_validate_platform_config(self, caplog):
|
||||||
"""Test validating platform configuration."""
|
"""Test validating platform configuration."""
|
||||||
platform_schema = PLATFORM_SCHEMA.extend({
|
platform_schema = PLATFORM_SCHEMA.extend({
|
||||||
'hello': str,
|
'hello': str,
|
||||||
@ -109,7 +109,7 @@ class TestSetup:
|
|||||||
MockPlatform('whatever',
|
MockPlatform('whatever',
|
||||||
platform_schema=platform_schema))
|
platform_schema=platform_schema))
|
||||||
|
|
||||||
with assert_setup_component(0):
|
with assert_setup_component(1):
|
||||||
assert setup.setup_component(self.hass, 'platform_conf', {
|
assert setup.setup_component(self.hass, 'platform_conf', {
|
||||||
'platform_conf': {
|
'platform_conf': {
|
||||||
'platform': 'whatever',
|
'platform': 'whatever',
|
||||||
@ -117,11 +117,12 @@ class TestSetup:
|
|||||||
'invalid': 'extra',
|
'invalid': 'extra',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
assert caplog.text.count('Your configuration contains extra keys') == 1
|
||||||
|
|
||||||
self.hass.data.pop(setup.DATA_SETUP)
|
self.hass.data.pop(setup.DATA_SETUP)
|
||||||
self.hass.config.components.remove('platform_conf')
|
self.hass.config.components.remove('platform_conf')
|
||||||
|
|
||||||
with assert_setup_component(1):
|
with assert_setup_component(2):
|
||||||
assert setup.setup_component(self.hass, 'platform_conf', {
|
assert setup.setup_component(self.hass, 'platform_conf', {
|
||||||
'platform_conf': {
|
'platform_conf': {
|
||||||
'platform': 'whatever',
|
'platform': 'whatever',
|
||||||
@ -132,6 +133,7 @@ class TestSetup:
|
|||||||
'invalid': True
|
'invalid': True
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
assert caplog.text.count('Your configuration contains extra keys') == 2
|
||||||
|
|
||||||
self.hass.data.pop(setup.DATA_SETUP)
|
self.hass.data.pop(setup.DATA_SETUP)
|
||||||
self.hass.config.components.remove('platform_conf')
|
self.hass.config.components.remove('platform_conf')
|
||||||
@ -183,7 +185,7 @@ class TestSetup:
|
|||||||
assert 'platform_conf' in self.hass.config.components
|
assert 'platform_conf' in self.hass.config.components
|
||||||
assert not config['platform_conf'] # empty
|
assert not config['platform_conf'] # empty
|
||||||
|
|
||||||
def test_validate_platform_config_2(self):
|
def test_validate_platform_config_2(self, caplog):
|
||||||
"""Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA."""
|
"""Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA."""
|
||||||
platform_schema = PLATFORM_SCHEMA.extend({
|
platform_schema = PLATFORM_SCHEMA.extend({
|
||||||
'hello': str,
|
'hello': str,
|
||||||
@ -204,7 +206,7 @@ class TestSetup:
|
|||||||
MockPlatform('whatever',
|
MockPlatform('whatever',
|
||||||
platform_schema=platform_schema))
|
platform_schema=platform_schema))
|
||||||
|
|
||||||
with assert_setup_component(0):
|
with assert_setup_component(1):
|
||||||
assert setup.setup_component(self.hass, 'platform_conf', {
|
assert setup.setup_component(self.hass, 'platform_conf', {
|
||||||
# fail: no extra keys allowed in platform schema
|
# fail: no extra keys allowed in platform schema
|
||||||
'platform_conf': {
|
'platform_conf': {
|
||||||
@ -213,6 +215,7 @@ class TestSetup:
|
|||||||
'invalid': 'extra',
|
'invalid': 'extra',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
assert caplog.text.count('Your configuration contains extra keys') == 1
|
||||||
|
|
||||||
self.hass.data.pop(setup.DATA_SETUP)
|
self.hass.data.pop(setup.DATA_SETUP)
|
||||||
self.hass.config.components.remove('platform_conf')
|
self.hass.config.components.remove('platform_conf')
|
||||||
@ -234,7 +237,7 @@ class TestSetup:
|
|||||||
self.hass.data.pop(setup.DATA_SETUP)
|
self.hass.data.pop(setup.DATA_SETUP)
|
||||||
self.hass.config.components.remove('platform_conf')
|
self.hass.config.components.remove('platform_conf')
|
||||||
|
|
||||||
def test_validate_platform_config_3(self):
|
def test_validate_platform_config_3(self, caplog):
|
||||||
"""Test fallback to component PLATFORM_SCHEMA."""
|
"""Test fallback to component PLATFORM_SCHEMA."""
|
||||||
component_schema = PLATFORM_SCHEMA_BASE.extend({
|
component_schema = PLATFORM_SCHEMA_BASE.extend({
|
||||||
'hello': str,
|
'hello': str,
|
||||||
@ -255,15 +258,15 @@ class TestSetup:
|
|||||||
MockPlatform('whatever',
|
MockPlatform('whatever',
|
||||||
platform_schema=platform_schema))
|
platform_schema=platform_schema))
|
||||||
|
|
||||||
with assert_setup_component(0):
|
with assert_setup_component(1):
|
||||||
assert setup.setup_component(self.hass, 'platform_conf', {
|
assert setup.setup_component(self.hass, 'platform_conf', {
|
||||||
'platform_conf': {
|
'platform_conf': {
|
||||||
# fail: no extra keys allowed
|
|
||||||
'platform': 'whatever',
|
'platform': 'whatever',
|
||||||
'hello': 'world',
|
'hello': 'world',
|
||||||
'invalid': 'extra',
|
'invalid': 'extra',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
assert caplog.text.count('Your configuration contains extra keys') == 1
|
||||||
|
|
||||||
self.hass.data.pop(setup.DATA_SETUP)
|
self.hass.data.pop(setup.DATA_SETUP)
|
||||||
self.hass.config.components.remove('platform_conf')
|
self.hass.config.components.remove('platform_conf')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user