From ffa111deb9d2d543b1f6d763519c4bdf0706247f Mon Sep 17 00:00:00 2001 From: Ziv <16467659+ziv1234@users.noreply.github.com> Date: Mon, 6 Apr 2020 12:21:52 +0300 Subject: [PATCH] Fix exceptions in tests for samsung_tv (#33732) --- .../components/samsungtv/test_config_flow.py | 3 +++ .../components/samsungtv/test_media_player.py | 17 ++++--------- tests/ignore_uncaught_exceptions.py | 24 ------------------- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index 65807602f09..4e5a02588b1 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -76,6 +76,7 @@ def remote_fixture(): remote_class.return_value = remote socket = mock.Mock() socket_class.return_value = socket + socket_class.gethostbyname.return_value = "FAKE_IP_ADDRESS" yield remote @@ -91,8 +92,10 @@ def remotews_fixture(): remotews.__enter__ = mock.Mock() remotews.__exit__ = mock.Mock() remotews_class.return_value = remotews + remotews_class().__enter__().token = "FAKE_TOKEN" socket = mock.Mock() socket_class.return_value = socket + socket_class.gethostbyname.return_value = "FAKE_IP_ADDRESS" yield remotews diff --git a/tests/components/samsungtv/test_media_player.py b/tests/components/samsungtv/test_media_player.py index b7881d2ddaa..c549e57a06e 100644 --- a/tests/components/samsungtv/test_media_player.py +++ b/tests/components/samsungtv/test_media_player.py @@ -143,6 +143,7 @@ def remotews_fixture(): remote.__enter__ = mock.Mock() remote.__exit__ = mock.Mock() remote_class.return_value = remote + remote_class().__enter__().token = "FAKE_TOKEN" socket1.gethostbyname.return_value = "FAKE_IP_ADDRESS" socket2.gethostbyname.return_value = "FAKE_IP_ADDRESS" yield remote @@ -648,9 +649,7 @@ async def test_play_media(hass, remote): async def test_play_media_invalid_type(hass, remote): """Test for play_media with invalid media type.""" - with patch("homeassistant.components.samsungtv.bridge.Remote") as remote, patch( - "homeassistant.components.samsungtv.config_flow.socket" - ): + with patch("homeassistant.components.samsungtv.bridge.Remote") as remote: url = "https://example.com" await setup_samsungtv(hass, MOCK_CONFIG) remote.reset_mock() @@ -672,9 +671,7 @@ async def test_play_media_invalid_type(hass, remote): async def test_play_media_channel_as_string(hass, remote): """Test for play_media with invalid channel as string.""" - with patch("homeassistant.components.samsungtv.bridge.Remote") as remote, patch( - "homeassistant.components.samsungtv.config_flow.socket" - ): + with patch("homeassistant.components.samsungtv.bridge.Remote") as remote: url = "https://example.com" await setup_samsungtv(hass, MOCK_CONFIG) remote.reset_mock() @@ -696,9 +693,7 @@ async def test_play_media_channel_as_string(hass, remote): async def test_play_media_channel_as_non_positive(hass, remote): """Test for play_media with invalid channel as non positive integer.""" - with patch("homeassistant.components.samsungtv.bridge.Remote") as remote, patch( - "homeassistant.components.samsungtv.config_flow.socket" - ): + with patch("homeassistant.components.samsungtv.bridge.Remote") as remote: await setup_samsungtv(hass, MOCK_CONFIG) remote.reset_mock() assert await hass.services.async_call( @@ -735,9 +730,7 @@ async def test_select_source(hass, remote): async def test_select_source_invalid_source(hass, remote): """Test for select_source with invalid source.""" - with patch("homeassistant.components.samsungtv.bridge.Remote") as remote, patch( - "homeassistant.components.samsungtv.config_flow.socket" - ): + with patch("homeassistant.components.samsungtv.bridge.Remote") as remote: await setup_samsungtv(hass, MOCK_CONFIG) remote.reset_mock() assert await hass.services.async_call( diff --git a/tests/ignore_uncaught_exceptions.py b/tests/ignore_uncaught_exceptions.py index 65ace96917d..64710242132 100644 --- a/tests/ignore_uncaught_exceptions.py +++ b/tests/ignore_uncaught_exceptions.py @@ -44,7 +44,6 @@ IGNORE_UNCAUGHT_EXCEPTIONS = [ ("tests.components.qwikswitch.test_init", "test_binary_sensor_device"), ("tests.components.qwikswitch.test_init", "test_sensor_device"), ("tests.components.rflink.test_init", "test_send_command_invalid_arguments"), - ("tests.components.samsungtv.test_media_player", "test_update_connection_failure"), ("tests.components.unifi_direct.test_device_tracker", "test_get_scanner"), ] @@ -59,29 +58,6 @@ IGNORE_UNCAUGHT_JSON_EXCEPTIONS = [ "tests.components.smartthings.test_init", "test_config_entry_loads_unconnected_cloud", ), - ("tests.components.samsungtv.test_config_flow", "test_ssdp"), - ("tests.components.samsungtv.test_config_flow", "test_user_websocket"), - ("tests.components.samsungtv.test_config_flow", "test_user_already_configured"), - ("tests.components.samsungtv.test_config_flow", "test_autodetect_websocket"), - ("tests.components.samsungtv.test_config_flow", "test_autodetect_websocket_ssl"), - ("tests.components.samsungtv.test_config_flow", "test_ssdp_already_configured"), - ("tests.components.samsungtv.test_config_flow", "test_ssdp_noprefix"), - ("tests.components.samsungtv.test_config_flow", "test_user_legacy"), - ("tests.components.samsungtv.test_config_flow", "test_autodetect_legacy"), - ( - "tests.components.samsungtv.test_media_player", - "test_select_source_invalid_source", - ), - ( - "tests.components.samsungtv.test_media_player", - "test_play_media_channel_as_string", - ), - ( - "tests.components.samsungtv.test_media_player", - "test_play_media_channel_as_non_positive", - ), - ("tests.components.samsungtv.test_media_player", "test_turn_off_websocket"), - ("tests.components.samsungtv.test_media_player", "test_play_media_invalid_type"), ("tests.components.harmony.test_config_flow", "test_form_import"), ("tests.components.harmony.test_config_flow", "test_form_ssdp"), ("tests.components.harmony.test_config_flow", "test_user_form"),