Skip to content

Commit 576c02e

Browse files
Drew KaulDrew Kaul
authored andcommitted
add async scene upload test
1 parent c8d6556 commit 576c02e

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

nucleus/scene.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ def to_payload(self) -> dict:
248248
payload[METADATA_KEY] = self.metadata
249249
return payload
250250

251+
def to_json(self) -> str:
252+
return json.dumps(self.to_payload(), allow_nan=False)
253+
251254

252255
@dataclass
253256
class LidarScene(Scene):

nucleus/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def serialize_and_write(
127127
):
128128
for unit in upload_units:
129129
try:
130-
if isinstance(unit, (DatasetItem, Annotation)):
130+
if isinstance(unit, (DatasetItem, Annotation, LidarScene)):
131131
file_pointer.write(unit.to_json() + "\n")
132132
else:
133133
file_pointer.write(json.dumps(unit) + "\n")

tests/test_scene.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ def test_scene_upload_sync(dataset):
3636
assert response["new_scenes"] == len(scenes)
3737

3838

39+
@pytest.mark.integration
40+
def test_scene_upload_async(dataset):
41+
payload = TEST_LIDAR_SCENES
42+
scenes = [
43+
LidarScene.from_json(scene_json) for scene_json in payload[SCENES_KEY]
44+
]
45+
update = payload[UPDATE_KEY]
46+
47+
job = dataset.append(scenes, update=update, asynchronous=True)
48+
job.sleep_until_complete()
49+
status = job.status()
50+
51+
assert status == {
52+
"job_id": job.job_id,
53+
"status": "Completed",
54+
"message": {
55+
"SceneUploadResponse": {
56+
"errors": [],
57+
"dataset_id": dataset.id,
58+
"new_scenes": len(scenes),
59+
"ignored_scenes": 0,
60+
"scenes_errored": 0,
61+
}
62+
},
63+
}
64+
65+
3966
@pytest.mark.integration
4067
def test_scene_and_cuboid_upload_sync(dataset):
4168
payload = TEST_LIDAR_SCENES

0 commit comments

Comments
 (0)