Coverage for mlos_bench/mlos_bench/tests/config/globals/test_load_global_config_examples.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 00:44 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""Tests for loading globals config examples.""" 

6import logging 

7from typing import List 

8 

9import pytest 

10 

11from mlos_bench.config.schemas import ConfigSchema 

12from mlos_bench.services.config_persistence import ConfigPersistenceService 

13from mlos_bench.tests.config import BUILTIN_TEST_CONFIG_PATH, locate_config_examples 

14 

15_LOG = logging.getLogger(__name__) 

16_LOG.setLevel(logging.DEBUG) 

17 

18 

19# Get the set of configs to test. 

20CONFIG_TYPE = "globals" 

21 

22 

23def filter_configs(configs_to_filter: List[str]) -> List[str]: 

24 """If necessary, filter out json files that aren't for the module we're testing.""" 

25 return configs_to_filter 

26 

27 

28configs = [ 

29 # *locate_config_examples( 

30 # ConfigPersistenceService.BUILTIN_CONFIG_PATH, 

31 # CONFIG_TYPE, 

32 # filter_configs, 

33 # ), 

34 *locate_config_examples( 

35 ConfigPersistenceService.BUILTIN_CONFIG_PATH, 

36 "experiments", 

37 filter_configs, 

38 ), 

39 *locate_config_examples( 

40 BUILTIN_TEST_CONFIG_PATH, 

41 CONFIG_TYPE, 

42 filter_configs, 

43 ), 

44 *locate_config_examples( 

45 BUILTIN_TEST_CONFIG_PATH, 

46 "experiments", 

47 filter_configs, 

48 ), 

49] 

50assert configs 

51 

52 

53@pytest.mark.parametrize("config_path", configs) 

54def test_load_globals_config_examples( 

55 config_loader_service: ConfigPersistenceService, 

56 config_path: str, 

57) -> None: 

58 """Tests loading a config example.""" 

59 config = config_loader_service.load_config(config_path, ConfigSchema.GLOBALS) 

60 assert isinstance(config, dict)