Skip to content

Commit

Permalink
Merge pull request #21 from robmarkcole/test-scene
Browse files Browse the repository at this point in the history
Test scene and face objects
  • Loading branch information
robmarkcole authored May 24, 2020
2 parents 98eef8b + 98b56ff commit d42c74a
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions tests/test_deepstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@

MOCK_IP_ADDRESS = "localhost"
MOCK_PORT = 5000
MOCK_URL = "http://{}:{}/v1/vision/detection".format(MOCK_IP_ADDRESS, MOCK_PORT)
OBJ_URL = "http://{}:{}/v1/vision/detection".format(MOCK_IP_ADDRESS, MOCK_PORT)
SCENE_URL = "http://{}:{}/v1/vision/scene".format(MOCK_IP_ADDRESS, MOCK_PORT)
FACE_DETECTION_URL = "http://{}:{}/v1/vision/face".format(MOCK_IP_ADDRESS, MOCK_PORT)

CONFIDENCE_THRESHOLD = 0.7

MOCK_BYTES = b"Test"
MOCK_API_KEY = "mock_api_key"
MOCK_TIMEOUT = 8

MOCK_SCENE_RESPONSE = {"success": True, "label": "street", "confidence": 0.86745402}

MOCK_OBJECT_DETECTION_RESPONSE = {
"success": True,
"predictions": [
Expand Down Expand Up @@ -41,6 +47,10 @@
],
}

MOCK_OBJECT_PREDICTIONS = MOCK_OBJECT_DETECTION_RESPONSE["predictions"]
MOCK_OBJECT_CONFIDENCES = [0.6998661, 0.7996547]


MOCK_FACE_RECOGNITION_RESPONSE = {
"success": True,
"predictions": [
Expand All @@ -63,17 +73,28 @@
],
}

MOCK_OBJECT_PREDICTIONS = MOCK_OBJECT_DETECTION_RESPONSE["predictions"]
MOCK_OBJECT_CONFIDENCES = [0.6998661, 0.7996547]
CONFIDENCE_THRESHOLD = 0.7
MOCK_FACE_DETECTION_RESPONSE = {
"success": True,
"predictions": [
{
"confidence": 0.9999999,
"y_min": 173,
"x_min": 203,
"y_max": 834,
"x_max": 667,
}
],
}


MOCK_RECOGNISED_FACES = {"Idris Elba": 75.0}


def test_DeepstackObject_detect():
"""Test a good response from server."""
with requests_mock.Mocker() as mock_req:
mock_req.post(
MOCK_URL, status_code=ds.HTTP_OK, json=MOCK_OBJECT_DETECTION_RESPONSE
OBJ_URL, status_code=ds.HTTP_OK, json=MOCK_OBJECT_DETECTION_RESPONSE
)

dsobject = ds.DeepstackObject(MOCK_IP_ADDRESS, MOCK_PORT)
Expand All @@ -85,13 +106,37 @@ def test_DeepstackObject_detect_timeout():
"""Test a timeout. THIS SHOULD FAIL"""
with pytest.raises(ds.DeepstackException) as excinfo:
with requests_mock.Mocker() as mock_req:
mock_req.post(MOCK_URL, exc=requests.exceptions.ConnectTimeout)
mock_req.post(OBJ_URL, exc=requests.exceptions.ConnectTimeout)
dsobject = ds.DeepstackObject(MOCK_IP_ADDRESS, MOCK_PORT)
dsobject.detect(MOCK_BYTES)
assert False
assert "SHOULD FAIL" in str(excinfo.value)


def test_DeepstackScene():
"""Test a good response from server."""
with requests_mock.Mocker() as mock_req:
mock_req.post(SCENE_URL, status_code=ds.HTTP_OK, json=MOCK_SCENE_RESPONSE)

dsscene = ds.DeepstackScene(MOCK_IP_ADDRESS, MOCK_PORT)
dsscene.detect(MOCK_BYTES)
assert dsscene.predictions == MOCK_SCENE_RESPONSE


def test_DeepstackFace():
"""Test a good response from server."""
with requests_mock.Mocker() as mock_req:
mock_req.post(
FACE_DETECTION_URL,
status_code=ds.HTTP_OK,
json=MOCK_FACE_DETECTION_RESPONSE,
)

dsface = ds.DeepstackFace(MOCK_IP_ADDRESS, MOCK_PORT)
dsface.detect(MOCK_BYTES)
assert dsface.predictions == MOCK_FACE_DETECTION_RESPONSE["predictions"]


def test_get_objects():
"""Cant always be sure order of returned list items."""
objects = ds.get_objects(MOCK_OBJECT_PREDICTIONS)
Expand Down

0 comments on commit d42c74a

Please sign in to comment.