Skip to content

Commit a42ccc7

Browse files
Drew KaulDrew Kaul
authored andcommitted
add tests for Frame class methods
1 parent 82a6cee commit a42ccc7

File tree

4 files changed

+83
-30
lines changed

4 files changed

+83
-30
lines changed

nucleus/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
NUCLEUS_ENDPOINT = "https://api.scale.com/v1/nucleus"
6868
NUM_SENSORS_KEY = "num_sensors"
6969
ORIGINAL_IMAGE_URL_KEY = "original_image_url"
70+
POINTCLOUD_KEY = "pointcloud"
7071
POINTCLOUD_LOCATION_KEY = "pointcloud_location"
7172
POINTCLOUD_URL_KEY = "pointcloud_url"
7273
POSITION_KEY = "position"

nucleus/scene.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def get_item(self, sensor_name: str):
3838
return self.items[sensor_name]
3939

4040
def get_items(self):
41-
return self.items.values()
41+
return list(self.items.values())
4242

4343
def get_sensors(self):
44-
return self.items.keys()
44+
return list(self.items.keys())
4545

4646
def get_index(self):
4747
return self.index

tests/helpers.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
TEST_POINTCLOUD_URLS = [
2626
"https://scaleapi-cust-lidar.s3.us-west-1.amazonaws.com/test-scale/frame-0.json",
27+
"https://scaleapi-cust-lidar.s3.us-west-1.amazonaws.com/test-scale/frame-1.json",
28+
"https://scaleapi-cust-lidar.s3.us-west-1.amazonaws.com/test-scale/frame-2.json",
29+
"https://scaleapi-cust-lidar.s3.us-west-1.amazonaws.com/test-scale/frame-3.json",
30+
"https://scaleapi-cust-lidar.s3.us-west-1.amazonaws.com/test-scale/frame-4.json",
2731
]
2832

2933
TEST_LIDAR_SCENES = {
@@ -56,7 +60,14 @@
5660
}
5761
},
5862
},
59-
}
63+
},
64+
{
65+
"lidar": {
66+
"pointcloud_url": TEST_POINTCLOUD_URLS[0],
67+
"reference_id": "lidar_frame_2",
68+
"metadata": {},
69+
},
70+
},
6071
],
6172
"metadata": {},
6273
},
@@ -71,6 +82,14 @@
7182
DatasetItem(TEST_IMG_URLS[3], "4"),
7283
]
7384

85+
TEST_LIDAR_ITEMS = [
86+
DatasetItem(pointcloud_location=TEST_POINTCLOUD_URLS[0], reference_id="1"),
87+
DatasetItem(pointcloud_location=TEST_POINTCLOUD_URLS[1], reference_id="2"),
88+
DatasetItem(pointcloud_location=TEST_POINTCLOUD_URLS[2], reference_id="3"),
89+
DatasetItem(pointcloud_location=TEST_POINTCLOUD_URLS[3], reference_id="4"),
90+
DatasetItem(pointcloud_location=TEST_POINTCLOUD_URLS[4], reference_id="5"),
91+
]
92+
7493
LOCAL_FILENAME = "tests/test_img.jpg"
7594
TEST_PREDS = [
7695
BoxPrediction("[Pytest Box Prediction 1]", 0, 0, 100, 100, "1"),

tests/test_scene.py

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
ANNOTATIONS_KEY,
44
DATASET_ITEM_ID_KEY,
55
FRAMES_KEY,
6+
IMAGE_KEY,
7+
IMAGE_URL_KEY,
68
ITEM_KEY,
9+
POINTCLOUD_KEY,
10+
POINTCLOUD_URL_KEY,
711
REFERENCE_ID_KEY,
812
SCENES_KEY,
913
UPDATE_KEY,
@@ -12,11 +16,14 @@
1216
from nucleus import (
1317
CuboidAnnotation,
1418
LidarScene,
19+
Frame,
1520
)
1621

1722
from .helpers import (
1823
TEST_DATASET_3D_NAME,
1924
TEST_CUBOID_ANNOTATIONS,
25+
TEST_DATASET_ITEMS,
26+
TEST_LIDAR_ITEMS,
2027
TEST_LIDAR_SCENES,
2128
assert_cuboid_annotation_matches_dict,
2229
)
@@ -31,6 +38,32 @@ def dataset(CLIENT):
3138
assert response == {"message": "Beginning dataset deletion..."}
3239

3340

41+
def test_frame_add_item(dataset):
42+
frame = Frame(index=0)
43+
frame.add_item(TEST_DATASET_ITEMS[0], "camera")
44+
frame.add_item(TEST_LIDAR_ITEMS[0], "lidar")
45+
46+
assert frame.get_index() == 0
47+
assert frame.get_sensors() == ["camera", "lidar"]
48+
for item in frame.get_items():
49+
assert item in [TEST_DATASET_ITEMS[0], TEST_LIDAR_ITEMS[0]]
50+
assert frame.get_item("lidar") == TEST_LIDAR_ITEMS[0]
51+
assert frame.to_payload() == {
52+
"camera": {
53+
"url": TEST_DATASET_ITEMS[0].image_location,
54+
"reference_id": TEST_DATASET_ITEMS[0].reference_id,
55+
"type": IMAGE_KEY,
56+
"metadata": TEST_DATASET_ITEMS[0].metadata or {},
57+
},
58+
"lidar": {
59+
"url": TEST_LIDAR_ITEMS[0].pointcloud_location,
60+
"reference_id": TEST_LIDAR_ITEMS[0].reference_id,
61+
"type": POINTCLOUD_KEY,
62+
"metadata": TEST_LIDAR_ITEMS[0].metadata or {},
63+
},
64+
}
65+
66+
3467
def test_scene_upload_sync(dataset):
3568
payload = TEST_LIDAR_SCENES
3669
scenes = [
@@ -44,33 +77,6 @@ def test_scene_upload_sync(dataset):
4477
assert response["new_scenes"] == len(scenes)
4578

4679

47-
@pytest.mark.integration
48-
def test_scene_upload_async(dataset):
49-
payload = TEST_LIDAR_SCENES
50-
scenes = [
51-
LidarScene.from_json(scene_json) for scene_json in payload[SCENES_KEY]
52-
]
53-
update = payload[UPDATE_KEY]
54-
55-
job = dataset.append(scenes, update=update, asynchronous=True)
56-
job.sleep_until_complete()
57-
status = job.status()
58-
59-
assert status == {
60-
"job_id": job.job_id,
61-
"status": "Completed",
62-
"message": {
63-
"SceneUploadResponse": {
64-
"errors": [],
65-
"dataset_id": dataset.id,
66-
"new_scenes": len(scenes),
67-
"ignored_scenes": 0,
68-
"scenes_errored": 0,
69-
}
70-
},
71-
}
72-
73-
7480
@pytest.mark.integration
7581
def test_scene_and_cuboid_upload_sync(dataset):
7682
payload = TEST_LIDAR_SCENES
@@ -103,3 +109,30 @@ def test_scene_and_cuboid_upload_sync(dataset):
103109
assert_cuboid_annotation_matches_dict(
104110
response_annotations[0], TEST_CUBOID_ANNOTATIONS[0]
105111
)
112+
113+
114+
@pytest.mark.integration
115+
def test_scene_upload_async(dataset):
116+
payload = TEST_LIDAR_SCENES
117+
scenes = [
118+
LidarScene.from_json(scene_json) for scene_json in payload[SCENES_KEY]
119+
]
120+
update = payload[UPDATE_KEY]
121+
122+
job = dataset.append(scenes, update=update, asynchronous=True)
123+
job.sleep_until_complete()
124+
status = job.status()
125+
126+
assert status == {
127+
"job_id": job.job_id,
128+
"status": "Completed",
129+
"message": {
130+
"SceneUploadResponse": {
131+
"errors": [],
132+
"dataset_id": dataset.id,
133+
"new_scenes": len(scenes),
134+
"ignored_scenes": 0,
135+
"scenes_errored": 0,
136+
}
137+
},
138+
}

0 commit comments

Comments
 (0)