Skip to content

Commit 3c3f877

Browse files
committed
Add test
1 parent bc42cb6 commit 3c3f877

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

roboflow/core/version.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,8 @@ def __download_zip(self, link, location, format):
818818

819819
def bar_progress(current, total, width=80):
820820
progress_message = (
821-
"Downloading Dataset Version Zip in "
822-
+ location
823-
+ " to "
824-
+ format
825-
+ ": %d%% [%d / %d] bytes" % (current / total * 100, current, total)
821+
f"Downloading Dataset Version Zip in {location} to {format}: "
822+
f"{current / total * 100:.0f}% [{current} / {total}] bytes"
826823
)
827824
sys.stdout.write("\r" + progress_message)
828825
sys.stdout.flush()

roboflow/deployment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def is_valid_ISO8601_timestamp(ts):
1010
try:
1111
datetime.fromisoformat(ts)
1212
return True
13-
except:
13+
except ValueError:
1414
return False
1515

1616

tests/test_project.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import requests
12
import responses
23

34
from roboflow import API_URL
45
from roboflow.adapters.rfapi import AnnotationSaveError, ImageUploadError
56
from roboflow.config import DEFAULT_BATCH_NAME
6-
from tests import PROJECT_NAME, ROBOFLOW_API_KEY, RoboflowTest
7+
from tests import PROJECT_NAME, ROBOFLOW_API_KEY, WORKSPACE_NAME, RoboflowTest
78

89

910
class TestProject(RoboflowTest):
@@ -82,3 +83,64 @@ def test_upload_raises_upload_annotation_error(self):
8283
)
8384

8485
self.assertEqual(str(error.exception), "Image was already annotated.")
86+
87+
def test_image_success(self):
88+
image_id = "test-image-id"
89+
expected_url = f"{API_URL}/{WORKSPACE_NAME}/{PROJECT_NAME}/images/{image_id}?api_key={ROBOFLOW_API_KEY}"
90+
mock_response = {
91+
"image": {
92+
"id": image_id,
93+
"name": "test_image.jpg",
94+
"annotation": {
95+
"key": "some-key",
96+
"width": 640,
97+
"height": 480,
98+
"boxes": [{"label": "person", "x": 100, "y": 150, "width": 50, "height": 80}],
99+
},
100+
"labels": ["person"],
101+
"split": "train",
102+
"tags": ["tag1", "tag2"],
103+
"created": 1616161616,
104+
"urls": {
105+
"original": "https://example.com/image.jpg",
106+
"thumb": "https://example.com/thumb.jpg",
107+
"annotation": "https://example.com/annotation.json",
108+
},
109+
"embedding": [0.1, 0.2, 0.3],
110+
}
111+
}
112+
113+
responses.add(responses.GET, expected_url, json=mock_response, status=200)
114+
115+
image_details = self.project.image(image_id)
116+
117+
self.assertIsInstance(image_details, dict)
118+
self.assertEqual(image_details["id"], image_id)
119+
self.assertEqual(image_details["name"], "test_image.jpg")
120+
self.assertIn("annotation", image_details)
121+
self.assertIn("labels", image_details)
122+
self.assertEqual(image_details["split"], "train")
123+
124+
def test_image_not_found(self):
125+
image_id = "nonexistent-image-id"
126+
expected_url = f"{API_URL}/{WORKSPACE_NAME}/{PROJECT_NAME}/images/{image_id}?api_key={ROBOFLOW_API_KEY}"
127+
mock_response = {"error": "Image not found."}
128+
129+
responses.add(responses.GET, expected_url, json=mock_response, status=404)
130+
131+
with self.assertRaises(RuntimeError) as context:
132+
self.project.image(image_id)
133+
134+
self.assertIn("HTTP error occurred while fetching image details", str(context.exception))
135+
136+
def test_image_invalid_json_response(self):
137+
image_id = "invalid-json-image-id"
138+
expected_url = f"{API_URL}/{WORKSPACE_NAME}/{PROJECT_NAME}/images/{image_id}?api_key={ROBOFLOW_API_KEY}"
139+
invalid_json = "Invalid JSON response"
140+
141+
responses.add(responses.GET, expected_url, body=invalid_json, status=200)
142+
143+
with self.assertRaises(requests.exceptions.JSONDecodeError) as context:
144+
self.project.image(image_id)
145+
146+
self.assertIn("Expecting value", str(context.exception))

0 commit comments

Comments
 (0)