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

Python common.mock_component函数代码示例

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

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



在下文中一共展示了mock_component函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_force_update_enabled

    def test_force_update_enabled(self):
        """Test force update option."""
        mock_component(self.hass, 'mqtt')
        assert setup_component(self.hass, binary_sensor.DOMAIN, {
            binary_sensor.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'test-topic',
                'payload_on': 'ON',
                'payload_off': 'OFF',
                'force_update': True
            }
        })

        events = []

        @ha.callback
        def callback(event):
            """Verify event got called."""
            events.append(event)

        self.hass.bus.listen(EVENT_STATE_CHANGED, callback)

        fire_mqtt_message(self.hass, 'test-topic', 'ON')
        self.hass.block_till_done()
        self.assertEqual(1, len(events))

        fire_mqtt_message(self.hass, 'test-topic', 'ON')
        self.hass.block_till_done()
        self.assertEqual(2, len(events))
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:30,代码来源:test_mqtt.py


示例2: setup_comp

def setup_comp(hass):
    """Initialize components."""
    mock_component(hass, 'zone')
    yaml_devices = hass.config.path(device_tracker.YAML_DEVICES)
    yield
    if os.path.isfile(yaml_devices):
        os.remove(yaml_devices)
开发者ID:Martwall,项目名称:home-assistant,代码行数:7,代码来源:test_unifi_direct.py


示例3: test_caching_data

def test_caching_data(hass):
    """Test that we cache data."""
    mock_component(hass, 'recorder')
    hass.state = CoreState.starting

    states = [
        State('input_boolean.b0', 'on'),
        State('input_boolean.b1', 'on'),
        State('input_boolean.b2', 'on'),
    ]

    with patch('homeassistant.helpers.restore_state.last_recorder_run',
               return_value=MagicMock(end=dt_util.utcnow())), \
            patch('homeassistant.helpers.restore_state.get_states',
                  return_value=states), \
            patch('homeassistant.helpers.restore_state.wait_connection_ready',
                  return_value=mock_coro(True)):
        state = yield from async_get_last_state(hass, 'input_boolean.b1')

    assert DATA_RESTORE_CACHE in hass.data
    assert hass.data[DATA_RESTORE_CACHE] == {st.entity_id: st for st in states}

    assert state is not None
    assert state.entity_id == 'input_boolean.b1'
    assert state.state == 'on'

    hass.bus.async_fire(EVENT_HOMEASSISTANT_START)

    yield from hass.async_block_till_done()

    assert DATA_RESTORE_CACHE not in hass.data
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:31,代码来源:test_restore_state.py


示例4: test_restore_state

def test_restore_state(hass):
    """Test state gets restored."""
    mock_component(hass, 'recorder')
    hass.state = CoreState.starting
    hass.data[DATA_RESTORE_CACHE] = {
        'light.bed_light': State('light.bed_light', 'on', {
            'brightness': 'value-brightness',
            'color_temp': 'value-color_temp',
            'rgb_color': 'value-rgb_color',
            'xy_color': 'value-xy_color',
            'white_value': 'value-white_value',
            'effect': 'value-effect',
        }),
    }

    yield from async_setup_component(hass, 'light', {
        'light': {
            'platform': 'demo',
        }})

    state = hass.states.get('light.bed_light')
    assert state is not None
    assert state.entity_id == 'light.bed_light'
    assert state.state == 'on'
    assert state.attributes.get('brightness') == 'value-brightness'
    assert state.attributes.get('color_temp') == 'value-color_temp'
    assert state.attributes.get('rgb_color') == 'value-rgb_color'
    assert state.attributes.get('xy_color') == 'value-xy_color'
    assert state.attributes.get('white_value') == 'value-white_value'
    assert state.attributes.get('effect') == 'value-effect'
开发者ID:tedstriker,项目名称:home-assistant,代码行数:30,代码来源:test_demo.py


示例5: setup_method

    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        mock_component(self.hass, 'zone')
        mock_component(self.hass, 'group')

        self.host = "127.0.0.1"
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:7,代码来源:test_upc_connect.py


示例6: test_restore_state

def test_restore_state(hass):
    """Ensure states are restored on startup."""
    hass.data[DATA_RESTORE_CACHE] = {
        'binary_sensor.test': State('binary_sensor.test', 'on'),
    }

    hass.state = CoreState.starting
    mock_component(hass, 'recorder')

    config = {
        'binary_sensor': {
            'platform': 'template',
            'sensors': {
                'test': {
                    'friendly_name': 'virtual thingy',
                    'value_template':
                        "{{ states.sensor.test_state.state == 'on' }}",
                    'device_class': 'motion',
                },
            },
        },
    }
    yield from setup.async_setup_component(hass, 'binary_sensor', config)

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

    yield from hass.async_start()
    yield from hass.async_block_till_done()

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


示例7: test_force_update_enabled

    def test_force_update_enabled(self):
        """Test force update option."""
        mock_component(self.hass, 'mqtt')
        assert setup_component(self.hass, sensor.DOMAIN, {
            sensor.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'test-topic',
                'unit_of_measurement': 'fav unit',
                'force_update': True
            }
        })

        events = []

        @ha.callback
        def callback(event):
            events.append(event)

        self.hass.bus.listen(EVENT_STATE_CHANGED, callback)

        fire_mqtt_message(self.hass, 'test-topic', '100')
        self.hass.block_till_done()
        self.assertEqual(1, len(events))

        fire_mqtt_message(self.hass, 'test-topic', '100')
        self.hass.block_till_done()
        self.assertEqual(2, len(events))
开发者ID:tucka,项目名称:home-assistant,代码行数:28,代码来源:test_mqtt.py


示例8: test_restore_state

def test_restore_state(hass):
    """Ensure states are restored on startup."""
    hass.data[DATA_RESTORE_CACHE] = {
        'input_slider.b1': State('input_slider.b1', '70'),
        'input_slider.b2': State('input_slider.b2', '200'),
    }

    hass.state = CoreState.starting
    mock_component(hass, 'recorder')

    yield from async_setup_component(hass, DOMAIN, {
        DOMAIN: {
            'b1': {
                'initial': 50,
                'min': 0,
                'max': 100,
            },
            'b2': {
                'initial': 60,
                'min': 0,
                'max': 100,
            },
        }})

    state = hass.states.get('input_slider.b1')
    assert state
    assert float(state.state) == 70

    state = hass.states.get('input_slider.b2')
    assert state
    assert float(state.state) == 60
开发者ID:nunofgs,项目名称:home-assistant,代码行数:31,代码来源:test_input_slider.py


示例9: setup_comp

def setup_comp(hass):
    """Initialize components."""
    mock_component(hass, 'group')
    hass.loop.run_until_complete(async_setup_component(hass, zone.DOMAIN, {
            'zone': {
                'name': 'test',
                'latitude': 32.880837,
                'longitude': -117.237561,
                'radius': 250,
            }
        }))
开发者ID:boced66,项目名称:home-assistant,代码行数:11,代码来源:test_geo_location.py


示例10: test_receive_mqtt_temperature

    def test_receive_mqtt_temperature(self):
        """Test getting the current temperature via MQTT."""
        config = copy.deepcopy(DEFAULT_CONFIG)
        config['climate']['current_temperature_topic'] = 'current_temperature'
        mock_component(self.hass, 'mqtt')
        assert setup_component(self.hass, climate.DOMAIN, config)

        fire_mqtt_message(self.hass, 'current_temperature', '47')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert 47 == state.attributes.get('current_temperature')
开发者ID:ManHammer,项目名称:home-assistant,代码行数:11,代码来源:test_mqtt.py


示例11: setUp

    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        mock_component(self.hass, 'group')
        self.calls = []

        @callback
        def record_call(service):
            """Helper to record calls."""
            self.calls.append(service)

        self.hass.services.register('test', 'automation', record_call)
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:12,代码来源:test_numeric_state.py


示例12: mock_client

def mock_client(hass, test_client):
    """Start the Hass HTTP component."""
    mock_component(hass, 'group')
    mock_component(hass, 'zone')
    with patch('homeassistant.components.device_tracker.async_load_config',
               return_value=mock_coro([])):
        hass.loop.run_until_complete(
            async_setup_component(hass, 'device_tracker', {
                'device_tracker': {
                    'platform': 'owntracks_http'
                }
            }))
    return hass.loop.run_until_complete(test_client(hass.http.app))
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:13,代码来源:test_owntracks_http.py


示例13: test_load_on_demand_already_loaded

def test_load_on_demand_already_loaded(hass, test_client):
    """Test getting suites."""
    mock_component(hass, 'zwave')

    with patch.object(config, 'SECTIONS', []), \
            patch.object(config, 'ON_DEMAND', ['zwave']), \
            patch('homeassistant.components.config.zwave.async_setup') as stp:
        stp.return_value = mock_coro(True)

        yield from async_setup_component(hass, 'config', {})

    yield from hass.async_block_till_done()
    assert 'config.zwave' in hass.config.components
    assert stp.called
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:14,代码来源:test_init.py


示例14: test_not_connected

def test_not_connected(hass):
    """Test that cache cannot be accessed if db connection times out."""
    mock_component(hass, 'recorder')
    hass.state = CoreState.starting

    states = [State('input_boolean.b1', 'on')]

    with patch('homeassistant.helpers.restore_state.last_recorder_run',
               return_value=MagicMock(end=dt_util.utcnow())), \
            patch('homeassistant.helpers.restore_state.get_states',
                  return_value=states), \
            patch('homeassistant.helpers.restore_state.wait_connection_ready',
                  return_value=mock_coro(False)):
        state = yield from async_get_last_state(hass, 'input_boolean.b1')
    assert state is None
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:15,代码来源:test_restore_state.py


示例15: setUp

    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        mock_component(self.hass, 'group')
        setup_component(self.hass, sun.DOMAIN, {
            sun.DOMAIN: {sun.CONF_ELEVATION: 0}})

        self.calls = []

        @callback
        def record_call(service):
            """Call recorder."""
            self.calls.append(service)

        self.hass.services.register('test', 'automation', record_call)
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:15,代码来源:test_sun.py


示例16: test_no_last_run_found

def test_no_last_run_found(hass):
    """Test that cache cannot be accessed if no last run found."""
    mock_component(hass, 'recorder')
    hass.state = CoreState.starting

    states = [State('input_boolean.b1', 'on')]

    with patch('homeassistant.helpers.restore_state.last_recorder_run',
               return_value=None), \
            patch('homeassistant.helpers.restore_state.get_states',
                  return_value=states), \
            patch('homeassistant.helpers.restore_state.wait_connection_ready',
                  return_value=mock_coro(True)):
        state = yield from async_get_last_state(hass, 'input_boolean.b1')
    assert state is None
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:15,代码来源:test_restore_state.py


示例17: setup_method

    def setup_method(self, _):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        mock_mqtt_component(self.hass)
        mock_component(self.hass, 'group')
        mock_component(self.hass, 'zone')

        patcher = patch('homeassistant.components.device_tracker.'
                        'DeviceTracker.async_update_config')
        patcher.start()
        self.addCleanup(patcher.stop)

        orig_context = owntracks.OwnTracksContext

        def store_context(*args):
            self.context = orig_context(*args)
            return self.context

        with patch('homeassistant.components.device_tracker.async_load_config',
                   return_value=mock_coro([])), \
                patch('homeassistant.components.device_tracker.'
                      'load_yaml_config_file', return_value=mock_coro({})), \
                patch.object(owntracks, 'OwnTracksContext', store_context), \
                assert_setup_component(1, device_tracker.DOMAIN):
            assert setup_component(self.hass, device_tracker.DOMAIN, {
                device_tracker.DOMAIN: {
                    CONF_PLATFORM: 'owntracks',
                    CONF_MAX_GPS_ACCURACY: 200,
                    CONF_WAYPOINT_IMPORT: True,
                    CONF_WAYPOINT_WHITELIST: ['jon', 'greg']
                }})

        self.hass.states.set(
            'zone.inner', 'zoning', INNER_ZONE)

        self.hass.states.set(
            'zone.inner_2', 'zoning', INNER_ZONE)

        self.hass.states.set(
            'zone.outer', 'zoning', OUTER_ZONE)

        # Clear state between tests
        # NB: state "None" is not a state that is created by Device
        # so when we compare state to None in the tests this
        # is really checking that it is still in its original
        # test case state. See Device.async_update.
        self.hass.states.set(DEVICE_TRACKER_STATE, None)
开发者ID:fabfurnari,项目名称:home-assistant,代码行数:47,代码来源:test_owntracks.py


示例18: setup_method

    def setup_method(self, method):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        mock_mqtt_component(self.hass)
        mock_component(self.hass, 'group')
        mock_component(self.hass, 'zone')

        patch_load = patch(
            'homeassistant.components.device_tracker.async_load_config',
            return_value=mock_coro([]))
        patch_load.start()
        self.addCleanup(patch_load.stop)

        patch_save = patch('homeassistant.components.device_tracker.'
                           'DeviceTracker.async_update_config')
        patch_save.start()
        self.addCleanup(patch_save.stop)
开发者ID:fripsy,项目名称:home-assistant,代码行数:17,代码来源:test_owntracks.py


示例19: test_hass_running

def test_hass_running(hass):
    """Test that cache cannot be accessed while hass is running."""
    mock_component(hass, 'recorder')

    states = [
        State('input_boolean.b0', 'on'),
        State('input_boolean.b1', 'on'),
        State('input_boolean.b2', 'on'),
    ]

    with patch('homeassistant.helpers.restore_state.last_recorder_run',
               return_value=MagicMock(end=dt_util.utcnow())), \
            patch('homeassistant.helpers.restore_state.get_states',
                  return_value=states), \
            patch('homeassistant.helpers.restore_state.wait_connection_ready',
                  return_value=mock_coro(True)):
        state = yield from async_get_last_state(hass, 'input_boolean.b1')
    assert state is None
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:18,代码来源:test_restore_state.py


示例20: test_new_version_shows_entity_after_hour_hassio

def test_new_version_shows_entity_after_hour_hassio(
        hass, mock_get_uuid, mock_get_newest_version):
    """Test if new entity is created if new version is available / hass.io."""
    mock_get_uuid.return_value = MOCK_HUUID
    mock_get_newest_version.return_value = mock_coro((NEW_VERSION, ''))
    mock_component(hass, 'hassio')
    hass.data['hassio_hass_version'] = "999.0"

    res = yield from async_setup_component(
        hass, updater.DOMAIN, {updater.DOMAIN: {}})
    assert res, 'Updater failed to set up'

    with patch('homeassistant.components.updater.current_version',
               MOCK_VERSION):
        async_fire_time_changed(hass, dt_util.utcnow() + timedelta(hours=1))
        yield from hass.async_block_till_done()

    assert hass.states.is_state(updater.ENTITY_ID, "999.0")
开发者ID:Martwall,项目名称:home-assistant,代码行数:18,代码来源:test_init.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python common.mock_coro函数代码示例发布时间:2022-05-27
下一篇:
Python common.load_fixture函数代码示例发布时间: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