Skip to content

Commit 76a18de

Browse files
Pradyumna Rahul1nF0rmed
Pradyumna Rahul
authored andcommitted
Adds File existence check to Uploader
This handles the TODO for checking the existence of the files being uploaded by the Uploader class. In the case that a file does not exist, it raises an UploadError.
1 parent d3bc0eb commit 76a18de

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: src/poetry/publishing/uploader.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ def _upload(
212212
self, session: requests.Session, url: str, dry_run: Optional[bool] = False
213213
) -> None:
214214
for file in self.files:
215-
# TODO: Check existence
215+
if not file.is_file():
216+
raise UploadError(
217+
"Wheel or Tar files associated with the Project Package do not exist"
218+
)
216219

217220
self._upload_file(session, url, file, dry_run)
218221

Diff for: tests/publishing/test_uploader.py

+11
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,14 @@ def test_uploader_registers_for_appropriate_400_errors(mocker, http, uploader):
6060
uploader.upload("https://foo.com")
6161

6262
assert 1 == register.call_count
63+
64+
65+
def test_uploader_properly_handles_file_not_existing(mocker, http, uploader):
66+
mocker.patch("pathlib.Path.is_file", return_value=False)
67+
68+
with pytest.raises(UploadError) as e:
69+
uploader.upload("https://foo.com")
70+
71+
assert "Wheel or Tar files associated with the Project Package do not exist" == str(
72+
e.value
73+
)

0 commit comments

Comments
 (0)