From a8e3cf929783ea9798f7f4d8344505b73b4b0b6c Mon Sep 17 00:00:00 2001 From: Raj Laud Date: Mon, 26 Oct 2020 17:58:57 -0500 Subject: [PATCH] Migrate away from asynctest --- tests/test_discovery.py | 4 ++-- tests/test_player.py | 15 +++++---------- tests/test_server.py | 13 ++++++------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 30b78ee..1ce5e9a 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -2,10 +2,10 @@ attempt to cover code that is covered by the live discovery test in test_integration.py.""" import logging +from unittest.mock import AsyncMock, Mock, patch import pysqueezebox import pytest -from asynctest import CoroutineMock, Mock, patch # pylint: disable=C0103 # All test coroutines will be treated as marked. @@ -32,7 +32,7 @@ async def test_bad_response(): async def test_callbacks(): """Test detection and handling of both sync and async callbacks.""" callback = Mock() - async_callback = CoroutineMock() + async_callback = AsyncMock() with patch( "pysqueezebox.discovery._unpack_discovery_response", return_value=RESPONSE diff --git a/tests/test_player.py b/tests/test_player.py index 90e1b5f..df09919 100644 --- a/tests/test_player.py +++ b/tests/test_player.py @@ -1,10 +1,9 @@ """ The following tests check the pysqueezebox.Player module while mocking I/O. """ -from unittest.mock import call, patch +from unittest.mock import AsyncMock, call, patch import pytest -from asynctest import CoroutineMock from pysqueezebox import Player, Server # pylint: disable=C0103 @@ -34,7 +33,7 @@ async def test_image_url(): async def test_wait(): """Test player._wait_for_property().""" - with patch.object(Player, "async_update", CoroutineMock()): + with patch.object(Player, "async_update", AsyncMock()): mock_player = Player(None, "00:11:22:33:44:55", "Test Player") await mock_player._wait_for_property(None, None, 0) mock_player.async_update.assert_not_called() @@ -47,13 +46,9 @@ async def test_wait(): async def test_verified_pause(): """Test player._verified_pause_stop.""" - with patch.object( - Player, "async_query", CoroutineMock(return_val=True) - ), patch.object( - Player, "async_update", CoroutineMock(return_val=True) - ), patch.object( - Player, "mode", "play" - ): + with patch.object(Player, "async_query", AsyncMock(return_val=True)), patch.object( + Player, "async_update", AsyncMock(return_val=True) + ), patch.object(Player, "mode", "play"): mock_player = Player(None, "11:22:33:44:55", "Test Player") assert not await mock_player.async_pause(timeout=0.1) pause_args = ["pause", "1"] diff --git a/tests/test_server.py b/tests/test_server.py index 82f7963..d76a359 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -2,11 +2,10 @@ The following tests check the pysqueezebox.Server module while mocking I/O. """ import asyncio -from unittest.mock import Mock, patch +from unittest.mock import AsyncMock, Mock, patch import pytest from aiohttp import ClientSession -from asynctest import CoroutineMock from pysqueezebox import Server # pylint: disable=C0103 @@ -16,7 +15,7 @@ async def test_get_players(): """Test async_get_players() method.""" - with patch.object(Server, "async_query", CoroutineMock(return_value=False)): + with patch.object(Server, "async_query", AsyncMock(return_value=False)): mock_lms = Server(None, None) await mock_lms.async_get_players() assert await mock_lms.async_get_player() is None @@ -29,18 +28,18 @@ async def test_async_query(): assert await lms.async_query("serverstatus") response = Mock(status="404", text="could not find page") - with patch.object(ClientSession, "post", CoroutineMock(return_value=response)): + with patch.object(ClientSession, "post", AsyncMock(return_value=response)): mock_lms = Server(ClientSession(), None) assert not await mock_lms.async_query("serverstatus") with patch.object( - ClientSession, "post", CoroutineMock(side_effect=asyncio.TimeoutError) + ClientSession, "post", AsyncMock(side_effect=asyncio.TimeoutError) ): mock_lms = Server(ClientSession(), None) assert not await mock_lms.async_query("serverstatus") data = {"bogus_key": "bogus_value"} - response = Mock(status=200, json=CoroutineMock(return_value=data)) - with patch.object(ClientSession, "post", CoroutineMock(return_value=response)): + response = Mock(status=200, json=AsyncMock(return_value=data)) + with patch.object(ClientSession, "post", AsyncMock(return_value=response)): mock_lms = Server(ClientSession(), None) assert not await mock_lms.async_query("serverstatus")