Coverage for mlos_bench/mlos_bench/tests/config/schemas/tunable-values/test_tunable_values_schemas.py: 100%
11 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-05 00:36 +0000
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-05 00:36 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""
6Tests for tunable values schema validation.
7"""
9from os import path
11import pytest
13from mlos_bench.config.schemas import ConfigSchema
15from mlos_bench.tests.config.schemas import get_schema_test_cases, check_test_case_against_schema
18# General testing strategy:
19# - hand code a set of good/bad configs (useful to test editor schema checking)
20# - for each config, load and validate against expected schema
22TEST_CASES = get_schema_test_cases(path.join(path.dirname(__file__), "test-cases"))
25# Now we actually perform all of those validation tests.
27@pytest.mark.parametrize("test_case_name", sorted(TEST_CASES.by_path))
28def test_tunable_values_configs_against_schema(test_case_name: str) -> None:
29 """
30 Checks that the tunable values config validates against the schema.
31 """
32 check_test_case_against_schema(TEST_CASES.by_path[test_case_name], ConfigSchema.TUNABLE_VALUES)
33 if TEST_CASES.by_path[test_case_name].test_case_type != "bad":
34 # Unified schema has a hard time validating bad configs, so we skip it.
35 # The trouble is that tunable-values, cli, globals all look like flat dicts with minor constraints on them,
36 # so adding/removing params doesn't invalidate it against all of the config types.
37 check_test_case_against_schema(TEST_CASES.by_path[test_case_name], ConfigSchema.UNIFIED)