Skip to content

Commit 9781a0a

Browse files
committed
renaming fixture
1 parent 4b1ac5f commit 9781a0a

File tree

7 files changed

+80
-80
lines changed

7 files changed

+80
-80
lines changed

test/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
from model import Detector, ImageQuery, ImageQueryTypeEnum, ResultTypeEnum
77

88

9-
def _generate_test_detector_name(prefix: str = "Test") -> str:
9+
def _generate_unique_detector_name(prefix: str = "Test") -> str:
1010
"""Generates a detector name with a timestamp and random suffix to ensure uniqueness."""
1111
return f"{prefix} {datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')}_{uuid4().hex[:8]}"
1212

1313

14-
@pytest.fixture(name="generate_test_detector_name")
15-
def fixture_test_detector_name():
14+
@pytest.fixture(name="detector_name")
15+
def fixture_detector_name():
1616
"""Fixture that provides a callable to generate unique detector names."""
17-
return _generate_test_detector_name
17+
return _generate_unique_detector_name
1818

1919

2020
def pytest_configure(config): # pylint: disable=unused-argument
@@ -39,7 +39,7 @@ def fixture_detector(gl: Groundlight) -> Detector:
3939
"""Creates a new Test detector."""
4040
query = "Is there a dog?"
4141
pipeline_config = "never-review"
42-
return gl.create_detector(name=_generate_test_detector_name(), query=query, pipeline_config=pipeline_config)
42+
return gl.create_detector(name=_generate_unique_detector_name(), query=query, pipeline_config=pipeline_config)
4343

4444

4545
@pytest.fixture(name="count_detector")
@@ -48,7 +48,7 @@ def fixture_count_detector(gl_experimental: ExperimentalApi) -> Detector:
4848
query = "How many dogs?"
4949
pipeline_config = "never-review-multi" # always predicts 0
5050
return gl_experimental.create_counting_detector(
51-
name=_generate_test_detector_name(), query=query, class_name="dog", pipeline_config=pipeline_config
51+
name=_generate_unique_detector_name(), query=query, class_name="dog", pipeline_config=pipeline_config
5252
)
5353

5454

test/integration/test_groundlight.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def test_create_groundlight_with_retries():
9595
assert gl.api_client.configuration.retries.total == retries.total
9696

9797

98-
def test_create_detector(gl: Groundlight, generate_test_detector_name: Callable):
99-
name = generate_test_detector_name()
98+
def test_create_detector(gl: Groundlight, detector_name: Callable):
99+
name = detector_name()
100100
query = "Is there a dog?"
101101
_detector = gl.create_detector(name=name, query=query)
102102
assert str(_detector)
@@ -107,28 +107,28 @@ def test_create_detector(gl: Groundlight, generate_test_detector_name: Callable)
107107

108108
# Test creating dectors with other modes
109109
count_detector = gl.create_detector(
110-
name=generate_test_detector_name(), query=query, mode=ModeEnum.COUNT, class_names="dog"
110+
name=detector_name(), query=query, mode=ModeEnum.COUNT, class_names="dog"
111111
)
112112
assert str(count_detector)
113113
multiclass_detector = gl.create_detector(
114-
name=generate_test_detector_name(), query=query, mode=ModeEnum.MULTI_CLASS, class_names=["dog", "cat"]
114+
name=detector_name(), query=query, mode=ModeEnum.MULTI_CLASS, class_names=["dog", "cat"]
115115
)
116116
assert str(multiclass_detector)
117117

118118

119-
def test_create_detector_with_pipeline_config(gl: Groundlight, generate_test_detector_name: Callable):
119+
def test_create_detector_with_pipeline_config(gl: Groundlight, detector_name: Callable):
120120
# "never-review" is a special model that always returns the same result with 100% confidence.
121121
# It's useful for testing.
122-
name = generate_test_detector_name("Test never-review")
122+
name = detector_name("Test never-review")
123123
query = "Is there a dog (always-pass)?"
124124
pipeline_config = "never-review"
125125
_detector = gl.create_detector(name=name, query=query, pipeline_config=pipeline_config)
126126
assert str(_detector)
127127
assert isinstance(_detector, Detector)
128128

129129

130-
def test_create_detector_with_edge_pipeline_config(gl: Groundlight, generate_test_detector_name: Callable):
131-
name = generate_test_detector_name("Test edge-pipeline-config")
130+
def test_create_detector_with_edge_pipeline_config(gl: Groundlight, detector_name: Callable):
131+
name = detector_name("Test edge-pipeline-config")
132132
query = "Is there a dog (edge-config)?"
133133
_detector = gl.create_detector(
134134
name=name,
@@ -140,10 +140,10 @@ def test_create_detector_with_edge_pipeline_config(gl: Groundlight, generate_tes
140140
assert isinstance(_detector, Detector)
141141

142142

143-
def test_create_detector_with_confidence_threshold(gl: Groundlight, generate_test_detector_name: Callable):
143+
def test_create_detector_with_confidence_threshold(gl: Groundlight, detector_name: Callable):
144144
# "never-review" is a special model that always returns the same result with 100% confidence.
145145
# It's useful for testing.
146-
name = generate_test_detector_name("Test with confidence")
146+
name = detector_name("Test with confidence")
147147
query = "Is there a dog in the image?"
148148
pipeline_config = "never-review"
149149
confidence_threshold = 0.825
@@ -196,8 +196,8 @@ def test_create_detector_with_confidence_threshold(gl: Groundlight, generate_tes
196196

197197

198198
@pytest.mark.skip_for_edge_endpoint(reason="The edge-endpoint does not support passing detector metadata.")
199-
def test_create_detector_with_everything(gl: Groundlight, generate_test_detector_name: Callable):
200-
name = generate_test_detector_name()
199+
def test_create_detector_with_everything(gl: Groundlight, detector_name: Callable):
200+
name = detector_name()
201201
query = "Is there a dog?"
202202
group_name = "Test group"
203203
confidence_threshold = 0.825
@@ -231,9 +231,9 @@ def test_list_detectors(gl: Groundlight):
231231
assert isinstance(detectors, PaginatedDetectorList)
232232

233233

234-
def test_get_or_create_detector(gl: Groundlight, generate_test_detector_name: Callable):
234+
def test_get_or_create_detector(gl: Groundlight, detector_name: Callable):
235235
# With a unique name, we should be creating a new detector.
236-
unique_name = generate_test_detector_name()
236+
unique_name = detector_name()
237237
query = "Is there a dog?"
238238
detector = gl.get_or_create_detector(name=unique_name, query=query)
239239
assert str(detector)
@@ -409,8 +409,8 @@ def test_submit_image_query_with_low_request_timeout(gl: Groundlight, detector:
409409

410410

411411
@pytest.mark.skip_for_edge_endpoint(reason="The edge-endpoint does not support passing detector metadata.")
412-
def test_create_detector_with_metadata(gl: Groundlight, generate_test_detector_name: Callable):
413-
name = generate_test_detector_name()
412+
def test_create_detector_with_metadata(gl: Groundlight, detector_name: Callable):
413+
name = detector_name()
414414
query = "Is there a dog?"
415415
metadata = generate_random_dict(target_size_bytes=200)
416416
detector = gl.create_detector(name=name, query=query, metadata=metadata)
@@ -421,8 +421,8 @@ def test_create_detector_with_metadata(gl: Groundlight, generate_test_detector_n
421421

422422

423423
@pytest.mark.skip_for_edge_endpoint(reason="The edge-endpoint does not support passing detector metadata.")
424-
def test_get_or_create_detector_with_metadata(gl: Groundlight, generate_test_detector_name: Callable):
425-
unique_name = generate_test_detector_name()
424+
def test_get_or_create_detector_with_metadata(gl: Groundlight, detector_name: Callable):
425+
unique_name = detector_name()
426426
query = "Is there a dog?"
427427
metadata = generate_random_dict(target_size_bytes=200)
428428
detector = gl.get_or_create_detector(name=unique_name, query=query, metadata=metadata)
@@ -442,8 +442,8 @@ def test_get_or_create_detector_with_metadata(gl: Groundlight, generate_test_det
442442
[""],
443443
],
444444
)
445-
def test_create_detector_with_invalid_metadata(gl: Groundlight, metadata_list: Any, generate_test_detector_name: Callable):
446-
name = generate_test_detector_name()
445+
def test_create_detector_with_invalid_metadata(gl: Groundlight, metadata_list: Any, detector_name: Callable):
446+
name = detector_name()
447447
query = "Is there a dog?"
448448

449449
for metadata in metadata_list:
@@ -626,9 +626,9 @@ def test_list_image_queries(gl: Groundlight):
626626
assert is_valid_display_result(image_query.result)
627627

628628

629-
def test_list_image_queries_with_filter(gl: Groundlight, generate_test_detector_name: Callable):
629+
def test_list_image_queries_with_filter(gl: Groundlight, detector_name: Callable):
630630
# We want a fresh detector so we know exactly what image queries are associated with it
631-
detector = gl.create_detector(name=generate_test_detector_name(), query="Is there a dog?")
631+
detector = gl.create_detector(name=detector_name(), query="Is there a dog?")
632632
image_query_yes = gl.ask_async(detector=detector.id, image="test/assets/dog.jpeg", human_review="NEVER")
633633
image_query_no = gl.ask_async(detector=detector.id, image="test/assets/cat.jpeg", human_review="NEVER")
634634
iq_ids = [image_query_yes.id, image_query_no.id]
@@ -854,33 +854,33 @@ def test_submit_image_query_with_empty_inspection_id(gl: Groundlight, detector:
854854
)
855855

856856

857-
def test_binary_detector(gl: Groundlight, generate_test_detector_name: Callable):
857+
def test_binary_detector(gl: Groundlight, detector_name: Callable):
858858
"""
859859
verify that we can create and submit to a binary detector
860860
"""
861-
name = generate_test_detector_name()
861+
name = detector_name()
862862
created_detector = gl.create_binary_detector(name, "Is there a dog", confidence_threshold=0.0)
863863
assert created_detector is not None
864864
binary_iq = gl.submit_image_query(created_detector, "test/assets/dog.jpeg")
865865
assert binary_iq.result.label is not None
866866

867867

868-
def test_counting_detector(gl: Groundlight, generate_test_detector_name: Callable):
868+
def test_counting_detector(gl: Groundlight, detector_name: Callable):
869869
"""
870870
verify that we can create and submit to a counting detector
871871
"""
872-
name = generate_test_detector_name()
872+
name = detector_name()
873873
created_detector = gl.create_counting_detector(name, "How many dogs", "dog", confidence_threshold=0.0)
874874
assert created_detector is not None
875875
count_iq = gl.submit_image_query(created_detector, "test/assets/dog.jpeg")
876876
assert count_iq.result.count is not None
877877

878878

879-
def test_counting_detector_async(gl: Groundlight, generate_test_detector_name: Callable):
879+
def test_counting_detector_async(gl: Groundlight, detector_name: Callable):
880880
"""
881881
verify that we can create and submit to a counting detector
882882
"""
883-
name = generate_test_detector_name()
883+
name = detector_name()
884884
created_detector = gl.create_counting_detector(name, "How many dogs", "dog", confidence_threshold=0.0)
885885
assert created_detector is not None
886886
async_iq = gl.ask_async(created_detector, "test/assets/dog.jpeg")
@@ -895,11 +895,11 @@ def test_counting_detector_async(gl: Groundlight, generate_test_detector_name: C
895895
assert _image_query.result is not None
896896

897897

898-
def test_multiclass_detector(gl: Groundlight, generate_test_detector_name: Callable):
898+
def test_multiclass_detector(gl: Groundlight, detector_name: Callable):
899899
"""
900900
verify that we can create and submit to a multi-class detector
901901
"""
902-
name = generate_test_detector_name()
902+
name = detector_name()
903903
class_names = ["Golden Retriever", "Labrador Retriever", "Poodle"]
904904
created_detector = gl.create_multiclass_detector(
905905
name, "What kind of dog is this?", class_names=class_names, confidence_threshold=0.0
@@ -910,12 +910,12 @@ def test_multiclass_detector(gl: Groundlight, generate_test_detector_name: Calla
910910
assert mc_iq.result.label in class_names
911911

912912

913-
def test_delete_detector(gl: Groundlight, generate_test_detector_name: Callable):
913+
def test_delete_detector(gl: Groundlight, detector_name: Callable):
914914
"""
915915
Test deleting a detector by both ID and object, and verify proper error handling.
916916
"""
917917
# Create a detector to delete
918-
name = generate_test_detector_name("Test delete detector")
918+
name = detector_name("Test delete detector")
919919
query = "Is there a dog to delete?"
920920
pipeline_config = "never-review"
921921
detector = gl.create_detector(name=name, query=query, pipeline_config=pipeline_config)
@@ -928,7 +928,7 @@ def test_delete_detector(gl: Groundlight, generate_test_detector_name: Callable)
928928
gl.get_detector(detector.id)
929929

930930
# Create another detector to test deletion by ID string and that an attached image query is deleted
931-
name2 = generate_test_detector_name("Test delete detector 2")
931+
name2 = detector_name("Test delete detector 2")
932932
detector2 = gl.create_detector(name=name2, query=query, pipeline_config=pipeline_config)
933933
gl.submit_image_query(detector2, "test/assets/dog.jpeg")
934934

@@ -951,14 +951,14 @@ def test_delete_detector(gl: Groundlight, generate_test_detector_name: Callable)
951951
gl.delete_detector(fake_detector_id) # type: ignore
952952

953953

954-
def test_create_detector_with_invalid_priming_group_id(gl: Groundlight, generate_test_detector_name: Callable):
954+
def test_create_detector_with_invalid_priming_group_id(gl: Groundlight, detector_name: Callable):
955955
"""
956956
Test that creating a detector with a non-existent priming_group_id returns an appropriate error.
957957
958958
Note: PrimingGroup IDs are provided by Groundlight representatives. If you would like to
959959
use a priming_group_id, please reach out to your Groundlight representative.
960960
"""
961-
name = generate_test_detector_name("Test invalid priming")
961+
name = detector_name("Test invalid priming")
962962
query = "Is there a dog?"
963963
pipeline_config = "never-review"
964964
priming_group_id = "prgrp_nonexistent12345678901234567890"

test/integration/test_groundlight_expensive.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def fixture_gl() -> Groundlight:
3030

3131

3232
@pytest.mark.skip(reason="This test requires a human labeler who does not need to be in the testing loop")
33-
def test_human_label(gl: Groundlight, generate_test_detector_name: Callable):
34-
detector = gl.create_detector(name=generate_test_detector_name(), query="Is there a dog?")
33+
def test_human_label(gl: Groundlight, detector_name: Callable):
34+
detector = gl.create_detector(name=detector_name(), query="Is there a dog?")
3535
img_query = gl.submit_image_query(
3636
detector=detector.id, image="test/assets/dog.jpeg", wait=60, human_review="ALWAYS"
3737
)
@@ -52,7 +52,7 @@ def test_human_label(gl: Groundlight, generate_test_detector_name: Callable):
5252

5353
@pytest.mark.skip(reason="This test can block development depending on the state of the service")
5454
@pytest.mark.skipif(MISSING_PIL, reason="Needs pillow") # type: ignore
55-
def test_detector_improvement(gl: Groundlight, generate_test_detector_name: Callable):
55+
def test_detector_improvement(gl: Groundlight, detector_name: Callable):
5656
# test that we get confidence improvement after sending images in
5757
# Pass two of each type of image in
5858
import time
@@ -61,7 +61,7 @@ def test_detector_improvement(gl: Groundlight, generate_test_detector_name: Call
6161

6262
random.seed(2741)
6363

64-
name = generate_test_detector_name("Test test_detector_improvement")
64+
name = detector_name("Test test_detector_improvement")
6565
query = "Is there a dog?"
6666
detector = gl.create_detector(name=name, query=query)
6767

@@ -122,11 +122,11 @@ def submit_noisy_image(image, label=None):
122122
@pytest.mark.skip(
123123
reason="We don't yet have an SLA level to test ask_confident against, and the test is flakey as a result"
124124
)
125-
def test_ask_method_quality(gl: Groundlight, detector: Detector, generate_test_detector_name: Callable):
125+
def test_ask_method_quality(gl: Groundlight, detector: Detector, detector_name: Callable):
126126
# asks for some level of quality on how fast ask_ml is and that we will get a confident result from ask_confident
127127
fast_always_yes_iq = gl.ask_ml(detector=detector.id, image="test/assets/dog.jpeg", wait=0)
128128
assert iq_is_answered(fast_always_yes_iq)
129-
name = generate_test_detector_name()
129+
name = detector_name()
130130
query = "Is there a dog?"
131131
detector = gl.create_detector(name=name, query=query, confidence_threshold=0.8)
132132
fast_iq = gl.ask_ml(detector=detector.id, image="test/assets/dog.jpeg", wait=0)

test/unit/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def test_list_detector():
2323
assert completed_process.returncode == 0
2424

2525

26-
def test_detector_and_image_queries(generate_test_detector_name: Callable):
26+
def test_detector_and_image_queries(detector_name: Callable):
2727
# test creating a detector
28-
test_detector_name = generate_test_detector_name("testdetector")
28+
test_detector_name = detector_name("testdetector")
2929
completed_process = subprocess.run(
3030
[
3131
"groundlight",

test/unit/test_detector_reset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88

99
@pytest.mark.skip(reason="This is an expensive test, reset may take some time")
10-
def test_reset_retry(gl_experimental: ExperimentalApi, generate_test_detector_name: Callable):
10+
def test_reset_retry(gl_experimental: ExperimentalApi, detector_name: Callable):
1111
# Reset the detector, retrying in case the reset is still ongoing
12-
det = gl_experimental.create_detector(generate_test_detector_name(), "test_query")
12+
det = gl_experimental.create_detector(detector_name(), "test_query")
1313
iq = gl_experimental.submit_image_query(det, "test/assets/cat.jpeg")
1414
gl_experimental.reset_detector(det.id)
1515
success = False
@@ -27,10 +27,10 @@ def test_reset_retry(gl_experimental: ExperimentalApi, generate_test_detector_na
2727

2828

2929
@pytest.mark.skip(reason="This test does not work with strong 0 shot models, enabled by default based on your account")
30-
def test_reset_training(gl_experimental: ExperimentalApi, generate_test_detector_name: Callable):
30+
def test_reset_training(gl_experimental: ExperimentalApi, detector_name: Callable):
3131
# If we reset a detector, we should have low confidence after the reset
3232
low_confidence_threshold = 0.6
33-
det = gl_experimental.create_detector(generate_test_detector_name(), "is this a cat")
33+
det = gl_experimental.create_detector(detector_name(), "is this a cat")
3434
gl_experimental.reset_detector(det.id)
3535
iq = gl_experimental.submit_image_query(det, "test/assets/cat.jpeg", human_review="NEVER")
3636
assert iq.result.confidence < low_confidence_threshold

0 commit comments

Comments
 (0)