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

5 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-05 00:36 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5""" 

6Unit tests to make sure we always produce a string representation 

7of a TunableGroup in canonical form. 

8""" 

9 

10from mlos_bench.tunables.tunable_groups import TunableGroups 

11 

12 

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

14 """ 

15 Check that we produce the same string representation of TunableGroups, 

16 regardless of the order in which we declare the covariant groups and 

17 tunables within each covariant group. 

18 """ 

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

20 tunables_other = TunableGroups({ 

21 "kernel": { 

22 "cost": 1, 

23 "params": { 

24 "kernel_sched_latency_ns": { 

25 "type": "int", 

26 "default": 2000000, 

27 "range": [0, 1000000000] 

28 }, 

29 "kernel_sched_migration_cost_ns": { 

30 "type": "int", 

31 "default": -1, 

32 "range": [0, 500000], 

33 "special": [-1] 

34 } 

35 } 

36 }, 

37 "boot": { 

38 "cost": 300, 

39 "params": { 

40 "idle": { 

41 "type": "categorical", 

42 "default": "halt", 

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

44 } 

45 } 

46 }, 

47 "provision": { 

48 "cost": 1000, 

49 "params": { 

50 "vmSize": { 

51 "type": "categorical", 

52 "default": "Standard_B4ms", 

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

54 } 

55 } 

56 }, 

57 }) 

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