Skip to content

Commit e2bd517

Browse files
committed
cleanup, update doc, add time range tests
1 parent a9118a9 commit e2bd517

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ pip install scaleapi
88
## Usage
99
```python
1010
import scale
11-
client = scale.ScaleClient('YOUR_API_KEY_HERE', callback_key='OPTIONAL_CALLBACK_KEY_HERE')
11+
client = scale.ScaleClient('YOUR_API_KEY_HERE')
1212
```
1313

1414
### Tasks
1515

16-
Most of these methods will return a `scale.Task` object, which will contain information
16+
Most of these methods will return a `scaleapi.Task` object, which will contain information
1717
about the json response (task_id, status...).
1818

1919
Any parameter available in the [documentation](https://docs.scaleapi.com) can be passed as an argument
@@ -121,10 +121,15 @@ task = client.cancel_task('asdfasdfasdfasdfasdfasdf')
121121

122122
Check [this](https://docs.scaleapi.com/#list-all-tasks) for further information.
123123

124-
Retrieve a list of all tasks.
124+
Retrieve a list of tasks, with optional filter by date/type. Paginated with limit/offset.
125125

126126
```python
127-
tasks = client.tasks()
127+
tasks = client.tasks(
128+
start_time='2015-10-13T22:38:42Z',
129+
end_time='2016-10-13T22:38:42Z',
130+
type='categorization',
131+
limit=100,
132+
offset=200)
128133
```
129134

130135
## Error handling

tests/test_client.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22
import scaleapi
3+
import time
4+
from datetime import datetime
35
import os
46

57
try:
@@ -9,6 +11,18 @@
911
raise Exception("Please set the environment variable SCALE_TEST_API_KEY to run tests.")
1012

1113

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+
1226
def test_categorize_ok():
1327
task = client.create_categorization_task(
1428
callback_url='http://www.example.com/callback',
@@ -105,43 +119,37 @@ def test_annotation_fail():
105119

106120

107121
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()
116123
# raises a scaleexception, because test tasks complete instantly
117124
with pytest.raises(scaleapi.ScaleException):
118125
task.cancel()
119126

120127

121128
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()
130130
task2 = client.fetch_task(task.id)
131131
assert task.status == 'pending'
132132
assert task2.status == 'completed'
133133
assert task2.id == task.id
134134
assert task2.callback_url == task.callback_url
135135
assert task2.instruction == task.instruction
136136
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
140139
assert task2.metadata == task.metadata
141140
assert task2.type == task.type
142141
assert task2.created_at == task.created_at
143142

144143

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+
145153
def test_task_retrieval_fail():
146154
with pytest.raises(scaleapi.ScaleException):
147155
client.fetch_task('fake_id_qwertyuiop')
@@ -150,13 +158,7 @@ def test_task_retrieval_fail():
150158
def test_tasks():
151159
tasks = []
152160
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())
160162
task_ids = {task.id for task in tasks}
161163
for task in client.tasks(limit=3):
162164
assert task.id in task_ids

0 commit comments

Comments
 (0)