Skip to content

Commit 085a5ee

Browse files
1nF0rmedneersighted
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. Co-authored-by: Bjorn Neergaard <[email protected]>
1 parent 9719df5 commit 085a5ee

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ def _upload(
212212
skip_existing: bool = False,
213213
) -> None:
214214
for file in self.files:
215-
# TODO: Check existence
216-
217215
self._upload_file(session, url, file, dry_run, skip_existing)
218216

219217
def _upload_file(
@@ -226,6 +224,9 @@ def _upload_file(
226224
) -> None:
227225
from cleo.ui.progress_bar import ProgressBar
228226

227+
if not file.is_file():
228+
raise UploadError(f"Archive ({file}) does not exist")
229+
229230
data = self.post_data(file)
230231
data.update(
231232
{

Diff for: tests/publishing/test_uploader.py

+11
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,14 @@ def test_uploader_skip_existing_bubbles_unskippable_errors(
119119

120120
with pytest.raises(UploadError):
121121
uploader.upload("https://foo.com", skip_existing=True)
122+
123+
124+
def test_uploader_properly_handles_file_not_existing(
125+
mocker: MockerFixture, http: type[httpretty.httpretty], uploader: Uploader
126+
):
127+
mocker.patch("pathlib.Path.is_file", return_value=False)
128+
129+
with pytest.raises(UploadError) as e:
130+
uploader.upload("https://foo.com")
131+
132+
assert f"Archive ({uploader.files[0]}) does not exist" == str(e.value)

0 commit comments

Comments
 (0)