Coverage for mlos_bench/mlos_bench/tests/tunables/tunables_copy_test.py: 93%
27 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 00:44 +0000
« 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"""Unit tests for deep copy of tunable objects and groups."""
7from mlos_bench.tunables.covariant_group import CovariantTunableGroup
8from mlos_bench.tunables.tunable import Tunable, TunableValue
9from mlos_bench.tunables.tunable_groups import TunableGroups
12def test_copy_tunable_int(tunable_int: Tunable) -> None:
13 """Check if deep copy works for Tunable object."""
14 tunable_copy = tunable_int.copy()
15 assert tunable_int == tunable_copy
16 tunable_copy.numerical_value += 200
17 assert tunable_int != tunable_copy
20def test_copy_tunable_groups(tunable_groups: TunableGroups) -> None:
21 """Check if deep copy works for TunableGroups object."""
22 tunable_groups_copy = tunable_groups.copy()
23 assert tunable_groups == tunable_groups_copy
24 tunable_groups_copy["vmSize"] = "Standard_B2ms"
25 assert tunable_groups_copy.is_updated()
26 assert not tunable_groups.is_updated()
27 assert tunable_groups != tunable_groups_copy
30def test_copy_covariant_group(covariant_group: CovariantTunableGroup) -> None:
31 """Check if deep copy works for TunableGroups object."""
32 covariant_group_copy = covariant_group.copy()
33 assert covariant_group == covariant_group_copy
34 tunable = next(iter(covariant_group.get_tunables()))
35 new_value: TunableValue
36 if tunable.is_categorical:
37 new_value = [x for x in tunable.categories if x != tunable.category][0]
38 elif tunable.is_numerical:
39 new_value = tunable.numerical_value + 1
40 covariant_group_copy[tunable] = new_value
41 assert covariant_group_copy.is_updated()
42 assert not covariant_group.is_updated()
43 assert covariant_group != covariant_group_copy