-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_classify_single.py
More file actions
58 lines (47 loc) · 2.07 KB
/
Copy pathtest_classify_single.py
File metadata and controls
58 lines (47 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pytest
from common_utils.image_generation import create_test_image
from resolver_athena_client.client.athena_client import AthenaClient
from resolver_athena_client.client.athena_options import AthenaOptions
from resolver_athena_client.client.channel import (
CredentialHelper,
create_channel_with_credentials,
)
from resolver_athena_client.client.models import ImageData
@pytest.mark.asyncio
@pytest.mark.functional
async def test_classify_single(
athena_options: AthenaOptions, credential_helper: CredentialHelper
) -> None:
"""Functional test for ClassifySingle endpoint and API methods.
This test creates a unique test image for each iteration and classifies it.
The test runs multiple iterations to ensure consistent behavior.
"""
# Create gRPC channel with credentials
channel = await create_channel_with_credentials(
athena_options.host, credential_helper
)
async with AthenaClient(channel, athena_options) as client:
image_bytes = create_test_image()
image_data = ImageData(image_bytes)
# Classify with auto-generated correlation ID
result = await client.classify_single(image_data)
if result.error.code:
msg = f"Image Result Error: {result.error.message}"
pytest.fail(msg)
# The WebIQ hash check runs against a 250ms budget and is abandoned
# if it exceeds it, in which case no KnownCSAM-* classification is
# emitted. Its presence is therefore not guaranteed, but when it is
# present the test image must be a clean no-match (weight 0.0).
for classification in result.classifications:
if classification.label.startswith("KnownCSAM-"):
assert classification.weight == 0.0
assert [
classification
for classification in result.classifications
if classification.label == "UnknownCSAM-Entropy"
]
assert [
classification
for classification in result.classifications
if classification.label == "UnknownCSAM-PCSAM"
]