Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Jan 27, 2019
1 parent 74b726c commit 549b051
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions tests/test_setup.py
Expand Up @@ -186,11 +186,10 @@ def test_validate_platform_config(self):
def test_validate_platform_config_2(self):
"""Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA."""
platform_schema = PLATFORM_SCHEMA.extend({
'cheers': str,
'hello': str,
})
platform_schema_base = PLATFORM_SCHEMA.extend({
'hello': str,
platform_schema_base = PLATFORM_SCHEMA_BASE.extend({
'hello': 'world',
})
loader.set_component(
self.hass,
Expand All @@ -207,7 +206,7 @@ def test_validate_platform_config_2(self):

with assert_setup_component(0):
assert setup.setup_component(self.hass, 'platform_conf', {
# Should fail: no extra keys allowed
# fail: no extra keys allowed in platform schema
'platform_conf': {
'platform': 'whatever',
'hello': 'world',
Expand All @@ -220,16 +219,15 @@ def test_validate_platform_config_2(self):

with assert_setup_component(1):
assert setup.setup_component(self.hass, 'platform_conf', {
# Should pass
# pass
'platform_conf': {
'platform': 'whatever',
'hello': 'world',
},
# Should fail: key cheers not in component platform_schema_base
# fail: key hello violates component platform_schema_base
'platform_conf 2': {
'platform': 'whatever',
'hello': 'world',
'cheers': 'mate'
'hello': 'there'
}
})

Expand All @@ -238,12 +236,12 @@ def test_validate_platform_config_2(self):

def test_validate_platform_config_3(self):
"""Test fallback to component PLATFORM_SCHEMA."""
component_schema = PLATFORM_SCHEMA.extend({
component_schema = PLATFORM_SCHEMA_BASE.extend({
'hello': str,
})
platform_schema = PLATFORM_SCHEMA.extend({
'cheers': str,
'hello': str,
'hello': 'world',
})
loader.set_component(
self.hass,
Expand All @@ -260,7 +258,7 @@ def test_validate_platform_config_3(self):
with assert_setup_component(0):
assert setup.setup_component(self.hass, 'platform_conf', {
'platform_conf': {
# Should fail: no extra keys allowed
# fail: no extra keys allowed
'hello': 'world',
'invalid': 'extra',
}
Expand All @@ -271,16 +269,15 @@ def test_validate_platform_config_3(self):

with assert_setup_component(1):
assert setup.setup_component(self.hass, 'platform_conf', {
# Should pass
# pass
'platform_conf': {
'platform': 'whatever',
'hello': 'world',
},
# Should fail: key cheers not in component platform_schema
# fail: fail: key hello violates component platform_schema
'platform_conf 2': {
'platform': 'whatever',
'hello': 'world',
'cheers': 'mate'
'hello': 'there'
}
})

Expand Down

0 comments on commit 549b051

Please sign in to comment.