Coverage for mlos_bench/mlos_bench/tests/util_nullable_test.py: 100%
19 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
« 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 `nullable` utility function.
7"""
8import pytest
10from mlos_bench.util import nullable
13def test_nullable_str() -> None:
14 """
15 Check that the `nullable` function works properly for `str`.
16 """
17 assert nullable(str, None) is None
18 assert nullable(str, "") is not None
19 assert nullable(str, "") == ""
20 assert nullable(str, "test") == "test"
21 assert nullable(str, 10) == "10"
24def test_nullable_int() -> None:
25 """
26 Check that the `nullable` function works properly for `int`.
27 """
28 assert nullable(int, None) is None
29 assert nullable(int, 10) is not None
30 assert nullable(int, 10) == 10
31 assert nullable(int, 36.6) == 36
34def test_nullable_func() -> None:
35 """
36 Check that the `nullable` function works properly with `list.pop()` function.
37 """
38 assert nullable(list.pop, None) is None
39 assert nullable(list.pop, [1, 2, 3]) == 3
41 with pytest.raises(IndexError):
42 assert nullable(list.pop, [])