Coverage for mlos_bench/mlos_bench/tests/launcher_in_process_test.py: 100%
8 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-07 01:52 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-07 01:52 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""Unit tests to check the launcher and the main optimization loop in-process."""
7from typing import List
9import pytest
11from mlos_bench.run import _main
14@pytest.mark.parametrize(
15 ("argv", "expected_score"),
16 [
17 (
18 [
19 "--config",
20 "mlos_bench/mlos_bench/tests/config/cli/mock-bench.jsonc",
21 "--trial_config_repeat_count",
22 "5",
23 "--mock_env_seed",
24 "-1", # Deterministic Mock Environment.
25 ],
26 67.40329,
27 ),
28 (
29 [
30 "--config",
31 "mlos_bench/mlos_bench/tests/config/cli/mock-opt.jsonc",
32 "--trial_config_repeat_count",
33 "3",
34 "--max-suggestions",
35 "3",
36 "--mock_env_seed",
37 "42", # Noisy Mock Environment.
38 ],
39 64.53897,
40 ),
41 ],
42)
43def test_main_bench(argv: List[str], expected_score: float) -> None:
44 """Run mlos_bench optimization loop with given config and check the results."""
45 (score, _config) = _main(argv)
46 assert score is not None
47 assert pytest.approx(score["score"], 1e-5) == expected_score