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

18 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 for accessing values to the individual parameters within tunable 

6groups. 

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 """Make sure we throw an error on accessing a numerical tunable as a categorical.""" 

17 with pytest.raises(ValueError): 

18 print(tunable_int.category) 

19 with pytest.raises(AssertionError): 

20 print(tunable_int.categories) 

21 

22 

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

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

25 with pytest.raises(ValueError): 

26 print(tunable_categorical.numerical_value) 

27 with pytest.raises(AssertionError): 

28 print(tunable_categorical.range) 

29 

30 

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

32 """Tests that the covariant group representation works as expected.""" 

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

34 

35 

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

37 """Tests that we can access the tunables in the covariant group.""" 

38 for tunable in covariant_group.get_tunables(): 

39 assert isinstance(tunable, Tunable)