13
13
raise Exception ("Please set the environment variable SCALE_TEST_API_KEY to run tests." )
14
14
15
15
def make_a_task ():
16
- return client .create_task (
17
- task_type = 'imageannotation' ,
16
+ return client .create_imageannotation_task (
18
17
callback_url = "http://www.example.com/callback" ,
19
18
instruction = "Draw a box around each baby cow and big cow." ,
20
19
attachment_type = "image" ,
@@ -29,8 +28,7 @@ def make_a_task():
29
28
)
30
29
31
30
def test_categorize_ok ():
32
- task = client .create_task (
33
- task_type = 'categorization' ,
31
+ task = client .create_categorization_task (
34
32
callback_url = 'http://www.example.com/callback' ,
35
33
instruction = 'Is this company public or private?' ,
36
34
attachment_type = 'website' ,
@@ -39,14 +37,12 @@ def test_categorize_ok():
39
37
40
38
def test_categorize_fail ():
41
39
with pytest .raises (scaleapi .ScaleInvalidRequest ):
42
- client .create_task (
43
- task_type = 'categorization' ,
40
+ client .create_categorization_task (
44
41
callback_url = 'http://www.example.com/callback' ,
45
42
categories = ['public' , 'private' ])
46
43
47
44
def test_transcription_ok ():
48
- task = client .create_task (
49
- task_type = 'categorization' ,
45
+ task = client .create_transcription_task (
50
46
callback_url = 'http://www.example.com/callback' ,
51
47
instruction = 'Transcribe the given fields. Then for each news item on the page, transcribe the information for the row.' ,
52
48
attachment_type = 'website' ,
@@ -62,14 +58,12 @@ def test_transcription_ok():
62
58
63
59
def test_transcription_fail ():
64
60
with pytest .raises (scaleapi .ScaleInvalidRequest ):
65
- client .create_task (
66
- task_type = 'transcription' ,
61
+ client .create_transcription_task (
67
62
callback_url = 'http://www.example.com/callback' ,
68
63
attachment_type = 'website' )
69
64
70
65
def test_imageannotation_ok ():
71
- client .create_task (
72
- task_type = 'imageannotation' ,
66
+ client .create_imageannotation_task (
73
67
callback_url = "http://www.example.com/callback" ,
74
68
instruction = "Draw a box around each baby cow and big cow." ,
75
69
attachment_type = "image" ,
@@ -82,29 +76,123 @@ def test_imageannotation_ok():
82
76
}
83
77
}
84
78
)
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 (
88
109
callback_url = 'http://www.example.com/callback' ,
89
110
instruction = 'Draw a box around each **baby cow** and **big cow**' ,
90
111
attachment_type = 'image' ,
91
112
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 )
99
117
100
- def test_imageannotation_fail ():
118
+ def test_annotation_fail ():
101
119
with pytest .raises (scaleapi .ScaleInvalidRequest ):
102
- client .create_task (
103
- task_type = 'imageannotation' ,
120
+ client .create_annotation_task (
104
121
callback_url = 'http://www.example.com/callback' ,
105
122
instruction = 'Draw a box around each **baby cow** and **big cow**' ,
106
123
attachment_type = 'image' )
107
124
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
+
108
196
def test_cancel ():
109
197
task = make_a_task ()
110
198
# raises a scaleexception, because test tasks complete instantly
@@ -169,5 +257,3 @@ def get_batch_status():
169
257
def get_batch ():
170
258
batch = create_a_batch ()
171
259
client .get_batch (batch .name )
172
-
173
- def
0 commit comments