Coverage for mlos_bench/mlos_bench/tests/config/services/test_load_service_config_examples.py: 100%
25 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""
6Tests for loading service config examples.
7"""
8import logging
9from typing import List
11import pytest
13from mlos_bench.tests.config import locate_config_examples
15from mlos_bench.config.schemas.config_schemas import ConfigSchema
16from mlos_bench.services.base_service import Service
17from mlos_bench.services.config_persistence import ConfigPersistenceService
20_LOG = logging.getLogger(__name__)
21_LOG.setLevel(logging.DEBUG)
24# Get the set of configs to test.
25CONFIG_TYPE = "services"
28def filter_configs(configs_to_filter: List[str]) -> List[str]:
29 """If necessary, filter out json files that aren't for the module we're testing."""
30 def predicate(config_path: str) -> bool:
31 arm_template = config_path.find("services/remote/azure/arm-templates/") >= 0 and config_path.endswith(".jsonc")
32 setup_rg_scripts = config_path.find("azure/scripts/setup-rg") >= 0
33 return not (arm_template or setup_rg_scripts)
34 return [config_path for config_path in configs_to_filter if predicate(config_path)]
37configs = locate_config_examples(ConfigPersistenceService.BUILTIN_CONFIG_PATH, CONFIG_TYPE, filter_configs)
38assert configs
41@pytest.mark.parametrize("config_path", configs)
42def test_load_service_config_examples(config_loader_service: ConfigPersistenceService, config_path: str) -> None:
43 """Tests loading a config example."""
44 config = config_loader_service.load_config(config_path, ConfigSchema.SERVICE)
45 # Make an instance of the class based on the config.
46 service_inst = config_loader_service.build_service(
47 config=config,
48 parent=config_loader_service,
49 )
50 assert service_inst is not None
51 assert isinstance(service_inst, Service)