From 088f0663e37bac29d0f5fa4f1261f1e7a211e28a Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Wed, 8 Nov 2023 09:16:57 -0800 Subject: Revise type annotations per PEP 604 --- tests/test_parse.py | 21 +++++++++++---------- tests/test_validations.py | 13 +++++++------ 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/test_parse.py b/tests/test_parse.py index d289d1d..e3bef2d 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -15,10 +15,11 @@ # You should have received a copy of the GNU General Public License # along with Wikiget. If not, see . +from __future__ import annotations + import io import logging from pathlib import Path -from typing import Dict import pytest @@ -93,7 +94,7 @@ class TestGetDest: class TestReadBatchFile: @pytest.fixture() - def dl_dict(self, tmp_path: Path) -> Dict[int, str]: + def dl_dict(self, tmp_path: Path) -> dict[int, str]: """ Create and process a test batch file with three lines, returning a dictionary. """ @@ -114,14 +115,14 @@ class TestReadBatchFile: _ = read_batch_file(str(tmp_file)) assert f"Using file '{tmp_file}' for batch download" in caplog.text - def test_batch_file_length(self, dl_dict: Dict[int, str]) -> None: + def test_batch_file_length(self, dl_dict: dict[int, str]) -> None: """ The processed batch dict should have the same number of items as lines in the batch file. """ assert len(dl_dict) == 3 - def test_batch_file_contents(self, dl_dict: Dict[int, str]) -> None: + def test_batch_file_contents(self, dl_dict: dict[int, str]) -> None: """ The processed batch dict should have the correct line numbers and filenames as keys and values, respectively. @@ -130,7 +131,7 @@ class TestReadBatchFile: assert dl_dict == expected_list @pytest.fixture() - def dl_dict_stdin(self, monkeypatch: pytest.MonkeyPatch) -> Dict[int, str]: + def dl_dict_stdin(self, monkeypatch: pytest.MonkeyPatch) -> dict[int, str]: """ Pass three lines of filenames from stdin to read_batch_file and return a dict. """ @@ -150,14 +151,14 @@ class TestReadBatchFile: _ = read_batch_file("-") assert "Using stdin for batch download" in caplog.text - def test_batch_stdin_length(self, dl_dict_stdin: Dict[int, str]) -> None: + def test_batch_stdin_length(self, dl_dict_stdin: dict[int, str]) -> None: """ The processed batch dict should have the same number of items as lines in the input. """ assert len(dl_dict_stdin) == 3 - def test_batch_stdin_contents(self, dl_dict_stdin: Dict[int, str]) -> None: + def test_batch_stdin_contents(self, dl_dict_stdin: dict[int, str]) -> None: """ The processed batch dict should have the correct line numbers and filenames as keys and values, respectively. @@ -166,7 +167,7 @@ class TestReadBatchFile: assert dl_dict_stdin == expected_list @pytest.fixture() - def dl_dict_with_comment(self, tmp_path: Path) -> Dict[int, str]: + def dl_dict_with_comment(self, tmp_path: Path) -> dict[int, str]: """ Create and process a test batch file with four lines, one of which is commented out and another of which is blank, and return a dictionary. @@ -176,7 +177,7 @@ class TestReadBatchFile: return read_batch_file(str(tmp_file)) def test_batch_file_with_comment_length( - self, dl_dict_with_comment: Dict[int, str] + self, dl_dict_with_comment: dict[int, str] ) -> None: """ The processed batch dict should contain the same number of items as uncommented @@ -185,7 +186,7 @@ class TestReadBatchFile: assert len(dl_dict_with_comment) == 2 def test_batch_file_with_comment_contents( - self, dl_dict_with_comment: Dict[int, str] + self, dl_dict_with_comment: dict[int, str] ) -> None: """ The processed batch dict should have the correct line numbers and filenames as diff --git a/tests/test_validations.py b/tests/test_validations.py index a1c57b5..a8fbf1b 100644 --- a/tests/test_validations.py +++ b/tests/test_validations.py @@ -15,9 +15,10 @@ # You should have received a copy of the GNU General Public License # along with Wikiget. If not, see . +from __future__ import annotations + from pathlib import Path from re import Match -from typing import Optional import pytest @@ -33,7 +34,7 @@ class TestSiteInput: "en.wikimpedia.org", ], ) - def invalid_input(self, request: pytest.FixtureRequest) -> Optional[Match]: + def invalid_input(self, request: pytest.FixtureRequest) -> Match | None: return valid_site(request.param) @pytest.fixture( @@ -44,7 +45,7 @@ class TestSiteInput: "meta.wikimedia.org", ], ) - def valid_input(self, request: pytest.FixtureRequest) -> Optional[Match]: + def valid_input(self, request: pytest.FixtureRequest) -> Match | None: return valid_site(request.param) def test_invalid_site_input(self, invalid_input: None) -> None: @@ -58,7 +59,7 @@ class TestSiteInput: class TestFileRegex: @pytest.fixture() - def file_match(self) -> Optional[Match]: + def file_match(self) -> Match | None: """ File regex should return a match object with match groups corresponding to the file prefix and name. @@ -87,7 +88,7 @@ class TestFileInput: "Fil:Example.jpg", ], ) - def invalid_input(self, request: pytest.FixtureRequest) -> Optional[Match]: + def invalid_input(self, request: pytest.FixtureRequest) -> Match | None: return valid_file(request.param) @pytest.fixture( @@ -100,7 +101,7 @@ class TestFileInput: "File:A (1).jpeg", ], ) - def valid_input(self, request: pytest.FixtureRequest) -> Optional[Match]: + def valid_input(self, request: pytest.FixtureRequest) -> Match | None: return valid_file(request.param) def test_invalid_file_input(self, invalid_input: None) -> None: -- cgit v1.2.3