Skip to content

Commit

Permalink
Adds File existence check to Uploader (#4417)
Browse files Browse the repository at this point in the history
This handles the TODO for checking the existence of the files being
uploaded by the Uploader class.

https://github.com/python-poetry/poetry/blob/c967a4a5abc6a0edd29c57eca307894f6e1c4f16/poetry/publishing/uploader.py#L229
In the case that a file does not exist, it raises a UploadError.

The raised error message is as follows: `Archive ([FILENAME]) does not exist`

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
  • Loading branch information
1nF0rmed and neersighted committed Sep 18, 2022
1 parent 9719df5 commit 83e6bbb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/poetry/publishing/uploader.py
Expand Up @@ -212,8 +212,6 @@ def _upload(
skip_existing: bool = False,
) -> None:
for file in self.files:
# TODO: Check existence

self._upload_file(session, url, file, dry_run, skip_existing)

def _upload_file(
Expand All @@ -226,6 +224,9 @@ def _upload_file(
) -> None:
from cleo.ui.progress_bar import ProgressBar

if not file.is_file():
raise UploadError(f"Archive ({file}) does not exist")

data = self.post_data(file)
data.update(
{
Expand Down
11 changes: 11 additions & 0 deletions tests/publishing/test_uploader.py
Expand Up @@ -119,3 +119,14 @@ def test_uploader_skip_existing_bubbles_unskippable_errors(

with pytest.raises(UploadError):
uploader.upload("https://foo.com", skip_existing=True)


def test_uploader_properly_handles_file_not_existing(
mocker: MockerFixture, http: type[httpretty.httpretty], uploader: Uploader
):
mocker.patch("pathlib.Path.is_file", return_value=False)

with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")

assert f"Archive ({uploader.files[0]}) does not exist" == str(e.value)

0 comments on commit 83e6bbb

Please sign in to comment.