Skip to content

Commit d42c74a

Browse files
authored
Merge pull request #21 from robmarkcole/test-scene
Test scene and face objects
2 parents 98eef8b + 98b56ff commit d42c74a

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

tests/test_deepstack.py

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66
MOCK_IP_ADDRESS = "localhost"
77
MOCK_PORT = 5000
8-
MOCK_URL = "http://{}:{}/v1/vision/detection".format(MOCK_IP_ADDRESS, MOCK_PORT)
8+
OBJ_URL = "http://{}:{}/v1/vision/detection".format(MOCK_IP_ADDRESS, MOCK_PORT)
9+
SCENE_URL = "http://{}:{}/v1/vision/scene".format(MOCK_IP_ADDRESS, MOCK_PORT)
10+
FACE_DETECTION_URL = "http://{}:{}/v1/vision/face".format(MOCK_IP_ADDRESS, MOCK_PORT)
11+
12+
CONFIDENCE_THRESHOLD = 0.7
913

1014
MOCK_BYTES = b"Test"
1115
MOCK_API_KEY = "mock_api_key"
1216
MOCK_TIMEOUT = 8
1317

18+
MOCK_SCENE_RESPONSE = {"success": True, "label": "street", "confidence": 0.86745402}
19+
1420
MOCK_OBJECT_DETECTION_RESPONSE = {
1521
"success": True,
1622
"predictions": [
@@ -41,6 +47,10 @@
4147
],
4248
}
4349

50+
MOCK_OBJECT_PREDICTIONS = MOCK_OBJECT_DETECTION_RESPONSE["predictions"]
51+
MOCK_OBJECT_CONFIDENCES = [0.6998661, 0.7996547]
52+
53+
4454
MOCK_FACE_RECOGNITION_RESPONSE = {
4555
"success": True,
4656
"predictions": [
@@ -63,17 +73,28 @@
6373
],
6474
}
6575

66-
MOCK_OBJECT_PREDICTIONS = MOCK_OBJECT_DETECTION_RESPONSE["predictions"]
67-
MOCK_OBJECT_CONFIDENCES = [0.6998661, 0.7996547]
68-
CONFIDENCE_THRESHOLD = 0.7
76+
MOCK_FACE_DETECTION_RESPONSE = {
77+
"success": True,
78+
"predictions": [
79+
{
80+
"confidence": 0.9999999,
81+
"y_min": 173,
82+
"x_min": 203,
83+
"y_max": 834,
84+
"x_max": 667,
85+
}
86+
],
87+
}
88+
89+
6990
MOCK_RECOGNISED_FACES = {"Idris Elba": 75.0}
7091

7192

7293
def test_DeepstackObject_detect():
7394
"""Test a good response from server."""
7495
with requests_mock.Mocker() as mock_req:
7596
mock_req.post(
76-
MOCK_URL, status_code=ds.HTTP_OK, json=MOCK_OBJECT_DETECTION_RESPONSE
97+
OBJ_URL, status_code=ds.HTTP_OK, json=MOCK_OBJECT_DETECTION_RESPONSE
7798
)
7899

79100
dsobject = ds.DeepstackObject(MOCK_IP_ADDRESS, MOCK_PORT)
@@ -85,13 +106,37 @@ def test_DeepstackObject_detect_timeout():
85106
"""Test a timeout. THIS SHOULD FAIL"""
86107
with pytest.raises(ds.DeepstackException) as excinfo:
87108
with requests_mock.Mocker() as mock_req:
88-
mock_req.post(MOCK_URL, exc=requests.exceptions.ConnectTimeout)
109+
mock_req.post(OBJ_URL, exc=requests.exceptions.ConnectTimeout)
89110
dsobject = ds.DeepstackObject(MOCK_IP_ADDRESS, MOCK_PORT)
90111
dsobject.detect(MOCK_BYTES)
91112
assert False
92113
assert "SHOULD FAIL" in str(excinfo.value)
93114

94115

116+
def test_DeepstackScene():
117+
"""Test a good response from server."""
118+
with requests_mock.Mocker() as mock_req:
119+
mock_req.post(SCENE_URL, status_code=ds.HTTP_OK, json=MOCK_SCENE_RESPONSE)
120+
121+
dsscene = ds.DeepstackScene(MOCK_IP_ADDRESS, MOCK_PORT)
122+
dsscene.detect(MOCK_BYTES)
123+
assert dsscene.predictions == MOCK_SCENE_RESPONSE
124+
125+
126+
def test_DeepstackFace():
127+
"""Test a good response from server."""
128+
with requests_mock.Mocker() as mock_req:
129+
mock_req.post(
130+
FACE_DETECTION_URL,
131+
status_code=ds.HTTP_OK,
132+
json=MOCK_FACE_DETECTION_RESPONSE,
133+
)
134+
135+
dsface = ds.DeepstackFace(MOCK_IP_ADDRESS, MOCK_PORT)
136+
dsface.detect(MOCK_BYTES)
137+
assert dsface.predictions == MOCK_FACE_DETECTION_RESPONSE["predictions"]
138+
139+
95140
def test_get_objects():
96141
"""Cant always be sure order of returned list items."""
97142
objects = ds.get_objects(MOCK_OBJECT_PREDICTIONS)

0 commit comments

Comments
 (0)