Skip to content

Commit e6980b8

Browse files
author
Diego Ardila
committed
added error test cases
1 parent 90e47b7 commit e6980b8

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

nucleus/dataset_item.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class DatasetItem:
2121
metadata: Optional[dict] = None
2222

2323
def __post_init__(self):
24-
self.image_url = self.image_location
2524
self.local = is_local_path(self.image_location)
2625

2726
@classmethod
@@ -37,11 +36,11 @@ def from_json(cls, payload: dict):
3736
)
3837

3938
def local_file_exists(self):
40-
return os.path.isfile(self.image_url)
39+
return os.path.isfile(self.image_location)
4140

4241
def to_payload(self) -> dict:
4342
payload = {
44-
IMAGE_URL_KEY: self.image_url,
43+
IMAGE_URL_KEY: self.image_location,
4544
METADATA_KEY: self.metadata or {},
4645
}
4746
if self.reference_id:

nucleus/job.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ def status(self) -> Dict[str, str]:
2020
def errors(self) -> List[str]:
2121
return self.client.make_request(
2222
payload={},
23-
route=f"job/${self.id}/errors",
23+
route=f"job/{self.id}/errors",
2424
requests_command=requests.get,
2525
)
2626

2727
def sleep_until_complete(self, verbose_std_out=True):
2828
while 1:
2929
time.sleep(1)
3030
status = self.status()
31+
if verbose_std_out:
32+
print(status)
3133
if status["status"] == "Running":
32-
if verbose_std_out:
33-
print(status)
3434
continue
3535
break
36+
3637
final_status = status
3738
if final_status["status"] == "Errored":
3839
raise JobError(final_status, self)

tests/test_dataset.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from nucleus.job import JobError
12
import pytest
23
import os
34

@@ -155,6 +156,46 @@ def test_dataset_append_async(dataset: Dataset):
155156
}
156157

157158

159+
def test_dataset_append_async_with_local_path(dataset: Dataset):
160+
ds_items = make_dataset_items()
161+
ds_items[
162+
0
163+
].image_location = "/a/fake/local/path/you/can/tell/is/local/but/is/fake"
164+
with pytest.raises(ValueError):
165+
dataset.append(ds_items, asynchronous=True)
166+
167+
168+
def test_dataset_append_async_with_1_bad_url(dataset: Dataset):
169+
ds_items = make_dataset_items()
170+
ds_items[0].image_location = "https://looks.ok.but.is.not.accessible"
171+
job = dataset.append(ds_items, asynchronous=True)
172+
with pytest.raises(JobError):
173+
job.sleep_until_complete()
174+
assert job.status() == {
175+
"job_id": f"{job.id}",
176+
"status": "Errored",
177+
"message": {
178+
"final_error": (
179+
"One or more of the images you attempted to upload did not process"
180+
" correctly. Please see the status for an overview and the errors for "
181+
"more detailed messages."
182+
),
183+
"image_upload_step": {"errored": 1, "pending": 0, "completed": 4},
184+
"ingest_to_reupload_queue": {
185+
"epoch": 1,
186+
"total": 5,
187+
"datasetId": f"{dataset.id}",
188+
"processed": 5,
189+
},
190+
"started_image_processing": f"Dataset: {dataset.id}, Job: {job.id}",
191+
},
192+
}
193+
assert job.errors() == [
194+
"One or more of the images you attempted to upload did not process correctly. Please see the status for an overview and the errors for more detailed messages.",
195+
'Failure when processing the image "https://looks.ok.but.is.not.accessible": {}',
196+
]
197+
198+
158199
def test_dataset_list_autotags(CLIENT, dataset):
159200
# Creation
160201
# List of Autotags should be empty

0 commit comments

Comments
 (0)