"""Test that we don't make any statistics calls if user hasn't provided preference.""" entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"}) entry.add_to_hass(hass) with patch( "zwave_js_server.model.driver.Driver.async_enable_statistics" ) as mock_cmd1, patch( "zwave_js_server.model.driver.Driver.async_disable_statistics" ) as mock_cmd2: await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() assert not mock_cmd1.called assert not mock_cmd2.called @pytest.mark.parametrize("error", [BaseZwaveJSServerError("Boom"), Exception("Boom")]) async def test_listen_failure(hass, client, error): """Test we handle errors during client listen.""" async def listen(driver_ready): """Mock the client listen method.""" # Set the connect side effect to stop an endless loop on reload. client.connect.side_effect = BaseZwaveJSServerError("Boom") raise error client.listen.side_effect = listen entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"}) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done()
async def listen(driver_ready): """Mock the client listen method.""" # Set the connect side effect to stop an endless loop on reload. client.connect.side_effect = BaseZwaveJSServerError("Boom") raise error
entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"}) entry.add_to_hass(hass) with patch( "zwave_js_server.model.driver.Driver.async_enable_statistics" ) as mock_cmd1, patch( "zwave_js_server.model.driver.Driver.async_disable_statistics" ) as mock_cmd2: await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() assert not mock_cmd1.called assert not mock_cmd2.called @pytest.mark.parametrize("error", [BaseZwaveJSServerError("Boom"), Exception("Boom")]) async def test_listen_failure(hass, client, error): """Test we handle errors during client listen.""" async def listen(driver_ready): """Mock the client listen method.""" # Set the connect side effect to stop an endless loop on reload. client.connect.side_effect = BaseZwaveJSServerError("Boom") raise error client.listen.side_effect = listen entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"}) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done()