Test Values Check

tests.values.test_values_check

test_values_check.py file for the fejao_config_parser package.

This module contains unit tests for the ValuesCheck class, which is responsible for converting string values to their specified types based on the configuration.

TestValuesCheck

Bases: TestCase

Test suite for the ValuesCheck class.

Source code in tests/values/test_values_check.py
 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
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
class TestValuesCheck(unittest.TestCase):
    """Test suite for the ValuesCheck class."""

    ###
    ### PRIVATE METHODS
    ###

    def test_check_values_is_private(self):
        """Test that __check_values method is private and not directly accessible."""
        config = [{"name": "example_bool", "type": "bool"}]
        values_found = {"example_bool": True}

        parser = ValuesCheck(config=config, values_found=values_found, info_string="test")

        with self.assertRaises(AttributeError):
            parser.__check_values()

        self.assertTrue(hasattr(parser, '_ValuesCheck__check_values'))
        self.assertNotIn('__check_values', dir(parser))

    ###
    ### TEST VALID VALUE TYPES
    ###

    def test_string_value_is_valid(self):
        """Test that a valid string value passes the check."""
        config = [{"name": "example_string", "type": "string"}]
        values_found = {"example_string": "hello"}

        ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_bool_value_is_valid(self):
        """Test that a valid bool value passes the check."""
        config = [{"name": "example_bool", "type": "bool"}]
        values_found = {"example_bool": True}

        ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_int_value_is_valid(self):
        """Test that a valid int value passes the check."""
        config = [{"name": "example_int", "type": "int"}]
        values_found = {"example_int": 123}

        ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_float_value_is_valid(self):
        """Test that a valid float value passes the check."""
        config = [{"name": "example_float", "type": "float"}]
        values_found = {"example_float": 1.23}

        ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_list_value_is_valid(self):
        """Test that a valid list value passes the check."""
        config = [{"name": "example_list", "type": "list"}]
        values_found = {"example_list": [1, 2, 3]}

        ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_dict_value_is_valid(self):
        """Test that a valid dict value passes the check."""
        config = [{"name": "example_dict", "type": "dict"}]
        values_found = {"example_dict": {"a": 1}}

        ValuesCheck(config=config, values_found=values_found, info_string="test")

    ###
    ### TEST INVALID VALUE TYPES
    ###

    def test_missing_value_is_ignored(self):
        """Test that a missing value is ignored and does not raise an error."""
        config = [{"name": "example_missing", "type": "string"}]
        values_found = {}

        ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_invalid_type_raises_value_error(self):
        """Test that an invalid string value type raises a ValueError."""
        config = [{"name": "example_string", "type": "unknown"}]
        values_found = {"example_string": 123}

        with self.assertRaises(ValueError):
            ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_string_value_invalid_type_raises_value_error(self):
        """Test that an invalid string value type raises a ValueError."""
        config = [{"name": "example_string", "type": "string"}]
        values_found = {"example_string": 123}

        with self.assertRaises(ValueError):
            ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_bool_value_invalid_type_raises_value_error(self):
        """Test that an invalid bool value type raises a ValueError."""
        config = [{"name": "example_bool", "type": "bool"}]
        values_found = {"example_bool": "true"}

        with self.assertRaises(ValueError):
            ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_int_value_invalid_type_raises_value_error(self):
        """Test that an invalid int value type raises a ValueError."""
        config = [{"name": "example_int", "type": "int"}]
        values_found = {"example_int": 1.23}

        with self.assertRaises(ValueError):
            ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_float_value_invalid_type_raises_value_error(self):
        """Test that an invalid float value type raises a ValueError."""
        config = [{"name": "example_float", "type": "float"}]
        values_found = {"example_float": 1}

        with self.assertRaises(ValueError):
            ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_list_value_invalid_type_raises_value_error(self):
        """Test that an invalid list value type raises a ValueError."""
        config = [{"name": "example_list", "type": "list"}]
        values_found = {"example_list": "not a list"}

        with self.assertRaises(ValueError):
            ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_dict_value_invalid_type_raises_value_error(self):
        """Test that an invalid dict value type raises a ValueError."""
        config = [{"name": "example_dict", "type": "dict"}]
        values_found = {"example_dict": ["a", "b"]}

        with self.assertRaises(ValueError):
            ValuesCheck(config=config, values_found=values_found, info_string="test")

    def test_unsupported_type_raises_value_error(self):
        """Test that an unsupported type raises a ValueError."""
        config = [{"name": "example_unknown", "type": "unsupported"}]
        values_found = {"example_unknown": "value"}

        with self.assertRaises(ValueError):
            ValuesCheck(config=config, values_found=values_found, info_string="test")
Methods:
test_bool_value_invalid_type_raises_value_error
test_bool_value_invalid_type_raises_value_error()

Test that an invalid bool value type raises a ValueError.

Source code in tests/values/test_values_check.py
107
108
109
110
111
112
113
def test_bool_value_invalid_type_raises_value_error(self):
    """Test that an invalid bool value type raises a ValueError."""
    config = [{"name": "example_bool", "type": "bool"}]
    values_found = {"example_bool": "true"}

    with self.assertRaises(ValueError):
        ValuesCheck(config=config, values_found=values_found, info_string="test")
test_bool_value_is_valid
test_bool_value_is_valid()

Test that a valid bool value passes the check.

Source code in tests/values/test_values_check.py
45
46
47
48
49
50
def test_bool_value_is_valid(self):
    """Test that a valid bool value passes the check."""
    config = [{"name": "example_bool", "type": "bool"}]
    values_found = {"example_bool": True}

    ValuesCheck(config=config, values_found=values_found, info_string="test")
test_check_values_is_private
test_check_values_is_private()

Test that __check_values method is private and not directly accessible.

Source code in tests/values/test_values_check.py
21
22
23
24
25
26
27
28
29
30
31
32
def test_check_values_is_private(self):
    """Test that __check_values method is private and not directly accessible."""
    config = [{"name": "example_bool", "type": "bool"}]
    values_found = {"example_bool": True}

    parser = ValuesCheck(config=config, values_found=values_found, info_string="test")

    with self.assertRaises(AttributeError):
        parser.__check_values()

    self.assertTrue(hasattr(parser, '_ValuesCheck__check_values'))
    self.assertNotIn('__check_values', dir(parser))
test_dict_value_invalid_type_raises_value_error
test_dict_value_invalid_type_raises_value_error()

Test that an invalid dict value type raises a ValueError.

Source code in tests/values/test_values_check.py
139
140
141
142
143
144
145
def test_dict_value_invalid_type_raises_value_error(self):
    """Test that an invalid dict value type raises a ValueError."""
    config = [{"name": "example_dict", "type": "dict"}]
    values_found = {"example_dict": ["a", "b"]}

    with self.assertRaises(ValueError):
        ValuesCheck(config=config, values_found=values_found, info_string="test")
test_dict_value_is_valid
test_dict_value_is_valid()

Test that a valid dict value passes the check.

Source code in tests/values/test_values_check.py
73
74
75
76
77
78
def test_dict_value_is_valid(self):
    """Test that a valid dict value passes the check."""
    config = [{"name": "example_dict", "type": "dict"}]
    values_found = {"example_dict": {"a": 1}}

    ValuesCheck(config=config, values_found=values_found, info_string="test")
test_float_value_invalid_type_raises_value_error
test_float_value_invalid_type_raises_value_error()

Test that an invalid float value type raises a ValueError.

Source code in tests/values/test_values_check.py
123
124
125
126
127
128
129
def test_float_value_invalid_type_raises_value_error(self):
    """Test that an invalid float value type raises a ValueError."""
    config = [{"name": "example_float", "type": "float"}]
    values_found = {"example_float": 1}

    with self.assertRaises(ValueError):
        ValuesCheck(config=config, values_found=values_found, info_string="test")
test_float_value_is_valid
test_float_value_is_valid()

Test that a valid float value passes the check.

Source code in tests/values/test_values_check.py
59
60
61
62
63
64
def test_float_value_is_valid(self):
    """Test that a valid float value passes the check."""
    config = [{"name": "example_float", "type": "float"}]
    values_found = {"example_float": 1.23}

    ValuesCheck(config=config, values_found=values_found, info_string="test")
test_int_value_invalid_type_raises_value_error
test_int_value_invalid_type_raises_value_error()

Test that an invalid int value type raises a ValueError.

Source code in tests/values/test_values_check.py
115
116
117
118
119
120
121
def test_int_value_invalid_type_raises_value_error(self):
    """Test that an invalid int value type raises a ValueError."""
    config = [{"name": "example_int", "type": "int"}]
    values_found = {"example_int": 1.23}

    with self.assertRaises(ValueError):
        ValuesCheck(config=config, values_found=values_found, info_string="test")
test_int_value_is_valid
test_int_value_is_valid()

Test that a valid int value passes the check.

Source code in tests/values/test_values_check.py
52
53
54
55
56
57
def test_int_value_is_valid(self):
    """Test that a valid int value passes the check."""
    config = [{"name": "example_int", "type": "int"}]
    values_found = {"example_int": 123}

    ValuesCheck(config=config, values_found=values_found, info_string="test")
test_invalid_type_raises_value_error
test_invalid_type_raises_value_error()

Test that an invalid string value type raises a ValueError.

Source code in tests/values/test_values_check.py
91
92
93
94
95
96
97
def test_invalid_type_raises_value_error(self):
    """Test that an invalid string value type raises a ValueError."""
    config = [{"name": "example_string", "type": "unknown"}]
    values_found = {"example_string": 123}

    with self.assertRaises(ValueError):
        ValuesCheck(config=config, values_found=values_found, info_string="test")
test_list_value_invalid_type_raises_value_error
test_list_value_invalid_type_raises_value_error()

Test that an invalid list value type raises a ValueError.

Source code in tests/values/test_values_check.py
131
132
133
134
135
136
137
def test_list_value_invalid_type_raises_value_error(self):
    """Test that an invalid list value type raises a ValueError."""
    config = [{"name": "example_list", "type": "list"}]
    values_found = {"example_list": "not a list"}

    with self.assertRaises(ValueError):
        ValuesCheck(config=config, values_found=values_found, info_string="test")
test_list_value_is_valid
test_list_value_is_valid()

Test that a valid list value passes the check.

Source code in tests/values/test_values_check.py
66
67
68
69
70
71
def test_list_value_is_valid(self):
    """Test that a valid list value passes the check."""
    config = [{"name": "example_list", "type": "list"}]
    values_found = {"example_list": [1, 2, 3]}

    ValuesCheck(config=config, values_found=values_found, info_string="test")
test_missing_value_is_ignored
test_missing_value_is_ignored()

Test that a missing value is ignored and does not raise an error.

Source code in tests/values/test_values_check.py
84
85
86
87
88
89
def test_missing_value_is_ignored(self):
    """Test that a missing value is ignored and does not raise an error."""
    config = [{"name": "example_missing", "type": "string"}]
    values_found = {}

    ValuesCheck(config=config, values_found=values_found, info_string="test")
test_string_value_invalid_type_raises_value_error
test_string_value_invalid_type_raises_value_error()

Test that an invalid string value type raises a ValueError.

Source code in tests/values/test_values_check.py
 99
100
101
102
103
104
105
def test_string_value_invalid_type_raises_value_error(self):
    """Test that an invalid string value type raises a ValueError."""
    config = [{"name": "example_string", "type": "string"}]
    values_found = {"example_string": 123}

    with self.assertRaises(ValueError):
        ValuesCheck(config=config, values_found=values_found, info_string="test")
test_string_value_is_valid
test_string_value_is_valid()

Test that a valid string value passes the check.

Source code in tests/values/test_values_check.py
38
39
40
41
42
43
def test_string_value_is_valid(self):
    """Test that a valid string value passes the check."""
    config = [{"name": "example_string", "type": "string"}]
    values_found = {"example_string": "hello"}

    ValuesCheck(config=config, values_found=values_found, info_string="test")
test_unsupported_type_raises_value_error
test_unsupported_type_raises_value_error()

Test that an unsupported type raises a ValueError.

Source code in tests/values/test_values_check.py
147
148
149
150
151
152
153
def test_unsupported_type_raises_value_error(self):
    """Test that an unsupported type raises a ValueError."""
    config = [{"name": "example_unknown", "type": "unsupported"}]
    values_found = {"example_unknown": "value"}

    with self.assertRaises(ValueError):
        ValuesCheck(config=config, values_found=values_found, info_string="test")