2022-07-25 23:45:44 +03:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License.
|
2022-07-08 19:28:41 +03:00
|
|
|
|
2023-03-09 20:29:30 +03:00
|
|
|
"""Test validate_assets script."""
|
|
|
|
|
2022-05-20 21:26:20 +03:00
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
2023-07-06 16:00:52 +03:00
|
|
|
import re
|
2022-05-20 21:26:20 +03:00
|
|
|
|
|
|
|
import azureml.assets as assets
|
|
|
|
|
2022-06-14 00:06:50 +03:00
|
|
|
RESOURCES_DIR = Path("resources/validate")
|
2023-10-27 07:35:04 +03:00
|
|
|
MODEL_VALIDATION_RESULTS = Path("resources/model_validation_results")
|
2022-05-20 21:26:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-07-06 16:00:52 +03:00
|
|
|
"test_subdir,check_images,check_names,check_names_skip_pattern,expected",
|
2023-03-09 20:29:30 +03:00
|
|
|
[
|
2023-07-06 16:00:52 +03:00
|
|
|
("name-mismatch", False, True, None, False),
|
|
|
|
("version-mismatch", False, True, None, False),
|
|
|
|
("invalid-strings", False, True, None, False),
|
|
|
|
("env-with-underscores", False, True, None, False),
|
|
|
|
("framework-ver-missing", False, True, None, False),
|
|
|
|
("ubuntu-in-name", False, True, None, False),
|
|
|
|
("ubuntu-in-name", False, True, re.compile(r"environment/env-ubuntu20.04/.+"), True),
|
|
|
|
("ubuntu-in-name", False, False, None, True),
|
|
|
|
("extra-gpu", False, None, True, False),
|
|
|
|
("incorrect-order", False, True, None, False),
|
|
|
|
("image-name-mismatch", True, True, None, False),
|
|
|
|
("publishing-disabled", True, True, None, False),
|
|
|
|
("good-validation", True, True, None, True),
|
|
|
|
("correct-order", True, True, None, True),
|
|
|
|
("missing-description-file", True, True, None, False),
|
2023-07-19 19:02:26 +03:00
|
|
|
("data-good", False, True, None, True),
|
|
|
|
("data-path-mismatch-1", False, True, None, False),
|
|
|
|
("data-path-mismatch-2", False, True, None, False),
|
2023-08-03 19:50:58 +03:00
|
|
|
("dockerfile-from-ce-image", False, False, None, False),
|
|
|
|
("dockerfile-from-ce-image-comment", False, False, None, False),
|
|
|
|
("dockerfile-from-ce-image-windows", False, False, None, False),
|
2023-10-02 17:03:04 +03:00
|
|
|
("bad-build-context", False, True, None, False),
|
2023-12-20 18:58:26 +03:00
|
|
|
("model-with-azure", False, True, None, False),
|
2024-09-26 17:07:26 +03:00
|
|
|
("azure-ai-model", False, True, None, True),
|
|
|
|
("azure-ai-model-bad", False, True, None, False),
|
2023-12-20 18:58:26 +03:00
|
|
|
("model-microsoft-good", False, True, None, True),
|
|
|
|
("model-microsoft-bad-asset-name", False, True, None, False),
|
|
|
|
("model-microsoft-bad-spec", False, True, None, False),
|
2024-05-17 14:45:33 +03:00
|
|
|
("evaluationresult/invalid_evaluation_type", False, True, None, False),
|
|
|
|
("evaluationresult/text_embeddings_correct", False, True, None, True),
|
|
|
|
("evaluationresult/text_embeddings_incorrect", False, True, None, False),
|
|
|
|
("evaluationresult/text_generation_correct", False, True, None, True),
|
|
|
|
("evaluationresult/text_generation_incorrect", False, True, None, False),
|
2024-09-17 02:46:18 +03:00
|
|
|
("evaluationresult/vision_correct", False, True, None, True),
|
|
|
|
("evaluationresult/vision_incorrect", False, True, None, False),
|
2023-03-09 20:29:30 +03:00
|
|
|
]
|
2022-05-20 21:26:20 +03:00
|
|
|
)
|
2023-07-06 16:00:52 +03:00
|
|
|
def test_validate_assets(test_subdir: str, check_images: bool, check_names: bool,
|
|
|
|
check_names_skip_pattern: re.Pattern, expected: bool):
|
2023-03-09 20:29:30 +03:00
|
|
|
"""Test validate_assets function.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
test_subdir (str): Test subdirectory
|
|
|
|
check_images (bool): Check image build/publish info
|
2023-07-06 16:00:52 +03:00
|
|
|
check_names (bool): Check name
|
|
|
|
check_names_skip_pattern (re.Pattern): Skip pattern for name validation
|
2023-03-09 20:29:30 +03:00
|
|
|
expected (bool): Success expected
|
|
|
|
"""
|
2022-05-20 21:26:20 +03:00
|
|
|
this_dir = Path(__file__).parent
|
|
|
|
|
|
|
|
assert assets.validate_assets(
|
2023-03-09 20:29:30 +03:00
|
|
|
input_dirs=this_dir / RESOURCES_DIR / test_subdir,
|
2023-10-27 07:35:04 +03:00
|
|
|
model_validation_results_dir=this_dir / MODEL_VALIDATION_RESULTS / test_subdir,
|
2023-03-09 20:29:30 +03:00
|
|
|
asset_config_filename=assets.DEFAULT_ASSET_FILENAME,
|
2023-07-06 16:00:52 +03:00
|
|
|
check_names=check_names,
|
|
|
|
check_names_skip_pattern=check_names_skip_pattern,
|
2023-10-02 17:03:04 +03:00
|
|
|
check_images=check_images,
|
|
|
|
check_build_context=True) == expected
|