Coverage for mlos_bench/mlos_bench/tests/tunables/tunables_str_test.py: 100%

4 statements  

« 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 to make sure we always produce a string representation of a TunableGroup 

6in canonical form. 

7""" 

8 

9from mlos_bench.tunables.tunable_groups import TunableGroups 

10 

11 

12def test_tunable_groups_str(tunable_groups: TunableGroups) -> None: 

13 """Check that we produce the same string representation of TunableGroups, regardless 

14 of the order in which we declare the covariant groups and tunables within each 

15 covariant group. 

16 """ 

17 # Same as `tunable_groups` (defined in the `conftest.py` file), but in different order: 

18 tunables_other = TunableGroups( 

19 { 

20 "kernel": { 

21 "cost": 1, 

22 "params": { 

23 "kernel_sched_latency_ns": { 

24 "type": "int", 

25 "default": 2000000, 

26 "range": [0, 1000000000], 

27 }, 

28 "kernel_sched_migration_cost_ns": { 

29 "type": "int", 

30 "default": -1, 

31 "range": [0, 500000], 

32 "special": [-1], 

33 }, 

34 }, 

35 }, 

36 "boot": { 

37 "cost": 300, 

38 "params": { 

39 "idle": { 

40 "type": "categorical", 

41 "default": "halt", 

42 "values": ["halt", "mwait", "noidle"], 

43 } 

44 }, 

45 }, 

46 "provision": { 

47 "cost": 1000, 

48 "params": { 

49 "vmSize": { 

50 "type": "categorical", 

51 "default": "Standard_B4ms", 

52 "values": ["Standard_B2s", "Standard_B2ms", "Standard_B4ms"], 

53 } 

54 }, 

55 }, 

56 } 

57 ) 

58 assert str(tunable_groups) == str(tunables_other)