From 3d34b09a361dadb50bb4e4ffa18c75928904c30d Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Mon, 6 Nov 2023 12:18:46 -0800 Subject: Simplify mock usage in tests --- tests/test_client.py | 12 +++++------- tests/test_dl.py | 8 +++----- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/test_client.py b/tests/test_client.py index 45739d3..207d9b2 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -16,11 +16,10 @@ # along with Wikiget. If not, see . import logging -from unittest.mock import MagicMock, patch +from unittest.mock import MagicMock, patch, sentinel import pytest -from mwclient import InvalidResponse, Site -from mwclient.image import Image +from mwclient import InvalidResponse from requests import ConnectionError, HTTPError from wikiget import DEFAULT_SITE @@ -113,9 +112,8 @@ class TestQueryApi: # would have created using the MediaWiki API. The Site.images attribute is # normally populated during Site init, but since we're not doing that, a mock # dict is created for query_api to parse. - mock_site = MagicMock(Site) - mock_image = MagicMock(Image) - mock_site.images = {"Example.jpg": mock_image} + mock_site = MagicMock() + mock_site.images = {"Example.jpg": sentinel.mock_image} image = query_api("Example.jpg", mock_site) - assert image == mock_image + assert image == sentinel.mock_image diff --git a/tests/test_dl.py b/tests/test_dl.py index f2a942f..08cf5b4 100644 --- a/tests/test_dl.py +++ b/tests/test_dl.py @@ -16,11 +16,9 @@ # along with Wikiget. If not, see . from pathlib import Path -from unittest.mock import MagicMock, patch +from unittest.mock import MagicMock, Mock, patch import pytest -from mwclient import Site -from mwclient.image import Image from wikiget.dl import prep_download, process_download from wikiget.file import File @@ -34,8 +32,8 @@ class TestPrepDownload: self, mock_connect_to_site: MagicMock, mock_query_api: MagicMock ) -> None: """The prep_download function should create the expected file object.""" - mock_site = MagicMock(Site) - mock_image = MagicMock(Image) + mock_site = Mock() + mock_image = Mock() mock_connect_to_site.return_value = mock_site mock_query_api.return_value = mock_image -- cgit v1.2.3