55
66import pytest
77
8- from xrlint .cli .config import ConfigError , read_config_list
9- from xrlint .config import Config , ConfigList
8+ from xrlint .cli .config import ConfigError , read_config
9+ from xrlint .config import Config , ConfigObject
1010from xrlint .rule import RuleConfig
1111
1212from .helpers import text_file
@@ -58,24 +58,24 @@ def new_config_py(self):
5858
5959 def test_read_config_yaml (self ):
6060 with text_file ("config.yaml" , yaml_text ) as config_path :
61- config = read_config_list (config_path )
61+ config = read_config (config_path )
6262 self .assert_config_ok (config , "yaml-test" )
6363
6464 def test_read_config_json (self ):
6565 with text_file ("config.json" , json_text ) as config_path :
66- config = read_config_list (config_path )
66+ config = read_config (config_path )
6767 self .assert_config_ok (config , "json-test" )
6868
6969 def test_read_config_py (self ):
7070 with text_file (self .new_config_py (), py_text ) as config_path :
71- config = read_config_list (config_path )
71+ config = read_config (config_path )
7272 self .assert_config_ok (config , "py-test" )
7373
7474 def assert_config_ok (self , config : Any , name : str ):
7575 self .assertEqual (
76- ConfigList (
76+ Config (
7777 [
78- Config (
78+ ConfigObject (
7979 name = name ,
8080 rules = {
8181 "rule-1" : RuleConfig (2 ),
@@ -94,7 +94,7 @@ def test_read_config_invalid_arg(self):
9494 match = "configuration file must be of type str|Path|PathLike, but got None" ,
9595 ):
9696 # noinspection PyTypeChecker
97- read_config_list (None )
97+ read_config (None )
9898
9999 def test_read_config_json_with_format_error (self ):
100100 with text_file ("config.json" , "{" ) as config_path :
@@ -106,34 +106,34 @@ def test_read_config_json_with_format_error(self):
106106 " line 1 column 2 \\ (char 1\\ )"
107107 ),
108108 ):
109- read_config_list (config_path )
109+ read_config (config_path )
110110
111111 def test_read_config_yaml_with_format_error (self ):
112112 with text_file ("config.yaml" , "}" ) as config_path :
113113 with pytest .raises (
114114 ConfigError ,
115115 match = "config.yaml: while parsing a block node" ,
116116 ):
117- read_config_list (config_path )
117+ read_config (config_path )
118118
119119 def test_read_config_yaml_with_type_error (self ):
120120 with text_file ("config.yaml" , "97" ) as config_path :
121121 with pytest .raises (
122122 ConfigError ,
123123 match = (
124- r"config\.yaml\: config_list must be of"
125- r" type ConfigList \| list\[Config \| dict \| str\],"
124+ r"config\.yaml\: config must be of type "
125+ r" Config \| ConfigObjectLike \| str \| Sequence\[ConfigObjectLike \| str\],"
126126 r" but got int"
127127 ),
128128 ):
129- read_config_list (config_path )
129+ read_config (config_path )
130130
131131 def test_read_config_with_unknown_format (self ):
132132 with pytest .raises (
133133 ConfigError ,
134134 match = "config.toml: unsupported configuration file format" ,
135135 ):
136- read_config_list ("config.toml" )
136+ read_config ("config.toml" )
137137
138138 def test_read_config_py_no_export (self ):
139139 py_code = "x = 42\n "
@@ -145,7 +145,7 @@ def test_read_config_py_no_export(self):
145145 " not found in module 'config_1002'"
146146 ),
147147 ):
148- read_config_list (config_path )
148+ read_config (config_path )
149149
150150 def test_read_config_py_with_value_error (self ):
151151 py_code = "def export_config():\n raise ValueError('value is useless!')\n "
@@ -154,7 +154,7 @@ def test_read_config_py_with_value_error(self):
154154 ValueError ,
155155 match = "value is useless!" ,
156156 ):
157- read_config_list (config_path )
157+ read_config (config_path )
158158
159159 def test_read_config_py_with_os_error (self ):
160160 py_code = "def export_config():\n raise OSError('where is my hat?')\n "
@@ -163,47 +163,47 @@ def test_read_config_py_with_os_error(self):
163163 ConfigError ,
164164 match = "where is my hat?" ,
165165 ):
166- read_config_list (config_path )
166+ read_config (config_path )
167167
168168 def test_read_config_py_with_invalid_config_list (self ):
169169 py_code = "def export_config():\n return 42\n "
170170 with text_file (self .new_config_py (), py_code ) as config_path :
171171 with pytest .raises (
172172 ConfigError ,
173173 match = (
174- r"\.py: return value of export_config\(\) :"
175- r" config_list must be of type"
176- r" ConfigList \| list\[Config\ | dict \| str\],"
174+ r"\.py: failed converting value of 'config_1003: export_config' :"
175+ r" config must be of type"
176+ r" Config \| ConfigObjectLike \| str \| Sequence\[ConfigObjectLike \| str\],"
177177 r" but got int"
178178 ),
179179 ):
180- read_config_list (config_path )
180+ read_config (config_path )
181181
182182
183183class CliConfigResolveTest (unittest .TestCase ):
184184 def test_read_config_py (self ):
185185 self .assert_ok (
186- read_config_list (Path (__file__ ).parent / "configs" / "recommended.py" )
186+ read_config (Path (__file__ ).parent / "configs" / "recommended.py" )
187187 )
188188
189189 def test_read_config_json (self ):
190190 self .assert_ok (
191- read_config_list (Path (__file__ ).parent / "configs" / "recommended.json" )
191+ read_config (Path (__file__ ).parent / "configs" / "recommended.json" )
192192 )
193193
194194 def test_read_config_yaml (self ):
195195 self .assert_ok (
196- read_config_list (Path (__file__ ).parent / "configs" / "recommended.yaml" )
196+ read_config (Path (__file__ ).parent / "configs" / "recommended.yaml" )
197197 )
198198
199- def assert_ok (self , config_list : ConfigList ):
200- self .assertIsInstance (config_list , ConfigList )
201- self .assertEqual (7 , len (config_list .configs ))
202- config = config_list .compute_config ("test.zarr" )
199+ def assert_ok (self , config : Config ):
203200 self .assertIsInstance (config , Config )
204- self .assertEqual (None , config .name )
205- self .assertIsInstance (config .plugins , dict )
206- self .assertEqual ({"xcube" }, set (config .plugins .keys ()))
207- self .assertIsInstance (config .rules , dict )
208- self .assertIn ("coords-for-dims" , config .rules )
209- self .assertIn ("xcube/cube-dims-order" , config .rules )
201+ self .assertEqual (7 , len (config .objects ))
202+ config_obj = config .compute_config_object ("test.zarr" )
203+ self .assertIsInstance (config_obj , ConfigObject )
204+ self .assertEqual (None , config_obj .name )
205+ self .assertIsInstance (config_obj .plugins , dict )
206+ self .assertEqual ({"xcube" }, set (config_obj .plugins .keys ()))
207+ self .assertIsInstance (config_obj .rules , dict )
208+ self .assertIn ("coords-for-dims" , config_obj .rules )
209+ self .assertIn ("xcube/cube-dims-order" , config_obj .rules )
0 commit comments