55import random
66import string
77import time
8- from datetime import datetime
98from typing import Any , Dict , Optional , Union
109
1110import pytest
11+ from conftest import generate_test_detector_name
1212from groundlight import Groundlight
1313from groundlight .binary_labels import VALID_DISPLAY_LABELS , Label , convert_internal_label_to_display
1414from groundlight .internalapi import ApiException , InternalApiError , NotFoundError
@@ -97,7 +97,7 @@ def test_create_groundlight_with_retries():
9797
9898
9999def test_create_detector (gl : Groundlight ):
100- name = f"Test { datetime . utcnow () } " # Need a unique name
100+ name = generate_test_detector_name ()
101101 query = "Is there a dog?"
102102 _detector = gl .create_detector (name = name , query = query )
103103 assert str (_detector )
@@ -107,20 +107,20 @@ def test_create_detector(gl: Groundlight):
107107 ), "We expected the default confidence threshold to be used."
108108
109109 # Test creating dectors with other modes
110- name = f"Test { datetime .utcnow ()} " # Need a unique name
111- count_detector = gl .create_detector (name = name , query = query , mode = ModeEnum .COUNT , class_names = "dog" )
110+ count_detector = gl .create_detector (
111+ name = generate_test_detector_name (), query = query , mode = ModeEnum .COUNT , class_names = "dog"
112+ )
112113 assert str (count_detector )
113- name = f"Test { datetime .utcnow ()} " # Need a unique name
114114 multiclass_detector = gl .create_detector (
115- name = name , query = query , mode = ModeEnum .MULTI_CLASS , class_names = ["dog" , "cat" ]
115+ name = generate_test_detector_name () , query = query , mode = ModeEnum .MULTI_CLASS , class_names = ["dog" , "cat" ]
116116 )
117117 assert str (multiclass_detector )
118118
119119
120120def test_create_detector_with_pipeline_config (gl : Groundlight ):
121121 # "never-review" is a special model that always returns the same result with 100% confidence.
122122 # It's useful for testing.
123- name = f "Test never-review { datetime . utcnow () } " # Need a unique name
123+ name = generate_test_detector_name ( "Test never-review" )
124124 query = "Is there a dog (always-pass)?"
125125 pipeline_config = "never-review"
126126 _detector = gl .create_detector (name = name , query = query , pipeline_config = pipeline_config )
@@ -129,7 +129,7 @@ def test_create_detector_with_pipeline_config(gl: Groundlight):
129129
130130
131131def test_create_detector_with_edge_pipeline_config (gl : Groundlight ):
132- name = f "Test edge-pipeline-config { datetime . utcnow () } "
132+ name = generate_test_detector_name ( "Test edge-pipeline-config" )
133133 query = "Is there a dog (edge-config)?"
134134 _detector = gl .create_detector (
135135 name = name ,
@@ -144,7 +144,7 @@ def test_create_detector_with_edge_pipeline_config(gl: Groundlight):
144144def test_create_detector_with_confidence_threshold (gl : Groundlight ):
145145 # "never-review" is a special model that always returns the same result with 100% confidence.
146146 # It's useful for testing.
147- name = f "Test with confidence { datetime . utcnow () } " # Need a unique name
147+ name = generate_test_detector_name ( "Test with confidence" )
148148 query = "Is there a dog in the image?"
149149 pipeline_config = "never-review"
150150 confidence_threshold = 0.825
@@ -198,7 +198,7 @@ def test_create_detector_with_confidence_threshold(gl: Groundlight):
198198
199199@pytest .mark .skip_for_edge_endpoint (reason = "The edge-endpoint does not support passing detector metadata." )
200200def test_create_detector_with_everything (gl : Groundlight ):
201- name = f"Test { datetime . utcnow () } " # Need a unique name
201+ name = generate_test_detector_name ()
202202 query = "Is there a dog?"
203203 group_name = "Test group"
204204 confidence_threshold = 0.825
@@ -234,7 +234,7 @@ def test_list_detectors(gl: Groundlight):
234234
235235def test_get_or_create_detector (gl : Groundlight ):
236236 # With a unique name, we should be creating a new detector.
237- unique_name = f"Unique name { datetime . utcnow () } "
237+ unique_name = generate_test_detector_name ()
238238 query = "Is there a dog?"
239239 detector = gl .get_or_create_detector (name = unique_name , query = query )
240240 assert str (detector )
@@ -411,7 +411,7 @@ def test_submit_image_query_with_low_request_timeout(gl: Groundlight, detector:
411411
412412@pytest .mark .skip_for_edge_endpoint (reason = "The edge-endpoint does not support passing detector metadata." )
413413def test_create_detector_with_metadata (gl : Groundlight ):
414- name = f"Test { datetime . utcnow () } " # Need a unique name
414+ name = generate_test_detector_name ()
415415 query = "Is there a dog?"
416416 metadata = generate_random_dict (target_size_bytes = 200 )
417417 detector = gl .create_detector (name = name , query = query , metadata = metadata )
@@ -423,7 +423,7 @@ def test_create_detector_with_metadata(gl: Groundlight):
423423
424424@pytest .mark .skip_for_edge_endpoint (reason = "The edge-endpoint does not support passing detector metadata." )
425425def test_get_or_create_detector_with_metadata (gl : Groundlight ):
426- unique_name = f"Unique name { datetime . utcnow () } "
426+ unique_name = generate_test_detector_name ()
427427 query = "Is there a dog?"
428428 metadata = generate_random_dict (target_size_bytes = 200 )
429429 detector = gl .get_or_create_detector (name = unique_name , query = query , metadata = metadata )
@@ -444,7 +444,7 @@ def test_get_or_create_detector_with_metadata(gl: Groundlight):
444444 ],
445445)
446446def test_create_detector_with_invalid_metadata (gl : Groundlight , metadata_list : Any ):
447- name = f"Test { datetime . utcnow () } " # Need a unique name
447+ name = generate_test_detector_name ()
448448 query = "Is there a dog?"
449449
450450 for metadata in metadata_list :
@@ -629,7 +629,7 @@ def test_list_image_queries(gl: Groundlight):
629629
630630def test_list_image_queries_with_filter (gl : Groundlight ):
631631 # We want a fresh detector so we know exactly what image queries are associated with it
632- detector = gl .create_detector (name = f"Test { datetime . utcnow () } " , query = "Is there a dog?" )
632+ detector = gl .create_detector (name = generate_test_detector_name () , query = "Is there a dog?" )
633633 image_query_yes = gl .ask_async (detector = detector .id , image = "test/assets/dog.jpeg" , human_review = "NEVER" )
634634 image_query_no = gl .ask_async (detector = detector .id , image = "test/assets/cat.jpeg" , human_review = "NEVER" )
635635 iq_ids = [image_query_yes .id , image_query_no .id ]
@@ -859,7 +859,7 @@ def test_binary_detector(gl: Groundlight):
859859 """
860860 verify that we can create and submit to a binary detector
861861 """
862- name = f"Test { datetime . utcnow () } "
862+ name = generate_test_detector_name ()
863863 created_detector = gl .create_binary_detector (name , "Is there a dog" , confidence_threshold = 0.0 )
864864 assert created_detector is not None
865865 binary_iq = gl .submit_image_query (created_detector , "test/assets/dog.jpeg" )
@@ -870,7 +870,7 @@ def test_counting_detector(gl: Groundlight):
870870 """
871871 verify that we can create and submit to a counting detector
872872 """
873- name = f"Test { datetime . utcnow () } "
873+ name = generate_test_detector_name ()
874874 created_detector = gl .create_counting_detector (name , "How many dogs" , "dog" , confidence_threshold = 0.0 )
875875 assert created_detector is not None
876876 count_iq = gl .submit_image_query (created_detector , "test/assets/dog.jpeg" )
@@ -881,7 +881,7 @@ def test_counting_detector_async(gl: Groundlight):
881881 """
882882 verify that we can create and submit to a counting detector
883883 """
884- name = f"Test { datetime . utcnow () } "
884+ name = generate_test_detector_name ()
885885 created_detector = gl .create_counting_detector (name , "How many dogs" , "dog" , confidence_threshold = 0.0 )
886886 assert created_detector is not None
887887 async_iq = gl .ask_async (created_detector , "test/assets/dog.jpeg" )
@@ -900,7 +900,7 @@ def test_multiclass_detector(gl: Groundlight):
900900 """
901901 verify that we can create and submit to a multi-class detector
902902 """
903- name = f"Test { datetime . utcnow () } "
903+ name = generate_test_detector_name ()
904904 class_names = ["Golden Retriever" , "Labrador Retriever" , "Poodle" ]
905905 created_detector = gl .create_multiclass_detector (
906906 name , "What kind of dog is this?" , class_names = class_names , confidence_threshold = 0.0
@@ -916,7 +916,7 @@ def test_delete_detector(gl: Groundlight):
916916 Test deleting a detector by both ID and object, and verify proper error handling.
917917 """
918918 # Create a detector to delete
919- name = f "Test delete detector { datetime . utcnow () } "
919+ name = generate_test_detector_name ( "Test delete detector" )
920920 query = "Is there a dog to delete?"
921921 pipeline_config = "never-review"
922922 detector = gl .create_detector (name = name , query = query , pipeline_config = pipeline_config )
@@ -929,7 +929,7 @@ def test_delete_detector(gl: Groundlight):
929929 gl .get_detector (detector .id )
930930
931931 # Create another detector to test deletion by ID string and that an attached image query is deleted
932- name2 = f "Test delete detector 2 { datetime . utcnow () } "
932+ name2 = generate_test_detector_name ( "Test delete detector 2" )
933933 detector2 = gl .create_detector (name = name2 , query = query , pipeline_config = pipeline_config )
934934 gl .submit_image_query (detector2 , "test/assets/dog.jpeg" )
935935
@@ -959,7 +959,7 @@ def test_create_detector_with_invalid_priming_group_id(gl: Groundlight):
959959 Note: PrimingGroup IDs are provided by Groundlight representatives. If you would like to
960960 use a priming_group_id, please reach out to your Groundlight representative.
961961 """
962- name = f "Test invalid priming { datetime . utcnow () } "
962+ name = generate_test_detector_name ( "Test invalid priming" )
963963 query = "Is there a dog?"
964964 pipeline_config = "never-review"
965965 priming_group_id = "prgrp_nonexistent12345678901234567890"
0 commit comments