• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python common.assert_setup_component函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.common.assert_setup_component函数的典型用法代码示例。如果您正苦于以下问题:Python assert_setup_component函数的具体用法?Python assert_setup_component怎么用?Python assert_setup_component使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_setup_component函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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')
开发者ID:thejacko12354,项目名称:home-assistant,代码行数:11,代码来源:test_rest.py


示例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')
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:12,代码来源:test_google_wifi.py


示例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')
开发者ID:arsaboo,项目名称:home-assistant,代码行数:52,代码来源:test_setup.py


示例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')
开发者ID:Martwall,项目名称:home-assistant,代码行数:14,代码来源:test_fail2ban.py


示例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')
开发者ID:Teagan42,项目名称:home-assistant,代码行数:14,代码来源:test_rest.py


示例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')
开发者ID:Martwall,项目名称:home-assistant,代码行数:50,代码来源:test_setup.py


示例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')
开发者ID:DavidLP,项目名称:home-assistant,代码行数:14,代码来源:test_rest.py


示例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'
开发者ID:DavidLP,项目名称:home-assistant,代码行数:31,代码来源:test_api_streams.py


示例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() == []
开发者ID:ManHammer,项目名称:home-assistant,代码行数:27,代码来源:test_template.py


示例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
开发者ID:danieljkemp,项目名称:home-assistant,代码行数:34,代码来源:test_init.py


示例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'
开发者ID:DavidLP,项目名称:home-assistant,代码行数:31,代码来源:test_api_streams.py


示例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
开发者ID:ManHammer,项目名称:home-assistant,代码行数:31,代码来源:test_init.py


示例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',
        }
开发者ID:ManHammer,项目名称:home-assistant,代码行数:29,代码来源:test_init.py


示例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() == []
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:33,代码来源:test_template.py


示例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
开发者ID:ManHammer,项目名称:home-assistant,代码行数:28,代码来源:test_template.py


示例16: test_template_tilt

    def test_template_tilt(self):
        """Test the tilt_template attribute."""
        with assert_setup_component(1, 'cover'):
            assert setup.setup_component(self.hass, 'cover', {
                'cover': {
                    'platform': 'template',
                    'covers': {
                        'test_template_cover': {
                            'value_template':
                                "{{ 1 == 1 }}",
                            'tilt_template':
                                "{{ 42 }}",
                            'open_cover': {
                                'service': 'cover.open_cover',
                                'entity_id': 'cover.test_state'
                            },
                            'close_cover': {
                                'service': 'cover.close_cover',
                                'entity_id': 'cover.test_state'
                            },
                        }
                    }
                }
            })

        self.hass.start()
        self.hass.block_till_done()

        state = self.hass.states.get('cover.test_template_cover')
        assert state.attributes.get('current_tilt_position') == 42.0
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:30,代码来源:test_template.py


示例17: test_template_out_of_bounds

    def test_template_out_of_bounds(self):
        """Test template out-of-bounds condition."""
        with assert_setup_component(1, 'cover'):
            assert setup.setup_component(self.hass, 'cover', {
                'cover': {
                    'platform': 'template',
                    'covers': {
                        'test_template_cover': {
                            'position_template':
                                "{{ -1 }}",
                            'tilt_template':
                                "{{ 110 }}",
                            'open_cover': {
                                'service': 'cover.open_cover',
                                'entity_id': 'cover.test_state'
                            },
                            'close_cover': {
                                'service': 'cover.close_cover',
                                'entity_id': 'cover.test_state'
                            },
                        }
                    }
                }
            })

        self.hass.start()
        self.hass.block_till_done()

        state = self.hass.states.get('cover.test_template_cover')
        assert state.attributes.get('current_tilt_position') is None
        assert state.attributes.get('current_position') is None
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:31,代码来源:test_template.py


示例18: test_setup_component

    def test_setup_component(self):
        """Setup ffmpeg component."""
        with assert_setup_component(1, 'binary_sensor'):
            setup_component(self.hass, 'binary_sensor', self.config)

        assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
        assert self.hass.states.get('binary_sensor.ffmpeg_motion') is not None
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:7,代码来源:test_ffmpeg.py


示例19: test_service_say_russian_config

    def test_service_say_russian_config(self, aioclient_mock):
        """Test service call say."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        url_param = {
            'text': 'HomeAssistant',
            'lang': 'ru-RU',
            'key': '1234567xx',
            'speaker': 'zahar',
            'format': 'mp3',
            'emotion': 'neutral',
            'speed': 1
        }
        aioclient_mock.get(
            self._base_url, status=200, content=b'test', params=url_param)

        config = {
            tts.DOMAIN: {
                'platform': 'yandextts',
                'api_key': '1234567xx',
                'language': 'ru-RU',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'yandextts_say', {
            tts.ATTR_MESSAGE: "HomeAssistant",
        })
        self.hass.block_till_done()

        assert len(aioclient_mock.mock_calls) == 1
        assert len(calls) == 1
开发者ID:Teagan42,项目名称:home-assistant,代码行数:34,代码来源:test_yandextts.py


示例20: test_event

    def test_event(self):
        """"Test the event."""
        config = {
            'binary_sensor': {
                'platform': 'template',
                'sensors': {
                    'test': {
                        'friendly_name': 'virtual thingy',
                        'value_template':
                            "{{ states.sensor.test_state.state == 'on' }}",
                        'device_class': 'motion',
                    },
                },
            },
        }
        with assert_setup_component(1):
            assert setup.setup_component(
                self.hass, 'binary_sensor', config)

        self.hass.start()
        self.hass.block_till_done()

        state = self.hass.states.get('binary_sensor.test')
        assert state.state == 'off'

        self.hass.states.set('sensor.test_state', 'on')
        self.hass.block_till_done()

        state = self.hass.states.get('binary_sensor.test')
        assert state.state == 'on'
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:30,代码来源:test_template.py



注:本文中的tests.common.assert_setup_component函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python common.async_fire_mqtt_message函数代码示例发布时间:2022-05-27
下一篇:
Python common.assert_equal函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap