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

11 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"""Test fixtures for individual Tunable objects.""" 

6 

7import pytest 

8 

9from mlos_bench.tunables.tunable import Tunable 

10 

11# pylint: disable=redefined-outer-name 

12# -- Ignore pylint complaints about pytest references to 

13# `tunable_groups` fixture as both a function and a parameter. 

14 

15 

16@pytest.fixture 

17def tunable_categorical() -> Tunable: 

18 """ 

19 A test fixture that produces a categorical Tunable object. 

20 

21 Returns 

22 ------- 

23 tunable : Tunable 

24 An instance of a categorical Tunable. 

25 """ 

26 return Tunable( 

27 "vmSize", 

28 { 

29 "description": "Azure VM size", 

30 "type": "categorical", 

31 "default": "Standard_B4ms", 

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

33 }, 

34 ) 

35 

36 

37@pytest.fixture 

38def tunable_int() -> Tunable: 

39 """ 

40 A test fixture that produces an integer Tunable object with limited range. 

41 

42 Returns 

43 ------- 

44 tunable : Tunable 

45 An instance of an integer Tunable. 

46 """ 

47 return Tunable( 

48 "kernel_sched_migration_cost_ns", 

49 { 

50 "description": "Cost of migrating the thread to another core", 

51 "type": "int", 

52 "default": 40000, 

53 "range": [0, 500000], 

54 "special": [-1], # Special value outside of the range 

55 }, 

56 ) 

57 

58 

59@pytest.fixture 

60def tunable_float() -> Tunable: 

61 """ 

62 A test fixture that produces a float Tunable object with limited range. 

63 

64 Returns 

65 ------- 

66 tunable : Tunable 

67 An instance of a float Tunable. 

68 """ 

69 return Tunable( 

70 "chaos_monkey_prob", 

71 { 

72 "description": "Probability of spontaneous VM shutdown", 

73 "type": "float", 

74 "default": 0.01, 

75 "range": [0, 1], 

76 }, 

77 )