diff options
| author | Cody Logan <cody@lokken.dev> | 2023-11-14 16:44:34 -0800 |
|---|---|---|
| committer | Cody Logan <cody@lokken.dev> | 2023-11-14 16:44:34 -0800 |
| commit | 605085c95fe5ab6af337aefc723794f78cf3dfd7 (patch) | |
| tree | f0dfba6e4fe1fa71a0ba48ecd6f098c66c03f30e /tests/test_dl.py | |
| parent | 733eeb27581ee6fc2a9c2d79d7b002127bde85f1 (diff) | |
| download | wikiget-605085c95fe5ab6af337aefc723794f78cf3dfd7.tar.gz wikiget-605085c95fe5ab6af337aefc723794f78cf3dfd7.zip | |
Use fixtures to create test files
This reduces the number of temporary folders and files created
during testing. Additionally, an actual JPEG is created for a couple
tests instead of using random text for the contents.
Diffstat (limited to 'tests/test_dl.py')
| -rw-r--r-- | tests/test_dl.py | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/tests/test_dl.py b/tests/test_dl.py index d7d5d77..cb5f0b6 100644 --- a/tests/test_dl.py +++ b/tests/test_dl.py @@ -54,15 +54,13 @@ class TestPrepDownload: assert file == expected_file - def test_prep_download_with_existing_file(self, tmp_path: Path) -> None: + def test_prep_download_with_existing_file(self, test_file: Path) -> None: """Test that an exception is raised when the download file already exists. Attempting to download a file with the same destination name as an existing file should raise a FileExistsError. """ - tmp_file = tmp_path / "File:Example.jpg" - tmp_file.write_text("nothing") - args = parse_args(["File:Example.jpg", "-o", str(tmp_file)]) + args = parse_args(["File:Example.jpg", "-o", str(test_file)]) with pytest.raises(FileExistsError): _ = prep_download(args.FILE, args) @@ -301,15 +299,13 @@ class TestDownload: """Define tests related to wikiget.dl.download.""" @pytest.fixture() - def mock_file(self, tmp_path: Path) -> File: + def mock_file(self) -> File: """Create a mock File object to test against. - :param tmp_path: temporary path object - :type tmp_path: Path :return: mock File object :rtype: File """ - file = File(name="Example.jpg", dest=str(tmp_path / "Example.jpg")) + file = File(name="Example.jpg") file.image = Mock() file.image.exists = True file.image.imageinfo = { |
