Improve test coverage of error conditions.
parent
95748a6880
commit
d54e10e54a
|
@ -4,9 +4,6 @@ tests.components.sensor.template
|
|||
|
||||
Tests template sensor.
|
||||
"""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import homeassistant.core as ha
|
||||
import homeassistant.components.sensor as sensor
|
||||
|
@ -56,8 +53,46 @@ class TestTemplateSensor:
|
|||
}
|
||||
})
|
||||
|
||||
|
||||
self.hass.states.set('sensor.test_state', 'Works')
|
||||
self.hass.pool.block_till_done()
|
||||
state = self.hass.states.get('sensor.test_template_sensor')
|
||||
assert state.state == 'error'
|
||||
|
||||
def test_invalid_name_does_not_create(self):
|
||||
assert sensor.setup(self.hass, {
|
||||
'sensor': {
|
||||
'platform': 'template',
|
||||
'sensors': {
|
||||
'test INVALID sensor': {
|
||||
'value_template':
|
||||
"{{ states.sensor.test_state.state }}"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
assert self.hass.states.all() == []
|
||||
|
||||
def test_invalid_config_does_not_create(self):
|
||||
assert sensor.setup(self.hass, {
|
||||
'sensor': {
|
||||
'platform': 'template',
|
||||
'sensors': {
|
||||
'test_template_sensor': {}
|
||||
}
|
||||
}
|
||||
})
|
||||
assert self.hass.states.all() == []
|
||||
|
||||
def test_missing_template_does_not_create(self):
|
||||
assert sensor.setup(self.hass, {
|
||||
'sensor': {
|
||||
'platform': 'template',
|
||||
'sensors': {
|
||||
'test_template_sensor': {
|
||||
'not_value_template':
|
||||
"{{ states.sensor.test_state.state }}"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
assert self.hass.states.all() == []
|
||||
|
|
Loading…
Reference in New Issue