本文整理汇总了Python中tests.common.assert_setup_component函数的典型用法代码示例。如果您正苦于以下问题:Python assert_setup_component函数的具体用法?Python assert_setup_component怎么用?Python assert_setup_component使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_setup_component函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_setup_minimum
def test_setup_minimum(self, mock_req):
"""Test setup with minimum configuration."""
mock_req.get('http://localhost', status_code=200)
self.assertTrue(setup_component(self.hass, 'sensor', {
'sensor': {
'platform': 'rest',
'resource': 'http://localhost'
}
}))
self.assertEqual(2, mock_req.call_count)
assert_setup_component(1, 'switch')
示例2: test_setup_minimum
def test_setup_minimum(self, mock_req):
"""Test setup with minimum configuration."""
resource = '{}{}{}'.format(
'http://', google_wifi.DEFAULT_HOST, google_wifi.ENDPOINT)
mock_req.get(resource, status_code=200)
self.assertTrue(setup_component(self.hass, 'sensor', {
'sensor': {
'platform': 'google_wifi',
'monitored_conditions': ['uptime']
}
}))
assert_setup_component(1, 'sensor')
示例3: test_validate_platform_config_2
def test_validate_platform_config_2(self, caplog):
"""Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA."""
platform_schema = PLATFORM_SCHEMA.extend({
'hello': str,
})
platform_schema_base = PLATFORM_SCHEMA_BASE.extend({
'hello': 'world',
})
loader.set_component(
self.hass,
'platform_conf',
MockModule('platform_conf',
platform_schema=platform_schema,
platform_schema_base=platform_schema_base))
loader.set_component(
self.hass,
'platform_conf.whatever',
MockPlatform('whatever',
platform_schema=platform_schema))
with assert_setup_component(1):
assert setup.setup_component(self.hass, 'platform_conf', {
# fail: no extra keys allowed in platform schema
'platform_conf': {
'platform': 'whatever',
'hello': 'world',
'invalid': 'extra',
}
})
assert caplog.text.count('Your configuration contains '
'extra keys') == 1
self.hass.data.pop(setup.DATA_SETUP)
self.hass.config.components.remove('platform_conf')
with assert_setup_component(1):
assert setup.setup_component(self.hass, 'platform_conf', {
# pass
'platform_conf': {
'platform': 'whatever',
'hello': 'world',
},
# fail: key hello violates component platform_schema_base
'platform_conf 2': {
'platform': 'whatever',
'hello': 'there'
}
})
self.hass.data.pop(setup.DATA_SETUP)
self.hass.config.components.remove('platform_conf')
示例4: test_multi_jails
def test_multi_jails(self):
"""Test that multiple jails can be set up as sensors.."""
config = {
'sensor': {
'platform': 'fail2ban',
'jails': ['jail_one', 'jail_two']
}
}
mock_fh = MockOpen()
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
create=True):
assert setup_component(self.hass, 'sensor', config)
self.hass.block_till_done()
assert_setup_component(2, 'sensor')
示例5: test_setup
def test_setup(self, aioclient_mock):
"""Test setup with valid configuration."""
aioclient_mock.get('http://localhost', status=200)
assert setup_component(self.hass, 'switch', {
'switch': {
'platform': 'rest',
'name': 'foo',
'resource': 'http://localhost',
'body_on': 'custom on text',
'body_off': 'custom off text',
}
})
assert aioclient_mock.call_count == 1
assert_setup_component(1, 'switch')
示例6: test_validate_platform_config_3
def test_validate_platform_config_3(self):
"""Test fallback to component PLATFORM_SCHEMA."""
component_schema = PLATFORM_SCHEMA_BASE.extend({
'hello': str,
})
platform_schema = PLATFORM_SCHEMA.extend({
'cheers': str,
'hello': 'world',
})
loader.set_component(
self.hass,
'platform_conf',
MockModule('platform_conf',
platform_schema=component_schema))
loader.set_component(
self.hass,
'platform_conf.whatever',
MockPlatform('whatever',
platform_schema=platform_schema))
with assert_setup_component(0):
assert setup.setup_component(self.hass, 'platform_conf', {
'platform_conf': {
# fail: no extra keys allowed
'platform': 'whatever',
'hello': 'world',
'invalid': 'extra',
}
})
self.hass.data.pop(setup.DATA_SETUP)
self.hass.config.components.remove('platform_conf')
with assert_setup_component(1):
assert setup.setup_component(self.hass, 'platform_conf', {
# pass
'platform_conf': {
'platform': 'whatever',
'hello': 'world',
},
# fail: key hello violates component platform_schema
'platform_conf 2': {
'platform': 'whatever',
'hello': 'there'
}
})
self.hass.data.pop(setup.DATA_SETUP)
self.hass.config.components.remove('platform_conf')
示例7: test_setup
def test_setup(self, mock_req):
"""Test setup with valid configuration."""
mock_req.get('localhost', status_code=200)
self.assertTrue(setup_component(self.hass, 'switch', {
'switch': {
'platform': 'rest',
'name': 'foo',
'resource': 'http://localhost',
'body_on': 'custom on text',
'body_off': 'custom off text',
}
}))
self.assertEqual(1, mock_req.call_count)
assert_setup_component(1, 'switch')
示例8: test_api_streams
def test_api_streams(hass):
"""Test API streams."""
log = logging.getLogger('homeassistant.components.api')
with assert_setup_component(1):
yield from async_setup_component(hass, 'sensor', {
'sensor': {
'platform': 'api_streams',
}
})
state = hass.states.get('sensor.connected_clients')
assert state.state == '0'
log.debug('STREAM 1 ATTACHED')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '1'
log.debug('STREAM 1 ATTACHED')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '2'
log.debug('STREAM 1 RESPONSE CLOSED')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '1'
示例9: test_template_syntax_error
def test_template_syntax_error(self):
"""Test templating syntax error."""
with assert_setup_component(0, 'switch'):
assert setup.setup_component(self.hass, 'switch', {
'switch': {
'platform': 'template',
'switches': {
'test_template_switch': {
'value_template':
"{% if rubbish %}",
'turn_on': {
'service': 'switch.turn_on',
'entity_id': 'switch.test_state'
},
'turn_off': {
'service': 'switch.turn_off',
'entity_id': 'switch.test_state'
},
}
}
}
})
self.hass.start()
self.hass.block_till_done()
assert self.hass.states.all() == []
示例10: test_reload_config_when_invalid_config
def test_reload_config_when_invalid_config(self, mock_load_yaml):
"""Test the reload config service handling invalid config."""
with assert_setup_component(1):
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'alias': 'hello',
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': {
'service': 'test.automation',
'data_template': {
'event': '{{ trigger.event.event_type }}'
}
}
}
})
assert self.hass.states.get('automation.hello') is not None
self.hass.bus.fire('test_event')
self.hass.block_till_done()
assert len(self.calls) == 1
assert self.calls[0].data.get('event') == 'test_event'
automation.reload(self.hass)
self.hass.block_till_done()
assert self.hass.states.get('automation.hello') is None
self.hass.bus.fire('test_event')
self.hass.block_till_done()
assert len(self.calls) == 1
示例11: test_websocket_api
def test_websocket_api(hass):
"""Test API streams."""
log = logging.getLogger('homeassistant.components.websocket_api')
with assert_setup_component(1):
yield from async_setup_component(hass, 'sensor', {
'sensor': {
'platform': 'api_streams',
}
})
state = hass.states.get('sensor.connected_clients')
assert state.state == '0'
log.debug('WS %s: %s', id(log), 'Connected')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '1'
log.debug('WS %s: %s', id(log), 'Connected')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '2'
log.debug('WS %s: %s', id(log), 'Closed connection')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '1'
示例12: test_update_stale
def test_update_stale(self):
"""Test stalled update."""
scanner = get_component(self.hass, 'device_tracker.test').SCANNER
scanner.reset()
scanner.come_home('DEV1')
register_time = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
scan_time = datetime(2015, 9, 15, 23, 1, tzinfo=dt_util.UTC)
with patch('homeassistant.components.device_tracker.dt_util.utcnow',
return_value=register_time):
with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'test',
device_tracker.CONF_CONSIDER_HOME: 59,
}})
self.hass.block_till_done()
assert STATE_HOME == \
self.hass.states.get('device_tracker.dev1').state
scanner.leave_home('DEV1')
with patch('homeassistant.components.device_tracker.dt_util.utcnow',
return_value=scan_time):
fire_time_changed(self.hass, scan_time)
self.hass.block_till_done()
assert STATE_NOT_HOME == \
self.hass.states.get('device_tracker.dev1').state
示例13: test_new_device_event_fired
def test_new_device_event_fired(self):
"""Test that the device tracker will fire an event."""
with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN,
TEST_PLATFORM)
test_events = []
@callback
def listener(event):
"""Record that our event got called."""
test_events.append(event)
self.hass.bus.listen("device_tracker_new_device", listener)
device_tracker.see(self.hass, 'mac_1', host_name='hello')
device_tracker.see(self.hass, 'mac_1', host_name='hello')
self.hass.block_till_done()
assert len(test_events) == 1
# Assert we can serialize the event
json.dumps(test_events[0].as_dict(), cls=JSONEncoder)
assert test_events[0].data == {
'entity_id': 'device_tracker.hello',
'host_name': 'hello',
'mac': 'MAC_1',
}
示例14: test_template_mutex
def test_template_mutex(self):
"""Test that only value or position template can be used."""
with assert_setup_component(0, 'cover'):
assert setup.setup_component(self.hass, 'cover', {
'cover': {
'platform': 'template',
'covers': {
'test_template_cover': {
'value_template':
"{{ 1 == 1 }}",
'position_template':
"{{ 42 }}",
'open_cover': {
'service': 'cover.open_cover',
'entity_id': 'cover.test_state'
},
'close_cover': {
'service': 'cover.close_cover',
'entity_id': 'cover.test_state'
},
'icon_template':
"{% if states.cover.test_state.state %}"
"mdi:check"
"{% endif %}"
}
}
}
})
self.hass.start()
self.hass.block_till_done()
assert self.hass.states.all() == []
示例15: test_template_state_boolean_on
def test_template_state_boolean_on(self):
"""Test the setting of the state with boolean on."""
with assert_setup_component(1, 'switch'):
assert setup.setup_component(self.hass, 'switch', {
'switch': {
'platform': 'template',
'switches': {
'test_template_switch': {
'value_template':
"{{ 1 == 1 }}",
'turn_on': {
'service': 'switch.turn_on',
'entity_id': 'switch.test_state'
},
'turn_off': {
'service': 'switch.turn_off',
'entity_id': 'switch.test_state'
},
}
}
}
})
self.hass.start()
self.hass.block_till_done()
state = self.hass.states.get('switch.test_template_switch')
assert state.state == STATE_ON