Coverage for mlos_bench/mlos_bench/tests/tunables/conftest.py: 100%
12 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""
6Test fixtures for individual Tunable objects.
7"""
9import pytest
11from mlos_bench.tunables.tunable import Tunable
13# pylint: disable=redefined-outer-name
14# -- Ignore pylint complaints about pytest references to
15# `tunable_groups` fixture as both a function and a parameter.
18@pytest.fixture
19def tunable_categorical() -> Tunable:
20 """
21 A test fixture that produces a categorical Tunable object.
23 Returns
24 -------
25 tunable : Tunable
26 An instance of a categorical Tunable.
27 """
28 return Tunable("vmSize", {
29 "description": "Azure VM size",
30 "type": "categorical",
31 "default": "Standard_B4ms",
32 "values": ["Standard_B2s", "Standard_B2ms", "Standard_B4ms"]
33 })
36@pytest.fixture
37def tunable_int() -> Tunable:
38 """
39 A test fixture that produces an integer Tunable object with limited range.
41 Returns
42 -------
43 tunable : Tunable
44 An instance of an integer Tunable.
45 """
46 return Tunable("kernel_sched_migration_cost_ns", {
47 "description": "Cost of migrating the thread to another core",
48 "type": "int",
49 "default": 40000,
50 "range": [0, 500000],
51 "special": [-1] # Special value outside of the range
52 })
55@pytest.fixture
56def tunable_float() -> Tunable:
57 """
58 A test fixture that produces a float Tunable object with limited range.
60 Returns
61 -------
62 tunable : Tunable
63 An instance of a float Tunable.
64 """
65 return Tunable("chaos_monkey_prob", {
66 "description": "Probability of spontaneous VM shutdown",
67 "type": "float",
68 "default": 0.01,
69 "range": [0, 1]
70 })