Coverage for mlos_bench/mlos_bench/tests/util_try_parse_test.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 00:44 +0000
« 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 try_parse_val utility function."""
7import math
9from mlos_bench.util import try_parse_val
12def test_try_parse_val() -> None:
13 """Check that we can retrieve git info about the current repository correctly."""
14 assert try_parse_val(None) is None
15 assert try_parse_val("1") == int(1)
16 assert try_parse_val("1.1") == float(1.1)
17 assert try_parse_val("1e6") == float(1e6)
18 res = try_parse_val("NaN")
19 assert isinstance(res, float) and math.isnan(res)
20 res = try_parse_val("inf")
21 assert isinstance(res, float) and math.isinf(res)
22 res = try_parse_val("-inf")
23 assert isinstance(res, float) and math.isinf(res) and res < 0
24 assert try_parse_val("str") == str("str")