aboutsummaryrefslogtreecommitdiff
path: root/tests/test_wikiget_cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_wikiget_cli.py')
-rw-r--r--tests/test_wikiget_cli.py45
1 files changed, 26 insertions, 19 deletions
diff --git a/tests/test_wikiget_cli.py b/tests/test_wikiget_cli.py
index 86b3780..0306579 100644
--- a/tests/test_wikiget_cli.py
+++ b/tests/test_wikiget_cli.py
@@ -15,6 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with Wikiget. If not, see <https://www.gnu.org/licenses/>.
+from unittest.mock import MagicMock, patch
+
import pytest
from wikiget import USER_AGENT, __version__
@@ -23,47 +25,52 @@ from wikiget.wikiget import cli
class TestCli:
def test_cli_no_params(self, monkeypatch: pytest.MonkeyPatch) -> None:
- monkeypatch.setattr("sys.argv", ["wikiget"])
- with pytest.raises(SystemExit) as e:
- cli()
- assert e.value.code == 2
+ with monkeypatch.context() as m:
+ m.setattr("sys.argv", ["wikiget"])
+ with pytest.raises(SystemExit) as e:
+ cli()
+ assert e.value.code == 2
- def test_cli_completed_successfully(self, monkeypatch: pytest.MonkeyPatch) -> None:
- def mock_process_download(*args, **kwargs) -> int: # noqa: ARG001
- """A successful call to process_download returns 0."""
- return 0
+ @patch("wikiget.wikiget.process_download")
+ def test_cli_completed_successfully(
+ self, mock_process_download: MagicMock, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ # a successful call to process_download returns 0
+ mock_process_download.return_value = 0
with monkeypatch.context() as m:
m.setattr("sys.argv", ["wikiget", "File:Example.jpg"])
- m.setattr("wikiget.wikiget.process_download", mock_process_download)
with pytest.raises(SystemExit) as e:
cli()
assert e.value.code == 0
- def test_cli_completed_with_problems(self, monkeypatch: pytest.MonkeyPatch) -> None:
- def mock_process_download(*args, **kwargs) -> int: # noqa: ARG001
- """An unsuccessful call to process_download returns 1."""
- return 1
+ @patch("wikiget.wikiget.process_download")
+ def test_cli_completed_with_problems(
+ self, mock_process_download: MagicMock, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ # an unsuccessful call to process_download returns 1
+ mock_process_download.return_value = 1
with monkeypatch.context() as m:
m.setattr("sys.argv", ["wikiget", "File:Example.jpg"])
- m.setattr("wikiget.wikiget.process_download", mock_process_download)
with pytest.raises(SystemExit) as e:
cli()
assert e.value.code == 1
+ @patch("wikiget.wikiget.process_download")
def test_cli_logs(
- self, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
+ self,
+ mock_process_download: MagicMock,
+ monkeypatch: pytest.MonkeyPatch,
+ caplog: pytest.LogCaptureFixture,
) -> None:
- def mock_process_download(*args, **kwargs) -> int: # noqa: ARG001
- """A successful call to process_download returns 0."""
- return 0
+ # a successful call to process_download returns 0
+ mock_process_download.return_value = 0
with monkeypatch.context() as m:
m.setattr("sys.argv", ["wikiget", "File:Example.jpg"])
- m.setattr("wikiget.wikiget.process_download", mock_process_download)
with pytest.raises(SystemExit):
cli()