diff options
Diffstat (limited to 'tests/test_wikiget_cli.py')
| -rw-r--r-- | tests/test_wikiget_cli.py | 87 |
1 files changed, 49 insertions, 38 deletions
diff --git a/tests/test_wikiget_cli.py b/tests/test_wikiget_cli.py index 99d113e..0306579 100644 --- a/tests/test_wikiget_cli.py +++ b/tests/test_wikiget_cli.py @@ -23,47 +23,58 @@ from wikiget import USER_AGENT, __version__ from wikiget.wikiget import cli -def test_cli_no_params(monkeypatch: pytest.MonkeyPatch): - monkeypatch.setattr("sys.argv", ["wikiget"]) - with pytest.raises(SystemExit) as e: - cli() - assert e.value.code == 2 +class TestCli: + def test_cli_no_params(self, monkeypatch: pytest.MonkeyPatch) -> None: + with monkeypatch.context() as m: + m.setattr("sys.argv", ["wikiget"]) + with pytest.raises(SystemExit) as e: + cli() + assert e.value.code == 2 + @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 -@patch("wikiget.wikiget.process_download") -def test_cli_completed_successfully( - mock_process_download: MagicMock, monkeypatch: pytest.MonkeyPatch -) -> None: - monkeypatch.setattr("sys.argv", ["wikiget", "File:Example.jpg"]) - mock_process_download.return_value = 0 - with pytest.raises(SystemExit) as e: - cli() - assert mock_process_download.called - assert e.value.code == 0 + with monkeypatch.context() as m: + m.setattr("sys.argv", ["wikiget", "File:Example.jpg"]) + with pytest.raises(SystemExit) as e: + cli() + assert e.value.code == 0 -@patch("wikiget.wikiget.process_download") -def test_cli_completed_with_problems( - mock_process_download: MagicMock, monkeypatch: pytest.MonkeyPatch -) -> None: - monkeypatch.setattr("sys.argv", ["wikiget", "File:Example.jpg"]) - mock_process_download.return_value = 1 - with pytest.raises(SystemExit) as e: - cli() - assert mock_process_download.called - assert e.value.code == 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"]) -@patch("wikiget.wikiget.process_download") -def test_cli_logs( - mock_process_download: MagicMock, - monkeypatch: pytest.MonkeyPatch, - caplog: pytest.LogCaptureFixture, -) -> None: - monkeypatch.setattr("sys.argv", ["wikiget", "File:Example.jpg"]) - mock_process_download.return_value = 0 - with pytest.raises(SystemExit): - cli() - assert mock_process_download.called - assert f"Starting download session using wikiget {__version__}" in caplog.text - assert USER_AGENT in caplog.text + with pytest.raises(SystemExit) as e: + cli() + assert e.value.code == 1 + + @patch("wikiget.wikiget.process_download") + def test_cli_logs( + self, + mock_process_download: MagicMock, + monkeypatch: pytest.MonkeyPatch, + caplog: pytest.LogCaptureFixture, + ) -> 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"]) + + with pytest.raises(SystemExit): + cli() + assert ( + f"Starting download session using wikiget {__version__}" in caplog.text + ) + assert USER_AGENT in caplog.text |
