@@ -17,8 +17,19 @@ def test_create_from_url(client, tmp_path, object_predictions,
1717 name = str (uuid .uuid4 ())
1818 file_name = f"{ name } .json"
1919 file_path = tmp_path / file_name
20+
21+ model_run_data_rows = [
22+ mrdr .data_row ().uid
23+ for mrdr in model_run_with_model_run_data_rows .model_run_data_rows ()
24+ ]
25+ predictions = [
26+ p for p in object_predictions
27+ if p ['dataRow' ]['id' ] in model_run_data_rows
28+ ]
2029 with file_path .open ("w" ) as f :
21- ndjson .dump (object_predictions , f )
30+ ndjson .dump (predictions , f )
31+
32+ # Needs to have data row ids
2233
2334 with open (file_path , "r" ) as f :
2435 url = client .upload_data (content = f .read (),
@@ -33,55 +44,74 @@ def test_create_from_url(client, tmp_path, object_predictions,
3344 priority = 5 )
3445
3546 assert annotation_import .model_run_id == model_run_with_model_run_data_rows .uid
36- annotation_import_test_helpers .check_running_state (annotation_import , name ,
37- url )
3847 annotation_import .wait_until_done ()
48+ assert not annotation_import .errors
49+ assert annotation_import .statuses
50+
51+ assert batch
52+ assert batch .project ().uid == configured_project_without_data_rows .uid
53+
54+ assert mal_prediction_import
55+ mal_prediction_import .wait_until_done ()
3956
40- if batch :
41- assert batch .project ().uid == configured_project_without_data_rows .uid
42- if mal_prediction_import :
43- mal_prediction_import .wait_until_done ()
57+ assert not mal_prediction_import .errors
58+ assert mal_prediction_import .statuses
4459
4560
4661def test_create_from_objects (model_run_with_model_run_data_rows ,
4762 configured_project_without_data_rows ,
4863 object_predictions ,
4964 annotation_import_test_helpers ):
5065 name = str (uuid .uuid4 ())
51-
66+ model_run_data_rows = [
67+ mrdr .data_row ().uid
68+ for mrdr in model_run_with_model_run_data_rows .model_run_data_rows ()
69+ ]
70+ predictions = [
71+ p for p in object_predictions
72+ if p ['dataRow' ]['id' ] in model_run_data_rows
73+ ]
5274 annotation_import , batch , mal_prediction_import = model_run_with_model_run_data_rows .upsert_predictions_and_send_to_project (
5375 name = name ,
54- predictions = object_predictions ,
76+ predictions = predictions ,
5577 project_id = configured_project_without_data_rows .uid ,
5678 priority = 5 )
5779
5880 assert annotation_import .model_run_id == model_run_with_model_run_data_rows .uid
59- annotation_import_test_helpers .check_running_state (annotation_import , name )
60- annotation_import_test_helpers .assert_file_content (
61- annotation_import .input_file_url , object_predictions )
6281 annotation_import .wait_until_done ()
82+ assert not annotation_import .errors
83+ assert annotation_import .statuses
6384
64- if batch :
65- assert batch .project ().uid == configured_project_without_data_rows .uid
85+ assert batch
86+ assert batch .project ().uid == configured_project_without_data_rows .uid
6687
67- if mal_prediction_import :
68- annotation_import_test_helpers .check_running_state (
69- mal_prediction_import , name )
70- mal_prediction_import .wait_until_done ()
88+ assert mal_prediction_import
89+ mal_prediction_import .wait_until_done ()
90+
91+ assert not mal_prediction_import .errors
92+ assert mal_prediction_import .statuses
7193
7294
7395def test_create_from_local_file (tmp_path , model_run_with_model_run_data_rows ,
7496 configured_project_without_data_rows ,
7597 object_predictions ,
7698 annotation_import_test_helpers ):
99+
77100 name = str (uuid .uuid4 ())
78101 file_name = f"{ name } .ndjson"
79102 file_path = tmp_path / file_name
80- with file_path .open ("w" ) as f :
81- ndjson .dump (object_predictions , f )
82103
83- annotation_import = model_run_with_model_run_data_rows .add_predictions (
84- name = name , predictions = str (file_path ))
104+ model_run_data_rows = [
105+ mrdr .data_row ().uid
106+ for mrdr in model_run_with_model_run_data_rows .model_run_data_rows ()
107+ ]
108+ predictions = [
109+ p for p in object_predictions
110+ if p ['dataRow' ]['id' ] in model_run_data_rows
111+ ]
112+
113+ with file_path .open ("w" ) as f :
114+ ndjson .dump (predictions , f )
85115
86116 annotation_import , batch , mal_prediction_import = model_run_with_model_run_data_rows .upsert_predictions_and_send_to_project (
87117 name = name ,
@@ -90,42 +120,15 @@ def test_create_from_local_file(tmp_path, model_run_with_model_run_data_rows,
90120 priority = 5 )
91121
92122 assert annotation_import .model_run_id == model_run_with_model_run_data_rows .uid
93- annotation_import_test_helpers .check_running_state (annotation_import , name )
94- annotation_import_test_helpers .assert_file_content (
95- annotation_import .input_file_url , object_predictions )
96123 annotation_import .wait_until_done ()
124+ assert not annotation_import .errors
125+ assert annotation_import .statuses
97126
98- if batch :
99- assert batch .project ().uid == configured_project_without_data_rows .uid
100-
101- if mal_prediction_import :
102- annotation_import_test_helpers .check_running_state (
103- mal_prediction_import , name )
104- mal_prediction_import .wait_until_done ()
127+ assert batch
128+ assert batch .project ().uid == configured_project_without_data_rows .uid
105129
130+ assert mal_prediction_import
131+ mal_prediction_import .wait_until_done ()
106132
107- @pytest .mark .slow
108- def test_wait_till_done (model_run_predictions ,
109- model_run_with_model_run_data_rows ):
110- name = str (uuid .uuid4 ())
111- annotation_import = model_run_with_model_run_data_rows .add_predictions (
112- name = name , predictions = model_run_predictions )
113-
114- assert len (annotation_import .inputs ) == len (model_run_predictions )
115- annotation_import .wait_until_done ()
116- assert annotation_import .state == AnnotationImportState .FINISHED
117- # Check that the status files are being returned as expected
118- assert len (annotation_import .errors ) == 0
119- assert len (annotation_import .inputs ) == len (model_run_predictions )
120- input_uuids = [
121- input_annot ['uuid' ] for input_annot in annotation_import .inputs
122- ]
123- inference_uuids = [pred ['uuid' ] for pred in model_run_predictions ]
124- assert set (input_uuids ) == set (inference_uuids )
125- assert len (annotation_import .statuses ) == len (model_run_predictions )
126- for status in annotation_import .statuses :
127- assert status ['status' ] == 'SUCCESS'
128- status_uuids = [
129- input_annot ['uuid' ] for input_annot in annotation_import .statuses
130- ]
131- assert set (input_uuids ) == set (status_uuids )
133+ assert not mal_prediction_import .errors
134+ assert mal_prediction_import .statuses
0 commit comments