当前位置: 首页>>代码示例>>Python>>正文


Python MockEntity.update方法代码示例

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


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

示例1: test_raise_error_on_update

# 需要导入模块: from tests.common import MockEntity [as 别名]
# 或者: from tests.common.MockEntity import update [as 别名]
def test_raise_error_on_update(hass):
    """Test the add entity if they raise an error on update."""
    updates = []
    component = EntityComponent(_LOGGER, DOMAIN, hass)
    entity1 = MockEntity(name='test_1')
    entity2 = MockEntity(name='test_2')

    def _raise():
        """Helper to raise an exception."""
        raise AssertionError

    entity1.update = _raise
    entity2.update = lambda: updates.append(1)

    yield from component.async_add_entities([entity1, entity2], True)

    assert len(updates) == 1
    assert 1 in updates
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:20,代码来源:test_entity_platform.py

示例2: test_update_state_adds_entities_with_update_before_add_false

# 需要导入模块: from tests.common import MockEntity [as 别名]
# 或者: from tests.common.MockEntity import update [as 别名]
    def test_update_state_adds_entities_with_update_before_add_false(self):
        """Test if not call update before add to state machine."""
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)

        ent = MockEntity()
        ent.update = Mock(spec_set=True)

        component.add_entities([ent], False)
        self.hass.block_till_done()

        assert 1 == len(self.hass.states.entity_ids())
        assert not ent.update.called
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:14,代码来源:test_entity_platform.py

示例3: test_polling_updates_entities_with_exception

# 需要导入模块: from tests.common import MockEntity [as 别名]
# 或者: from tests.common.MockEntity import update [as 别名]
    def test_polling_updates_entities_with_exception(self):
        """Test the updated entities that not break with an exception."""
        component = EntityComponent(
            _LOGGER, DOMAIN, self.hass, timedelta(seconds=20))

        update_ok = []
        update_err = []

        def update_mock():
            """Mock normal update."""
            update_ok.append(None)

        def update_mock_err():
            """Mock error update."""
            update_err.append(None)
            raise AssertionError("Fake error update")

        ent1 = MockEntity(should_poll=True)
        ent1.update = update_mock_err
        ent2 = MockEntity(should_poll=True)
        ent2.update = update_mock
        ent3 = MockEntity(should_poll=True)
        ent3.update = update_mock
        ent4 = MockEntity(should_poll=True)
        ent4.update = update_mock

        component.add_entities([ent1, ent2, ent3, ent4])

        update_ok.clear()
        update_err.clear()

        fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=20))
        self.hass.block_till_done()

        assert len(update_ok) == 3
        assert len(update_err) == 1
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:38,代码来源:test_entity_platform.py

示例4: test_update_state_adds_entities

# 需要导入模块: from tests.common import MockEntity [as 别名]
# 或者: from tests.common.MockEntity import update [as 别名]
    def test_update_state_adds_entities(self):
        """Test if updating poll entities cause an entity to be added works."""
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)

        ent1 = MockEntity()
        ent2 = MockEntity(should_poll=True)

        component.add_entities([ent2])
        assert 1 == len(self.hass.states.entity_ids())
        ent2.update = lambda *_: component.add_entities([ent1])

        fire_time_changed(
            self.hass, dt_util.utcnow() + DEFAULT_SCAN_INTERVAL
        )
        self.hass.block_till_done()

        assert 2 == len(self.hass.states.entity_ids())
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:19,代码来源:test_entity_platform.py


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