1
1
import responses
2
2
3
3
from roboflow import API_URL
4
+ from roboflow .adapters .rfapi import ImageUploadError , AnnotationSaveError
4
5
from roboflow .config import DEFAULT_BATCH_NAME
5
- from roboflow .core .exceptions import UploadAnnotationError , UploadImageError
6
6
from tests import PROJECT_NAME , ROBOFLOW_API_KEY , RoboflowTest
7
7
8
8
9
9
class TestProject (RoboflowTest ):
10
10
def test_check_valid_image_with_accepted_formats (self ):
11
- # Mock dataset upload
12
- responses .add (
13
- responses .POST ,
14
- f"{ API_URL } /dataset/{ PROJECT_NAME } /upload?api_key={ ROBOFLOW_API_KEY } " f"&batch={ DEFAULT_BATCH_NAME } " ,
15
- json = {"duplicate" : True , "id" : "hbALkCFdNr9rssgOUXug" },
16
- status = 200 ,
17
- )
18
-
19
11
images_to_test = [
20
12
"rabbit.JPG" ,
21
13
"rabbit2.jpg" ,
@@ -27,14 +19,6 @@ def test_check_valid_image_with_accepted_formats(self):
27
19
self .assertTrue (self .project .check_valid_image (f"tests/images/{ image } " ))
28
20
29
21
def test_check_valid_image_with_unaccepted_formats (self ):
30
- # Mock dataset upload
31
- responses .add (
32
- responses .POST ,
33
- f"{ API_URL } /dataset/{ PROJECT_NAME } /upload?api_key={ ROBOFLOW_API_KEY } " f"&batch={ DEFAULT_BATCH_NAME } " ,
34
- json = {"duplicate" : True , "id" : "hbALkCFdNr9rssgOUXug" },
35
- status = 200 ,
36
- )
37
-
38
22
images_to_test = [
39
23
"sky-rabbit.gif" ,
40
24
"sky-rabbit.heic" ,
@@ -54,13 +38,13 @@ def test_upload_raises_upload_image_error_response_200(self):
54
38
status = 200 ,
55
39
)
56
40
57
- with self .assertRaises (UploadImageError ) as error :
41
+ with self .assertRaises (ImageUploadError ) as error :
58
42
self .project .upload (
59
43
"tests/images/rabbit.JPG" ,
60
44
annotation_path = "tests/annotations/valid_annotation.json" ,
61
45
)
62
46
63
- self .assertEqual (str (error .exception ), "Error uploading image: Invalid Image" )
47
+ self .assertEqual (str (error .exception ), "Invalid Image" )
64
48
65
49
def test_upload_raises_upload_image_error_response_400 (self ):
66
50
responses .add (
@@ -73,13 +57,13 @@ def test_upload_raises_upload_image_error_response_400(self):
73
57
status = 400 ,
74
58
)
75
59
76
- with self .assertRaises (UploadImageError ) as error :
60
+ with self .assertRaises (ImageUploadError ) as error :
77
61
self .project .upload (
78
62
"tests/images/rabbit.JPG" ,
79
63
annotation_path = "tests/annotations/valid_annotation.json" ,
80
64
)
81
65
82
- self .assertEqual (str (error .exception ), "Error uploading image: Invalid Image" )
66
+ self .assertEqual (str (error .exception ), "Invalid Image" )
83
67
84
68
def test_upload_raises_upload_annotation_error (self ):
85
69
image_id = "hbALkCFdNr9rssgOUXug"
@@ -105,10 +89,10 @@ def test_upload_raises_upload_annotation_error(self):
105
89
status = 400 ,
106
90
)
107
91
108
- with self .assertRaises (UploadAnnotationError ) as error :
92
+ with self .assertRaises (AnnotationSaveError ) as error :
109
93
self .project .upload (
110
94
"tests/images/rabbit.JPG" ,
111
95
annotation_path = f"tests/annotations/{ image_name } " ,
112
96
)
113
97
114
- self .assertEqual (str (error .exception ), "Error uploading annotation: Image was already annotated." )
98
+ self .assertEqual (str (error .exception ), "Image was already annotated." )
0 commit comments