Coverage for mlos_bench/mlos_bench/tests/util_try_parse_test.py: 100%
15 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 try_parse_val utility function.
7"""
9import math
11from mlos_bench.util import try_parse_val
14def test_try_parse_val() -> None:
15 """
16 Check that we can retrieve git info about the current repository correctly.
17 """
18 assert try_parse_val(None) is None
19 assert try_parse_val("1") == int(1)
20 assert try_parse_val("1.1") == float(1.1)
21 assert try_parse_val("1e6") == float(1e6)
22 res = try_parse_val("NaN")
23 assert isinstance(res, float) and math.isnan(res)
24 res = try_parse_val("inf")
25 assert isinstance(res, float) and math.isinf(res)
26 res = try_parse_val("-inf")
27 assert isinstance(res, float) and math.isinf(res) and res < 0
28 assert try_parse_val("str") == str("str")