Skip to content

Commit 04e4d3f

Browse files
committed
Move HF tests to separate location
1 parent 082ca6f commit 04e4d3f

File tree

4 files changed

+173
-109
lines changed

4 files changed

+173
-109
lines changed

tests/model_registry/model_catalog/catalog_config/test_model_catalog_negative.py

Lines changed: 8 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from tests.model_registry.constants import DEFAULT_MODEL_CATALOG_CM
88
from tests.model_registry.model_catalog.constants import DEFAULT_CATALOGS
99
from tests.model_registry.model_catalog.catalog_config.utils import validate_model_catalog_configmap_data
10-
from tests.model_registry.utils import execute_get_command
10+
from tests.model_registry.model_catalog.utils import assert_source_error_state_message
1111

1212
LOGGER = get_logger(name=__name__)
1313

@@ -75,120 +75,19 @@ def test_modify_default_catalog_configmap_reconciles(
7575
"non-existent-catalog.yaml: no such file or directory",
7676
id="test_source_error_invalid_path",
7777
),
78-
pytest.param(
79-
"""
80-
catalogs:
81-
- name: HuggingFace Hub
82-
id: error_catalog
83-
type: hf
84-
enabled: true
85-
""",
86-
"includedModels cannot be empty for Hugging Face catalog",
87-
id="test_hf_source_no_include_model",
88-
),
89-
pytest.param(
90-
"""
91-
catalogs:
92-
- name: HuggingFace Hub
93-
id: error_catalog
94-
type: hf
95-
enabled: true
96-
includedModels:
97-
- abc-random*
98-
""",
99-
'failed to expand model patterns: wildcard pattern "abc-random*" is not supported - '
100-
"Hugging Face requires a specific organization",
101-
id="test_hf_source_invalid_organization",
102-
),
103-
pytest.param(
104-
"""
105-
catalogs:
106-
- name: HuggingFace Hub
107-
id: error_catalog
108-
type: hf
109-
enabled: true
110-
includedModels:
111-
- '*'
112-
""",
113-
'failed to expand model patterns: wildcard pattern "*" is not supported - '
114-
"Hugging Face requires a specific organization",
115-
id="test_hf_source_global_wildcard",
116-
),
117-
pytest.param(
118-
"""
119-
catalogs:
120-
- name: HuggingFace Hub
121-
id: error_catalog
122-
type: hf
123-
enabled: true
124-
includedModels:
125-
- '*/*'
126-
""",
127-
'failed to expand model patterns: wildcard pattern "*/*" is not supported - '
128-
"Hugging Face requires a specific organization",
129-
id="test_hf_source_global_org_wildcard",
130-
),
131-
pytest.param(
132-
"""
133-
catalogs:
134-
- name: HuggingFace Hub
135-
id: error_catalog
136-
type: hf
137-
enabled: true
138-
includedModels:
139-
- 'RedHatAI/'
140-
""",
141-
'failed to expand model patterns: wildcard pattern "RedHatAI/" is not supported - '
142-
"Hugging Face requires a specific organization",
143-
id="test_hf_source_empty_model_name",
144-
),
145-
pytest.param(
146-
"""
147-
catalogs:
148-
- name: HuggingFace Hub
149-
id: error_catalog
150-
type: hf
151-
enabled: true
152-
includedModels:
153-
- '*RedHatAI*'
154-
""",
155-
'failed to expand model patterns: wildcard pattern "*RedHatAI*" is not supported - '
156-
"Hugging Face requires a specific organization",
157-
id="test_hf_source_multiple_wildcards",
158-
),
159-
pytest.param(
160-
"""
161-
catalogs:
162-
- name: HuggingFace Hub
163-
id: error_catalog
164-
type: hf
165-
enabled: true
166-
properties:
167-
allowedOrganization: "abc-random"
168-
includedModels:
169-
- '*'
170-
""",
171-
"failed to expand model patterns: no models found",
172-
id="test_hf_source_non_existent_allowed_organization",
173-
),
17478
],
17579
indirect=["updated_catalog_config_map_scope_function"],
17680
)
177-
def test_source_error_state(
81+
def test_default_source_error_state(
17882
self: Self,
17983
updated_catalog_config_map_scope_function: ConfigMap,
18084
model_catalog_rest_url: list[str],
18185
model_registry_rest_headers: dict[str, str],
182-
expected_error_message,
86+
expected_error_message: str,
18387
):
184-
results = execute_get_command(
185-
url=f"{model_catalog_rest_url[0]}sources",
186-
headers=model_registry_rest_headers,
187-
)["items"]
188-
# pick the relevant source first by id:
189-
matched_source = [result for result in results if result["id"] == "error_catalog"]
190-
assert matched_source, f"Matched expected source not found: {results}"
191-
assert matched_source[0]["status"] == "error"
192-
assert expected_error_message in matched_source[0]["error"], (
193-
f"Expected error: {expected_error_message} not found in {matched_source[0]['error']}"
88+
assert_source_error_state_message(
89+
model_catalog_rest_url=model_catalog_rest_url,
90+
model_registry_rest_headers=model_registry_rest_headers,
91+
expected_error_message=expected_error_message,
92+
source_id="error_catalog",
19493
)

tests/model_registry/model_catalog/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ def updated_catalog_config_map_scope_function(
394394
wait_for_model_catalog_api(url=model_catalog_rest_url[0], headers=model_registry_rest_headers)
395395
yield catalog_config_map
396396
is_model_catalog_ready(client=admin_client, model_registry_namespace=model_registry_namespace)
397+
wait_for_model_catalog_api(url=model_catalog_rest_url[0], headers=model_registry_rest_headers)
397398

398399

399400
@pytest.fixture(scope="class")
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import pytest
2+
from simple_logger.logger import get_logger
3+
from typing import Self
4+
5+
from ocp_resources.config_map import ConfigMap
6+
from tests.model_registry.model_catalog.utils import assert_source_error_state_message
7+
8+
LOGGER = get_logger(name=__name__)
9+
10+
pytestmark = [
11+
pytest.mark.usefixtures(
12+
"updated_dsc_component_state_scope_session",
13+
"model_registry_namespace",
14+
)
15+
]
16+
17+
18+
class TestHuggingFaceNegative:
19+
@pytest.mark.parametrize(
20+
"updated_catalog_config_map_scope_function, expected_error_message",
21+
[
22+
pytest.param(
23+
"""
24+
catalogs:
25+
- name: Modified Catalog
26+
id: error_catalog
27+
type: yaml
28+
properties:
29+
yamlCatalogPath: non-existent-catalog.yaml
30+
""",
31+
"non-existent-catalog.yaml: no such file or directory",
32+
id="test_source_error_invalid_path",
33+
),
34+
pytest.param(
35+
"""
36+
catalogs:
37+
- name: HuggingFace Hub
38+
id: error_catalog
39+
type: hf
40+
enabled: true
41+
""",
42+
"includedModels cannot be empty for Hugging Face catalog",
43+
id="test_hf_source_no_include_model",
44+
),
45+
pytest.param(
46+
"""
47+
catalogs:
48+
- name: HuggingFace Hub
49+
id: error_catalog
50+
type: hf
51+
enabled: true
52+
includedModels:
53+
- abc-random*
54+
""",
55+
'failed to expand model patterns: wildcard pattern "abc-random*" is not supported - '
56+
"Hugging Face requires a specific organization",
57+
id="test_hf_source_invalid_organization",
58+
),
59+
pytest.param(
60+
"""
61+
catalogs:
62+
- name: HuggingFace Hub
63+
id: error_catalog
64+
type: hf
65+
enabled: true
66+
includedModels:
67+
- '*'
68+
""",
69+
'failed to expand model patterns: wildcard pattern "*" is not supported - '
70+
"Hugging Face requires a specific organization",
71+
id="test_hf_source_global_wildcard",
72+
),
73+
pytest.param(
74+
"""
75+
catalogs:
76+
- name: HuggingFace Hub
77+
id: error_catalog
78+
type: hf
79+
enabled: true
80+
includedModels:
81+
- '*/*'
82+
""",
83+
'failed to expand model patterns: wildcard pattern "*/*" is not supported - '
84+
"Hugging Face requires a specific organization",
85+
id="test_hf_source_global_org_wildcard",
86+
),
87+
pytest.param(
88+
"""
89+
catalogs:
90+
- name: HuggingFace Hub
91+
id: error_catalog
92+
type: hf
93+
enabled: true
94+
includedModels:
95+
- 'RedHatAI/'
96+
""",
97+
'failed to expand model patterns: wildcard pattern "RedHatAI/" is not supported - '
98+
"Hugging Face requires a specific organization",
99+
id="test_hf_source_empty_model_name",
100+
),
101+
pytest.param(
102+
"""
103+
catalogs:
104+
- name: HuggingFace Hub
105+
id: error_catalog
106+
type: hf
107+
enabled: true
108+
includedModels:
109+
- '*RedHatAI*'
110+
""",
111+
'failed to expand model patterns: wildcard pattern "*RedHatAI*" is not supported - '
112+
"Hugging Face requires a specific organization",
113+
id="test_hf_source_multiple_wildcards",
114+
),
115+
pytest.param(
116+
"""
117+
catalogs:
118+
- name: HuggingFace Hub
119+
id: error_catalog
120+
type: hf
121+
enabled: true
122+
properties:
123+
allowedOrganization: "abc-random"
124+
includedModels:
125+
- '*'
126+
""",
127+
"failed to expand model patterns: no models found",
128+
id="test_hf_source_non_existent_allowed_organization",
129+
),
130+
],
131+
indirect=["updated_catalog_config_map_scope_function"],
132+
)
133+
def test_huggingface_source_error_state(
134+
self: Self,
135+
updated_catalog_config_map_scope_function: ConfigMap,
136+
model_catalog_rest_url: list[str],
137+
model_registry_rest_headers: dict[str, str],
138+
expected_error_message: str,
139+
):
140+
assert_source_error_state_message(
141+
model_catalog_rest_url=model_catalog_rest_url,
142+
model_registry_rest_headers=model_registry_rest_headers,
143+
expected_error_message=expected_error_message,
144+
source_id="error_catalog",
145+
)

tests/model_registry/model_catalog/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,22 @@ def get_excluded_model_str(models: list[str]) -> str:
251251
- {model_name}
252252
"""
253253
return excluded_models
254+
255+
256+
def assert_source_error_state_message(
257+
model_catalog_rest_url: list[str],
258+
model_registry_rest_headers: dict[str, str],
259+
expected_error_message: str,
260+
source_id: str,
261+
):
262+
results = execute_get_command(
263+
url=f"{model_catalog_rest_url[0]}sources",
264+
headers=model_registry_rest_headers,
265+
)["items"]
266+
# pick the relevant source first by id:
267+
matched_source = [result for result in results if result["id"] == source_id]
268+
assert matched_source, f"Matched expected source not found: {results}"
269+
assert matched_source[0]["status"] == "error"
270+
assert expected_error_message in matched_source[0]["error"], (
271+
f"Expected error: {expected_error_message} not found in {matched_source[0]['error']}"
272+
)

0 commit comments

Comments
 (0)