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