Coverage for mlos_bench/mlos_bench/tests/tunables/tunables_copy_test.py: 93%
28 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"""
6Unit tests for deep copy of tunable objects and groups.
7"""
9from mlos_bench.tunables.covariant_group import CovariantTunableGroup
10from mlos_bench.tunables.tunable import Tunable, TunableValue
11from mlos_bench.tunables.tunable_groups import TunableGroups
14def test_copy_tunable_int(tunable_int: Tunable) -> None:
15 """
16 Check if deep copy works for Tunable object.
17 """
18 tunable_copy = tunable_int.copy()
19 assert tunable_int == tunable_copy
20 tunable_copy.numerical_value += 200
21 assert tunable_int != tunable_copy
24def test_copy_tunable_groups(tunable_groups: TunableGroups) -> None:
25 """
26 Check if deep copy works for TunableGroups object.
27 """
28 tunable_groups_copy = tunable_groups.copy()
29 assert tunable_groups == tunable_groups_copy
30 tunable_groups_copy["vmSize"] = "Standard_B2ms"
31 assert tunable_groups_copy.is_updated()
32 assert not tunable_groups.is_updated()
33 assert tunable_groups != tunable_groups_copy
36def test_copy_covariant_group(covariant_group: CovariantTunableGroup) -> None:
37 """
38 Check if deep copy works for TunableGroups object.
39 """
40 covariant_group_copy = covariant_group.copy()
41 assert covariant_group == covariant_group_copy
42 tunable = next(iter(covariant_group.get_tunables()))
43 new_value: TunableValue
44 if tunable.is_categorical:
45 new_value = [x for x in tunable.categories if x != tunable.category][0]
46 elif tunable.is_numerical:
47 new_value = tunable.numerical_value + 1
48 covariant_group_copy[tunable] = new_value
49 assert covariant_group_copy.is_updated()
50 assert not covariant_group.is_updated()
51 assert covariant_group != covariant_group_copy