aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_parse_value.py
blob: 81db4720ccd47d0f1d6fecb16eeabc18a589a28c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pytest

from config_file.parsers.parse_value import can_be_parsed_as_bool, parse_value


@pytest.mark.parametrize(
    "test_input,expected",
    [
        ("5", 5),
        ("-5", -5),
        ("-234.5", -234.5),
        ("35.5", 35.5),
        ("TRUE", True),
        ("true", True),
        ("false", False),
        ("blah", "blah"),
        (343, 343),
        (3.2, 3.2),
        (True, True),
        ({"blah": "5"}, {"blah": 5}),
        (
            {"blah": {"blah2": {"blah3": "false"}, "abc": "5.25", "boo": "tRuE"}},
            {"blah": {"blah2": {"blah3": False}, "abc": 5.25, "boo": True}},
        ),
        (
            ["5", "4.4", "faLSe", "trUE", "foo", "-5", "-5.2"],
            [5, 4.4, False, True, "foo", -5, -5.2],
        ),
    ],
)
def test_parse_value(test_input, expected):
    assert parse_value(test_input) == expected


def test_can_be_parsed_as_bool():
    """
    This is the section not being covered in the parse_value.py
    file from test_parse_value, but I don't think it's reachable
    from using it.
    """
    assert can_be_parsed_as_bool(5) is False