當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。