Skip to content

Commit 875addd

Browse files
author
Leandro Rosemberg
committed
Tests for image upload error, raising a UploadImageError
1 parent be98a44 commit 875addd

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"it is": [
3+
{
4+
"a": 0,
5+
"invalid annotation": true
6+
}
7+
]
8+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"info": {
3+
"year": "2020",
4+
"version": "1",
5+
"description": "None",
6+
"contributor": "Linas",
7+
"url": "https://app.roboflow.ai/datasets/hard-hat-sample/1",
8+
"date_created": "2000-01-01T00:00:00+00:00"
9+
},
10+
"licenses": [{"id": 1, "url": "https://creativecommons.org/publicdomain/zero/1.0/", "name": "Public Domain"}],
11+
"categories": [
12+
{"id": 0, "name": "cat", "supercategory": "animals"}
13+
],
14+
"images": [
15+
{
16+
"id": 0,
17+
"license": 1,
18+
"file_name": "bla.JPG",
19+
"height": 1024,
20+
"width": 1792,
21+
"date_captured": "2020-07-20T19:39:26+00:00"
22+
}
23+
],
24+
"annotations": [
25+
{
26+
"id": 0,
27+
"image_id": 0,
28+
"category_id": 0,
29+
"bbox": [45, 2, 85, 85],
30+
"area": 7225,
31+
"segmentation": [],
32+
"iscrowd": 0
33+
},
34+
{
35+
"id": 1,
36+
"image_id": 0,
37+
"category_id": 0,
38+
"bbox": [324, 29, 72, 81],
39+
"area": 5832,
40+
"segmentation": [],
41+
"iscrowd": 0
42+
}
43+
]
44+
}

tests/test_project.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from roboflow import API_URL
44
from roboflow.config import DEFAULT_BATCH_NAME
5-
from tests import PROJECT_NAME, ROBOFLOW_API_KEY, RoboflowTest
5+
from roboflow.core.exceptions import UploadImageError
6+
from tests import RoboflowTest, PROJECT_NAME, ROBOFLOW_API_KEY
67

78

89
class TestProject(RoboflowTest):
@@ -41,3 +42,23 @@ def test_check_valid_image_with_unaccepted_formats(self):
4142

4243
for image in images_to_test:
4344
self.assertFalse(self.project.check_valid_image(f"tests/images/{image}"))
45+
46+
def test_upload_image_that_already_is_annotated_raises_upload_image_error(self):
47+
responses.add(
48+
responses.POST,
49+
f"{API_URL}/dataset/{PROJECT_NAME}/upload?api_key={ROBOFLOW_API_KEY}" f"&batch={DEFAULT_BATCH_NAME}",
50+
json={
51+
"message": "Image was already annotated.",
52+
"type": "InvalidImageException",
53+
"hint": "This image was already annotated; to overwrite the annotation, pass overwrite=true...",
54+
},
55+
status=200,
56+
)
57+
58+
with self.assertRaises(UploadImageError) as error:
59+
self.project.upload(
60+
"tests/images/rabbit.JPG",
61+
annotation_path="tests/annotations/valid_annotation.json",
62+
)
63+
64+
self.assertEquals(str(error.exception), "Error uploading image: Image was already annotated.")

0 commit comments

Comments
 (0)