Skip to content

test_def_file_decoder

Unit tests of DefFileDecoder

Functions

decoder

decoder()

Initialize classical decoder

Source code in tests/test_def_file_decoder.py
 8
 9
10
11
@pytest.fixture
def decoder():
    """Initialize classical decoder"""
    return DefFileDecoder()

decoder_with_positions

decoder_with_positions()

Initialize decoder with value position parsing

Source code in tests/test_def_file_decoder.py
14
15
16
17
@pytest.fixture
def decoder_with_positions():
    """Initialize decoder with value position parsing"""
    return DefFileDecoder(include_positions=True)

test_array

test_array(decoder)

Test decoding of arrays

Source code in tests/test_def_file_decoder.py
64
65
66
67
68
def test_array(decoder):
    """Test decoding of arrays"""
    assert decoder.decode("a = 1,2") == {"a": [1, 2]}
    assert decoder.decode("a = 1,2,3") == {"a": [1, 2, 3]}
    assert decoder.decode("a = a, 2, y") == {"a": ["a", 2, True]}

test_auto

test_auto(decoder)

Test decoding of auto values

Source code in tests/test_def_file_decoder.py
71
72
73
74
75
76
77
78
def test_auto(decoder):
    """Test decoding of auto values"""
    assert decoder.decode("a=_AUTO_") == {"a": ("_AUTO_", None)}
    assert decoder.decode("a=_AUTO_:DEFAULT=3.14") == {"a": ("_AUTO_", 3.14)}
    assert decoder.decode("a=_AUTOBLOCKER_") == {"a": ("_AUTOBLOCKER_", None)}
    assert decoder.decode("a=_AUTOBLOCKER_:DEFAULT='text'") == {
        "a": ("_AUTOBLOCKER_", "'text'")
    }

test_float

test_float(decoder)

Test decoding float numbers

Source code in tests/test_def_file_decoder.py
38
39
40
41
42
43
44
45
def test_float(decoder):
    """Test decoding float numbers"""
    assert decoder.decode("a=3.1415") == {"a": 3.1415}
    assert decoder.decode("a=3.14e2") == {"a": 314}
    assert decoder.decode("a=3.14e-2") == {"a": 0.0314}
    assert decoder.decode("a=-3.1415") == {"a": -3.1415}
    assert decoder.decode("a=-3.14e2") == {"a": -314}
    assert decoder.decode("a=-3.14e-2") == {"a": -0.0314}

test_include

test_include(decoder)

Test decoding of INCLUDEDEF statements

Source code in tests/test_def_file_decoder.py
20
21
22
23
24
25
def test_include(decoder):
    """Test decoding of INCLUDEDEF statements"""
    assert decoder.decode("INCLUDEDEF=module1") == {"INCLUDEDEF": ["module1"]}
    assert decoder.decode("INCLUDEDEF=module1\nINCLUDEDEF=module2") == {
        "INCLUDEDEF": ["module1", "module2"]
    }

test_integer

test_integer(decoder)

Test decoding integer numbers

Source code in tests/test_def_file_decoder.py
48
49
50
51
52
53
54
def test_integer(decoder):
    """Test decoding integer numbers"""
    assert decoder.decode("a=1") == {"a": 1}
    assert decoder.decode("a=-1") == {"a": -1}
    assert decoder.decode("a=-0") == {"a": 0}
    assert decoder.decode("a=+0") == {"a": 0}
    assert decoder.decode("a=6123") == {"a": 6123}

test_logical

test_logical(decoder)

Test decoding logical values

Source code in tests/test_def_file_decoder.py
28
29
30
31
32
33
34
35
def test_logical(decoder):
    """Test decoding logical values"""
    assert decoder.decode("a = true\nb=y\nc=TRUE") == {"a": True, "b": True, "c": True}
    assert decoder.decode("a = false\nb=n\nc=FALSE") == {
        "a": False,
        "b": False,
        "c": False,
    }

test_positions

test_positions(decoder_with_positions)

Test decoding of value positions

Source code in tests/test_def_file_decoder.py
81
82
83
84
85
86
87
def test_positions(decoder_with_positions):
    """Test decoding of value positions"""
    assert decoder_with_positions.decode("a=1\nb='text'\nc=_AUTO_:DEFAULT=3.14") == {
        "a": {"value": 1, "start_pos": 2, "end_pos": 3},
        "b": {"value": "'text'", "start_pos": 6, "end_pos": 12},
        "c": {"value": ("_AUTO_", 3.14), "start_pos": 15, "end_pos": 34},
    }

test_string

test_string(decoder)

Test decoding strings (quoted and unqoted)

Source code in tests/test_def_file_decoder.py
57
58
59
60
61
def test_string(decoder):
    """Test decoding strings (quoted and unqoted)"""
    assert decoder.decode("a=text") == {"a": "text"}
    assert decoder.decode("a='text'") == {"a": "'text'"}
    assert decoder.decode('a="text"') == {"a": '"text"'}