31
31
32
32
def test_config_parser_valid_config_file ():
33
33
"""Test valid YAML parsing."""
34
- conf = ConfigParser (TEST_FILE )
35
- assert type (conf .config .dict ()) == type (TEST_DICT )
34
+ conf = ConfigParser (Path ( TEST_FILE ) )
35
+ assert type (conf .config .model_dump ()) == type (TEST_DICT )
36
36
assert isinstance (conf .config , type (TEST_CONFIG_INSTANCE ))
37
37
38
38
39
39
def test_config_parser_invalid_config_file ():
40
40
"""Test invalid YAML parsing."""
41
41
with pytest .raises (ValidationError ):
42
- ConfigParser (TEST_FILE_INVALID )
42
+ ConfigParser (Path ( TEST_FILE_INVALID ) )
43
43
44
44
45
45
def test_config_parser_invalid_file_path ():
46
46
"""Test invalid file path."""
47
- conf = ConfigParser (TEST_FILE )
47
+ conf = ConfigParser (Path ( TEST_FILE ) )
48
48
with pytest .raises (OSError ):
49
- assert conf .parse_yaml ("" ) is not None
49
+ assert conf .parse_yaml (Path ( "" ) ) is not None
50
50
51
51
52
52
def test_config_parser_invalid_log_config ():
53
53
"""Test invalid log config YAML."""
54
- conf = ConfigParser (TEST_FILE_INVALID_LOG )
55
- assert type (conf .config .dict ()) == type (TEST_DICT )
54
+ conf = ConfigParser (Path ( TEST_FILE_INVALID_LOG ) )
55
+ assert type (conf .config .model_dump ()) == type (TEST_DICT )
56
56
assert isinstance (conf .config , type (TEST_CONFIG_INSTANCE ))
57
57
58
58
59
59
def test_config_parser_with_custom_config_model ():
60
60
"""Test with valid custom config model class."""
61
61
conf = ConfigParser (
62
- config_file = TEST_FILE ,
62
+ config_file = Path ( TEST_FILE ) ,
63
63
custom_config_model = TEST_CONFIG_MODEL ,
64
64
)
65
65
assert isinstance (conf .config .custom .param , str )
@@ -68,22 +68,22 @@ def test_config_parser_with_custom_config_model():
68
68
69
69
def test_process_yaml_valid_config_file ():
70
70
"""Test process_yaml with valid YAML file."""
71
- result = ConfigParser .parse_yaml (TEST_FILE )
71
+ result = ConfigParser .parse_yaml (Path ( TEST_FILE ) )
72
72
assert isinstance (result , dict )
73
73
74
74
75
75
def test_process_yaml_invalid_config_file ():
76
76
"""Test process_yaml with invalid YAML file."""
77
77
with pytest .raises (ValueError ):
78
- ConfigParser .parse_yaml (TEST_FILE_INVALID_YAML )
78
+ ConfigParser .parse_yaml (Path ( TEST_FILE_INVALID_YAML ) )
79
79
80
80
81
81
def test_process_yaml_missing_file ():
82
82
"""Test process_yaml when file cannot be opened."""
83
83
with mock .patch ("foca.config.config_parser.open" ) as mock_open :
84
84
mock_open .side_effect = OSError
85
85
with pytest .raises (OSError ):
86
- ConfigParser .parse_yaml (TEST_FILE )
86
+ ConfigParser .parse_yaml (Path ( TEST_FILE ) )
87
87
88
88
89
89
def test_merge_yaml_with_no_args ():
@@ -95,14 +95,14 @@ def test_merge_yaml_with_no_args():
95
95
96
96
def test_merge_yaml_with_two_args ():
97
97
"""Test merge_yaml with no arguments."""
98
- yaml_list = [PATH , PATH_ADDITION ]
98
+ yaml_list = [Path ( PATH ), Path ( PATH_ADDITION ) ]
99
99
res = ConfigParser .merge_yaml (* yaml_list )
100
100
assert 'put' in res ['paths' ]['/pets/{petId}' ]
101
101
102
102
103
103
def test_parse_custom_config_valid_model ():
104
104
"""Test ``.parse_custom_config()`` with a valid model class."""
105
- conf = ConfigParser (config_file = TEST_FILE )
105
+ conf = ConfigParser (config_file = Path ( TEST_FILE ) )
106
106
result = conf .parse_custom_config (model = TEST_CONFIG_MODEL )
107
107
assert isinstance (result , BaseModel )
108
108
assert isinstance (result .param , str )
@@ -111,20 +111,20 @@ def test_parse_custom_config_valid_model():
111
111
112
112
def test_parse_custom_config_model_module_not_exists ():
113
113
"""Test ``.parse_custom_config()`` when module does not exist."""
114
- conf = ConfigParser (config_file = TEST_FILE )
114
+ conf = ConfigParser (config_file = Path ( TEST_FILE ) )
115
115
with pytest .raises (ValueError ):
116
116
conf .parse_custom_config (model = TEST_CONFIG_MODEL_MODULE_NOT_EXISTS )
117
117
118
118
119
119
def test_parse_custom_config_model_not_exists ():
120
120
"""Test ``.parse_custom_config()`` when model class does not exist."""
121
- conf = ConfigParser (config_file = TEST_FILE )
121
+ conf = ConfigParser (config_file = Path ( TEST_FILE ) )
122
122
with pytest .raises (ValueError ):
123
123
conf .parse_custom_config (model = TEST_CONFIG_MODEL_NOT_EXISTS )
124
124
125
125
126
126
def test_parse_custom_config_invalid ():
127
127
"""Test ``.parse_custom_config()`` when model class does not exist."""
128
- conf = ConfigParser (config_file = TEST_FILE_CUSTOM_INVALID )
128
+ conf = ConfigParser (config_file = Path ( TEST_FILE_CUSTOM_INVALID ) )
129
129
with pytest .raises (ValueError ):
130
130
conf .parse_custom_config (model = TEST_CONFIG_MODEL )
0 commit comments