Coverage for mlos_bench/mlos_bench/tests/config/storage/test_load_storage_config_examples.py: 100%
26 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-14 00:55 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-14 00:55 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""Tests for loading storage config examples."""
6import logging
8import pytest
10from mlos_bench.config.schemas.config_schemas import ConfigSchema
11from mlos_bench.services.config_persistence import ConfigPersistenceService
12from mlos_bench.storage.base_storage import Storage
13from mlos_bench.tests.config import BUILTIN_TEST_CONFIG_PATH, locate_config_examples
14from mlos_bench.util import get_class_from_name
16_LOG = logging.getLogger(__name__)
17_LOG.setLevel(logging.DEBUG)
20# Get the set of configs to test.
21CONFIG_TYPE = "storage"
24def filter_configs(configs_to_filter: list[str]) -> list[str]:
25 """If necessary, filter out json files that aren't for the module we're testing."""
26 return configs_to_filter
29configs = locate_config_examples(
30 ConfigPersistenceService.BUILTIN_CONFIG_PATH,
31 CONFIG_TYPE,
32 filter_configs,
33)
34assert configs
36test_configs = locate_config_examples(
37 BUILTIN_TEST_CONFIG_PATH,
38 CONFIG_TYPE,
39 filter_configs,
40)
41# assert test_configs
42configs.extend(test_configs)
45@pytest.mark.parametrize("config_path", configs)
46def test_load_storage_config_examples(
47 config_loader_service: ConfigPersistenceService,
48 config_path: str,
49) -> None:
50 """Tests loading a config example."""
51 config = config_loader_service.load_config(config_path, ConfigSchema.STORAGE)
52 assert isinstance(config, dict)
53 # Skip schema loading that would require a database connection for this test.
54 config["config"]["lazy_schema_create"] = True
55 cls = get_class_from_name(config["class"])
56 assert issubclass(cls, Storage)
57 # Make an instance of the class based on the config.
58 storage_inst = config_loader_service.build_storage(
59 config=config,
60 service=config_loader_service,
61 )
62 assert storage_inst is not None
63 assert isinstance(storage_inst, cls)