1
1
import pytest
2
2
import scaleapi
3
+ import time
4
+ from datetime import datetime
3
5
import os
4
6
5
7
try :
9
11
raise Exception ("Please set the environment variable SCALE_TEST_API_KEY to run tests." )
10
12
11
13
14
+ def make_a_task ():
15
+ return client .create_comparison_task (
16
+ callback_url = 'http://www.example.com/callback' ,
17
+ instruction = 'Do the objects in these images have the same pattern?' ,
18
+ attachment_type = 'image' ,
19
+ attachments = [
20
+ 'http://i.ebayimg.com/00/$T2eC16dHJGwFFZKjy5ZjBRfNyMC4Ig~~_32.JPG' ,
21
+ 'http://images.wisegeek.com/checkered-tablecloth.jpg'
22
+ ],
23
+ choices = ['yes' , 'no' ])
24
+
25
+
12
26
def test_categorize_ok ():
13
27
task = client .create_categorization_task (
14
28
callback_url = 'http://www.example.com/callback' ,
@@ -105,43 +119,37 @@ def test_annotation_fail():
105
119
106
120
107
121
def test_cancel ():
108
- task = client .create_annotation_task (
109
- callback_url = 'http://www.example.com/callback' ,
110
- instruction = 'Draw a box around each **baby cow** and **big cow**' ,
111
- attachment_type = 'image' ,
112
- attachment = 'http://i.imgur.com/v4cBreD.jpg' ,
113
- objects_to_annotate = ['baby cow' , 'big cow' ],
114
- with_labels = True )
115
-
122
+ task = make_a_task ()
116
123
# raises a scaleexception, because test tasks complete instantly
117
124
with pytest .raises (scaleapi .ScaleException ):
118
125
task .cancel ()
119
126
120
127
121
128
def test_task_retrieval ():
122
- task = client .create_annotation_task (
123
- callback_url = 'http://www.example.com/callback' ,
124
- instruction = 'Draw a box around each **baby cow** and **big cow**' ,
125
- attachment_type = 'image' ,
126
- attachment = 'http://i.imgur.com/v4cBreD.jpg' ,
127
- objects_to_annotate = ['baby cow' , 'big cow' ],
128
- with_labels = True )
129
-
129
+ task = make_a_task ()
130
130
task2 = client .fetch_task (task .id )
131
131
assert task .status == 'pending'
132
132
assert task2 .status == 'completed'
133
133
assert task2 .id == task .id
134
134
assert task2 .callback_url == task .callback_url
135
135
assert task2 .instruction == task .instruction
136
136
assert task2 .attachment_type == task .attachment_type
137
- assert task2 .attachment == task .attachment
138
- assert task2 .objects_to_annotate == task .objects_to_annotate
139
- assert task2 .with_labels == task .with_labels
137
+ assert task2 .attachments == task .attachments
138
+ assert task2 .choices == task .choices
140
139
assert task2 .metadata == task .metadata
141
140
assert task2 .type == task .type
142
141
assert task2 .created_at == task .created_at
143
142
144
143
144
+ def test_task_retrieval_time ():
145
+ task = make_a_task ()
146
+ start_time = datetime .utcnow ().isoformat ()
147
+ time .sleep (1 )
148
+ end_time = datetime .utcnow ().isoformat ()
149
+ tasks = client .tasks (start_time = start_time , end_time = end_time )
150
+ assert tasks == []
151
+
152
+
145
153
def test_task_retrieval_fail ():
146
154
with pytest .raises (scaleapi .ScaleException ):
147
155
client .fetch_task ('fake_id_qwertyuiop' )
@@ -150,13 +158,7 @@ def test_task_retrieval_fail():
150
158
def test_tasks ():
151
159
tasks = []
152
160
for i in range (3 ):
153
- tasks .append (client .create_annotation_task (
154
- callback_url = 'http://www.example.com/callback' ,
155
- instruction = 'Draw a box around each **baby cow** and **big cow**' ,
156
- attachment_type = 'image' ,
157
- attachment = 'http://i.imgur.com/v4cBreD.jpg' ,
158
- objects_to_annotate = ['baby cow' , 'big cow' ],
159
- with_labels = True ))
161
+ tasks .append (make_a_task ())
160
162
task_ids = {task .id for task in tasks }
161
163
for task in client .tasks (limit = 3 ):
162
164
assert task .id in task_ids
0 commit comments