Skip to content

Commit

Permalink
Fix bug when downloading non-local files from a wiki
Browse files Browse the repository at this point in the history
Revert to the pre-v0.6.0 method of checking for file existence.
A change introduced in v0.6.0 caused the check to fail if the file
existed only in a shared repository and not locally on the requested
wiki.
  • Loading branch information
clpo13 committed Nov 16, 2023
1 parent ce58a03 commit 291d4ab
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/wikiget/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def download(f: File, args: Namespace) -> int:
# prepend the current filename to all log messages
adapter = FileLogAdapter(logger, {"filename": filename})

if file.exists:
if file.imageinfo:
# file exists either locally or at a common repository, like Wikimedia Commons
file_url = file.imageinfo["url"]
file_size = file.imageinfo["size"]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ def mock_file(self) -> File:
"""
file = File(name="Example.jpg")
file.image = Mock()
file.image.exists = True
file.image.imageinfo = {
"url": "https://upload.wikimedia.org/wikipedia/commons/a/a9/Example.jpg",
"size": 9022,
Expand Down Expand Up @@ -475,7 +474,7 @@ def test_download_nonexistent_file(
self, mock_file: File, caplog: pytest.LogCaptureFixture
) -> None:
"""Test that a warning message is logged if no file info was returned."""
mock_file.image.exists = False
mock_file.image.imageinfo = {}

args = parse_args(["File:Example.jpg"])
errors = download(mock_file, args)
Expand Down

0 comments on commit 291d4ab

Please sign in to comment.