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

19 statements  

« 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 accessing values to the individual parameters within tunable groups. 

7""" 

8 

9import pytest 

10 

11from mlos_bench.tunables.covariant_group import CovariantTunableGroup 

12from mlos_bench.tunables.tunable import Tunable 

13 

14 

15def test_categorical_access_to_numerical_tunable(tunable_int: Tunable) -> None: 

16 """ 

17 Make sure we throw an error on accessing a numerical tunable as a categorical. 

18 """ 

19 with pytest.raises(ValueError): 

20 print(tunable_int.category) 

21 with pytest.raises(AssertionError): 

22 print(tunable_int.categories) 

23 

24 

25def test_numerical_access_to_categorical_tunable(tunable_categorical: Tunable) -> None: 

26 """ 

27 Make sure we throw an error on accessing a numerical tunable as a categorical. 

28 """ 

29 with pytest.raises(ValueError): 

30 print(tunable_categorical.numerical_value) 

31 with pytest.raises(AssertionError): 

32 print(tunable_categorical.range) 

33 

34 

35def test_covariant_group_repr(covariant_group: CovariantTunableGroup) -> None: 

36 """ 

37 Tests that the covariant group representation works as expected. 

38 """ 

39 assert repr(covariant_group).startswith(f"{covariant_group.name}:") 

40 

41 

42def test_covariant_group_tunables(covariant_group: CovariantTunableGroup) -> None: 

43 """ 

44 Tests that we can access the tunables in the covariant group. 

45 """ 

46 for tunable in covariant_group.get_tunables(): 

47 assert isinstance(tunable, Tunable)