Commit 83e6bbbc by Pradyumna Rahul Committed by GitHub

Adds File existence check to Uploader (#4417)

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>
parent 9719df59
......@@ -212,8 +212,6 @@ class Uploader:
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(
......@@ -226,6 +224,9 @@ class Uploader:
) -> 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(
{
......
......@@ -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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment