1
1
import pytest
2
2
3
- import nucleus
4
- from nucleus import Dataset
3
+ from pathlib import Path
4
+
5
+ from nucleus import Dataset , DatasetItem , UploadResponse
6
+ from nucleus .constants import (
7
+ NEW_ITEMS ,
8
+ UPDATED_ITEMS ,
9
+ IGNORED_ITEMS ,
10
+ ERROR_ITEMS ,
11
+ ERROR_PAYLOAD ,
12
+ DATASET_ID_KEY ,
13
+ )
5
14
6
15
7
16
TEST_DATASET_NAME = '[PyTest] Test Dataset'
17
+ TEST_IMG_URLS = [
18
+ 's3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/6dd63871-831611a6.jpg' ,
19
+ 's3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/82c1005c-e2d1d94f.jpg' ,
20
+ 's3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/7f2e1814-6591087d.jpg' ,
21
+ 's3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/06924f46-1708b96f.jpg' ,
22
+ 's3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/89b42832-10d662f4.jpg' ,
23
+ ]
8
24
9
25
@pytest .fixture (scope = 'module' )
10
26
def dataset (CLIENT ):
@@ -27,3 +43,43 @@ def test_dataset_create_and_delete(CLIENT):
27
43
# Deletion
28
44
response = CLIENT .delete_dataset (ds .id )
29
45
assert response == {}
46
+
47
+
48
+ def test_dataset_append (dataset ):
49
+ def check_is_expected_response (response ):
50
+ assert isinstance (response , UploadResponse )
51
+ resp_json = response .json ()
52
+ assert resp_json [DATASET_ID_KEY ] == dataset .id
53
+ assert resp_json [NEW_ITEMS ] == len (TEST_IMG_URLS )
54
+ assert resp_json [UPDATED_ITEMS ] == 0
55
+ assert resp_json [IGNORED_ITEMS ] == 0
56
+ assert resp_json [ERROR_ITEMS ] == 0
57
+ assert ERROR_PAYLOAD not in resp_json
58
+
59
+ # Plain image upload
60
+ ds_items_plain = []
61
+ for url in TEST_IMG_URLS :
62
+ ds_items_plain .append (DatasetItem (image_location = url ))
63
+ response = dataset .append (ds_items_plain )
64
+ check_is_expected_response (response )
65
+
66
+ # With reference ids and metadata:
67
+ ds_items_with_metadata = []
68
+ for i , url in enumerate (TEST_IMG_URLS ):
69
+ ds_items_with_metadata .append (DatasetItem (
70
+ image_location = url ,
71
+ reference_id = Path (url ).name ,
72
+ metadata = {
73
+ 'made_with_pytest' : True ,
74
+ 'example_int' : i ,
75
+ 'example_str' : 'hello' ,
76
+ 'example_float' : 0.5 ,
77
+ 'example_dict' : {
78
+ 'nested' : True ,
79
+ },
80
+ 'example_list' : ['hello' , i , False ],
81
+ }
82
+ ))
83
+
84
+ response = dataset .append (ds_items_with_metadata )
85
+ check_is_expected_response (response )
0 commit comments