1313 raise Exception ("Please set the environment variable SCALE_TEST_API_KEY to run tests." )
1414
1515def make_a_task ():
16- return client .create_task (
17- task_type = 'imageannotation' ,
16+ return client .create_imageannotation_task (
1817 callback_url = "http://www.example.com/callback" ,
1918 instruction = "Draw a box around each baby cow and big cow." ,
2019 attachment_type = "image" ,
@@ -29,8 +28,7 @@ def make_a_task():
2928 )
3029
3130def test_categorize_ok ():
32- task = client .create_task (
33- task_type = 'categorization' ,
31+ task = client .create_categorization_task (
3432 callback_url = 'http://www.example.com/callback' ,
3533 instruction = 'Is this company public or private?' ,
3634 attachment_type = 'website' ,
@@ -39,14 +37,12 @@ def test_categorize_ok():
3937
4038def test_categorize_fail ():
4139 with pytest .raises (scaleapi .ScaleInvalidRequest ):
42- client .create_task (
43- task_type = 'categorization' ,
40+ client .create_categorization_task (
4441 callback_url = 'http://www.example.com/callback' ,
4542 categories = ['public' , 'private' ])
4643
4744def test_transcription_ok ():
48- task = client .create_task (
49- task_type = 'categorization' ,
45+ task = client .create_transcription_task (
5046 callback_url = 'http://www.example.com/callback' ,
5147 instruction = 'Transcribe the given fields. Then for each news item on the page, transcribe the information for the row.' ,
5248 attachment_type = 'website' ,
@@ -62,14 +58,12 @@ def test_transcription_ok():
6258
6359def test_transcription_fail ():
6460 with pytest .raises (scaleapi .ScaleInvalidRequest ):
65- client .create_task (
66- task_type = 'transcription' ,
61+ client .create_transcription_task (
6762 callback_url = 'http://www.example.com/callback' ,
6863 attachment_type = 'website' )
6964
7065def test_imageannotation_ok ():
71- client .create_task (
72- task_type = 'imageannotation' ,
66+ client .create_imageannotation_task (
7367 callback_url = "http://www.example.com/callback" ,
7468 instruction = "Draw a box around each baby cow and big cow." ,
7569 attachment_type = "image" ,
@@ -82,29 +76,123 @@ def test_imageannotation_ok():
8276 }
8377 }
8478 )
85- # min_width and min_height should be optional
86- task2 = client .create_task (
87- task_type = 'imageannotation' ,
79+
80+ def test_imageannotation_fail ():
81+ with pytest .raises (scaleapi .ScaleInvalidRequest ):
82+ client .create_imageannotation_task (
83+ callback_url = 'http://www.example.com/callback' ,
84+ instruction = 'Draw a box around each **baby cow** and **big cow**' ,
85+ attachment_type = 'image' )
86+
87+ def test_documenttranscription_ok ():
88+ client .create_documenttranscription_task (
89+ callback_url = 'http://www.example.com/callback' ,
90+ instruction = 'Please transcribe this receipt.' ,
91+ attachment = 'http://document.scale.com/receipt-20200519.jpg' ,
92+ features = [
93+ {
94+ 'type' : "block" ,
95+ 'label' : "barcode" ,
96+ }
97+ ]
98+ )
99+
100+ def test_documenttranscription_fail ():
101+ with pytest .raises (scaleapi .ScaleInvalidRequest ):
102+ client .create_imageannotation_task (
103+ callback_url = 'http://www.example.com/callback' ,
104+ instruction = 'Please transcribe this receipt.' ,
105+ )
106+
107+ def test_annotation_ok ():
108+ task = client .create_annotation_task (
88109 callback_url = 'http://www.example.com/callback' ,
89110 instruction = 'Draw a box around each **baby cow** and **big cow**' ,
90111 attachment_type = 'image' ,
91112 attachment = 'http://i.imgur.com/v4cBreD.jpg' ,
92- geometries = {
93- "box" : {
94- "objects_to_annotate" : ["Baby Cow" , "Big Cow" ],
95- "min_height" : 10 ,
96- "min_width" : 10
97- }
98- })
113+ min_width = '30' ,
114+ min_height = '30' ,
115+ objects_to_annotate = ['baby cow' , 'big cow' ],
116+ with_labels = True )
99117
100- def test_imageannotation_fail ():
118+ def test_annotation_fail ():
101119 with pytest .raises (scaleapi .ScaleInvalidRequest ):
102- client .create_task (
103- task_type = 'imageannotation' ,
120+ client .create_annotation_task (
104121 callback_url = 'http://www.example.com/callback' ,
105122 instruction = 'Draw a box around each **baby cow** and **big cow**' ,
106123 attachment_type = 'image' )
107124
125+ def test_polygonannotation_ok ():
126+ task = client .create_polygonannotation_task (
127+ callback_url = 'http://www.example.com/callback' ,
128+ instruction = 'Draw a tight shape around the big cow' ,
129+ attachment_type = 'image' ,
130+ attachment = 'http://i.imgur.com/v4cBreD.jpg' ,
131+ objects_to_annotate = ['big cow' ],
132+ with_labels = True )
133+
134+ def test_polygonannotation_fail ():
135+ with pytest .raises (scaleapi .ScaleInvalidRequest ):
136+ client .create_polygonannotation_task (
137+ callback_url = 'http://www.example.com/callback' ,
138+ instruction = 'Draw a tight shape around the big cow' ,
139+ attachment_type = 'image' )
140+
141+ def test_lineannotation_ok ():
142+ task = client .create_lineannotation_task (
143+ callback_url = 'http://www.example.com/callback' ,
144+ instruction = 'Draw a tight shape around the big cow' ,
145+ attachment_type = 'image' ,
146+ attachment = 'http://i.imgur.com/v4cBreD.jpg' ,
147+ objects_to_annotate = ['big cow' ],
148+ with_labels = True )
149+
150+ def test_lineannotation_fail ():
151+ with pytest .raises (scaleapi .ScaleInvalidRequest ):
152+ client .create_lineannotation_task (
153+ callback_url = 'http://www.example.com/callback' ,
154+ instruction = 'Draw a tight shape around the big cow' ,
155+ attachment_type = 'image' )
156+
157+ def test_datacollection_ok ():
158+ task = client .create_datacollection_task (
159+ callback_url = 'http://www.example.com/callback' ,
160+ instruction = 'Find the URL for the hiring page for the company with attached website.' ,
161+ attachment_type = 'website' ,
162+ attachment = 'http://www.google.com/' ,
163+ fields = { 'hiring_page' : 'Hiring Page URL' })
164+
165+ def test_datacollection_fail ():
166+ with pytest .raises (scaleapi .ScaleInvalidRequest ):
167+ client .create_datacollection_task (
168+ callback_url = 'http://www.example.com/callback' ,
169+ attachment_type = 'website' )
170+
171+ def test_audiotranscription_ok ():
172+ task = client .create_audiotranscription_task (
173+ callback_url = 'http://www.example.com/callback' ,
174+ attachment_type = 'audio' ,
175+ attachment = 'https://storage.googleapis.com/deepmind-media/pixie/knowing-what-to-say/second-list/speaker-3.wav' ,
176+ verbatim = False ,
177+ phrases = ['avocado' , 'stone' ]
178+ )
179+
180+ def test_audiotranscription_fail ():
181+ with pytest .raises (scaleapi .ScaleInvalidRequest ):
182+ client .create_audiotranscription_task (
183+ callback_url = 'http://www.example.com/callback' ,
184+ attachment_type = 'audio' )
185+
186+ def test_namedentityrecognition_ok ():
187+ return client .create_namedentityrecognition_task (
188+ callback_url = 'http://www.example.com/callback' ,
189+ instruction = 'Do the objects in these images have the same pattern?' ,
190+ text = 'Example text to label with NER tool' ,
191+ labels = [{
192+ 'name' : 'Label_A' ,
193+ 'description' : 'the first label' ,
194+ }])
195+
108196def test_cancel ():
109197 task = make_a_task ()
110198 # raises a scaleexception, because test tasks complete instantly
@@ -169,5 +257,3 @@ def get_batch_status():
169257def get_batch ():
170258 batch = create_a_batch ()
171259 client .get_batch (batch .name )
172-
173- def
0 commit comments