Skip to content

Commit

Permalink
adding some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Huff authored and Tim Huff committed Aug 7, 2023
1 parent ecd424a commit c111a7b
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion test/integration/test_groundlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from groundlight.status_codes import is_user_error
from model import ClassificationResult, Detector, ImageQuery, PaginatedDetectorList, PaginatedImageQueryList

from internalapi import InternalApiError

DEFAULT_CONFIDENCE_THRESHOLD = 0.9


Expand Down Expand Up @@ -59,7 +61,6 @@ def fixture_image_query_no(gl: Groundlight, detector: Detector) -> ImageQuery:
iq = gl.submit_image_query(detector=detector.id, image="test/assets/cat.jpeg")
return iq


def test_create_detector(gl: Groundlight):
name = f"Test {datetime.utcnow()}" # Need a unique name
query = "Is there a dog?"
Expand Down Expand Up @@ -410,3 +411,67 @@ def submit_noisy_image(image, label=None):
return

assert False, "The detector performance has not improved after two minutes"

def test_start_inspection(gl: Groundlight):
inspection_id = gl.start_inspection()

assert isinstance(inspection_id, str)
assert 'inspect_' in inspection_id

def test_update_inspection_metadata_successful(gl: Groundlight):
"""Starts an inspection and adds a couple pieces of metadata to it.
This should succeed. If there are any errors, an exception will be raised.
"""
inspection_id = gl.start_inspection()

user_provided_key = 'Inspector'
user_provided_value = 'Bob'
gl.update_inspection_metadata(inspection_id, user_provided_key, user_provided_value)

user_provided_key = 'Engine ID'
user_provided_value = '1234'
gl.update_inspection_metadata(inspection_id, user_provided_key, user_provided_value)

def test_update_inspection_metadata_invalid_inspection_id(gl: Groundlight):
"""Attempt to update metadata for an inspection that doesn't exist.
Should raise an InternalApiError.
"""

# The URCap might submit an empty string if an inspection hasn't started.
# An InternalApiError should be raised in this case.
inspection_id = ''
user_provided_key = 'Operator'
user_provided_value = 'Bob'

with pytest.raises(InternalApiError):
gl.update_inspection_metadata(inspection_id, user_provided_key, user_provided_value)

def test_stop_inspection_pass(gl: Groundlight, detector: Detector):
"""Starts an inspection, submits a query that should pass, stops
the inspection, checks the result.
"""
inspection_id = gl.start_inspection()

_ = gl.submit_image_query(detector=detector,
image="test/assets/dog.jpeg",
inspection_id=inspection_id)

assert gl.stop_inspection(inspection_id) == "PASS"

def test_stop_inspection_fail(gl: Groundlight, detector: Detector):
"""Starts an inspection, submits a query that should fail, stops
the inspection, checks the result.
"""
inspection_id = gl.start_inspection()

_ = gl.submit_image_query(detector=detector,
image="test/assets/cat.jpeg",
inspection_id=inspection_id)

assert gl.stop_inspection(inspection_id) == "FAIL"

def test_stop_inspection_with_invalid_id(gl: Groundlight):
inspection_id = 'some_invalid_inspection_id'

with pytest.raises(InternalApiError):
gl.stop_inspection(inspection_id)

0 comments on commit c111a7b

Please sign in to comment.