From daf4a17b53ed59ffa4b130ce9bedd4f42ef1bfdb Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Mon, 23 Oct 2023 12:08:08 -0700 Subject: Reorganize tests using fixtures --- tests/test_parse.py | 53 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'tests/test_parse.py') diff --git a/tests/test_parse.py b/tests/test_parse.py index 757b361..a04b30f 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -18,38 +18,51 @@ import pytest from wikiget.exceptions import ParseError +from wikiget.file import File from wikiget.parse import get_dest from wikiget.wikiget import construct_parser class TestGetDest: - parser = construct_parser() + @pytest.fixture(scope="class") + def file_with_filename(self) -> File: + args = construct_parser().parse_args(["File:Example.jpg"]) + return get_dest(args.FILE, args) - def test_get_dest_with_filename(self): - args = self.parser.parse_args(["File:Example.jpg"]) - file = get_dest(args.FILE, args) - assert file.name == "Example.jpg" - assert file.dest == "Example.jpg" - assert file.site == "commons.wikimedia.org" + def test_get_dest_name_with_filename(self, file_with_filename: File) -> None: + assert file_with_filename.name == "Example.jpg" - def test_get_dest_with_url(self): - args = self.parser.parse_args( - [ - "https://en.wikipedia.org/wiki/File:Example.jpg", - ] + def test_get_dest_with_filename(self, file_with_filename: File) -> None: + assert file_with_filename.dest == "Example.jpg" + + def test_get_dest_site_with_filename(self, file_with_filename: File) -> None: + assert file_with_filename.site == "commons.wikimedia.org" + + @pytest.fixture(scope="class") + def file_with_url(self) -> File: + args = construct_parser().parse_args( + ["https://en.wikipedia.org/wiki/File:Example.jpg"] ) - file = get_dest(args.FILE, args) - assert file.name == "Example.jpg" - assert file.dest == "Example.jpg" - assert file.site == "en.wikipedia.org" + return get_dest(args.FILE, args) + + def test_get_dest_name_with_url(self, file_with_url: File) -> None: + assert file_with_url.name == "Example.jpg" + + def test_get_dest_with_url(self, file_with_url: File) -> None: + assert file_with_url.dest == "Example.jpg" + + def test_get_dest_site_with_url(self, file_with_url: File) -> None: + assert file_with_url.site == "en.wikipedia.org" - def test_get_dest_with_bad_filename(self): - args = self.parser.parse_args(["Example.jpg"]) + def test_get_dest_with_bad_filename(self) -> None: + args = construct_parser().parse_args(["Example.jpg"]) with pytest.raises(ParseError): _ = get_dest(args.FILE, args) - def test_get_dest_with_different_site(self, caplog: pytest.LogCaptureFixture): - args = self.parser.parse_args( + def test_get_dest_with_different_site( + self, caplog: pytest.LogCaptureFixture + ) -> None: + args = construct_parser().parse_args( [ "https://commons.wikimedia.org/wiki/File:Example.jpg", "--site", -- cgit v1.2.3