@@ -156,7 +156,7 @@ def test_validate():
156
156
:return:
157
157
"""
158
158
159
- with Conf ('myconf' ) as spec : # noqa: SIM117
159
+ with Conf ('myconf' ) as spec :
160
160
with Conf ('section' ):
161
161
Conf ('name' , VDR .V_STRING )
162
162
Conf ('address' , VDR .V_STRING )
@@ -192,13 +192,20 @@ def parsec_config_2(tmp_path: Path):
192
192
Conf ('address' , VDR .V_INTEGER_LIST )
193
193
with Conf ('allow_many' ):
194
194
Conf ('<user defined>' , VDR .V_STRING , '' )
195
+ with Conf ('so_many' ):
196
+ with Conf ('<thing>' ):
197
+ Conf ('color' , VDR .V_STRING )
198
+ Conf ('horsepower' , VDR .V_INTEGER )
195
199
parsec_config = ParsecConfig (spec , validator = cylc_config_validate )
196
200
conf_file = tmp_path / 'myconf'
197
201
conf_file .write_text ("""
198
202
[section]
199
203
name = test
200
204
[allow_many]
201
205
anything = yup
206
+ [so_many]
207
+ [[legs]]
208
+ horsepower = 123
202
209
""" )
203
210
parsec_config .loadcfg (conf_file , "1.0" )
204
211
return parsec_config
@@ -213,25 +220,32 @@ def test_expand(parsec_config_2: ParsecConfig):
213
220
214
221
def test_get (parsec_config_2 : ParsecConfig ):
215
222
cfg = parsec_config_2 .get (keys = None , sparse = False )
216
- assert parsec_config_2 . dense == cfg
223
+ assert cfg == parsec_config_2 . dense
217
224
218
225
cfg = parsec_config_2 .get (keys = None , sparse = True )
219
- assert parsec_config_2 . sparse == cfg
226
+ assert cfg == parsec_config_2 . sparse
220
227
221
228
cfg = parsec_config_2 .get (keys = ['section' ], sparse = True )
222
- assert parsec_config_2 .sparse ['section' ] == cfg
223
-
224
- with pytest .raises (InvalidConfigError ):
225
- parsec_config_2 .get (keys = ['alloy_many' , 'a' ], sparse = True )
226
-
227
- cfg = parsec_config_2 .get (keys = ['section' , 'name' ], sparse = True )
228
- assert cfg == 'test'
229
-
230
- with pytest .raises (InvalidConfigError ):
231
- parsec_config_2 .get (keys = ['section' , 'a' ], sparse = True )
232
-
233
- with pytest .raises (ItemNotFoundError ):
234
- parsec_config_2 .get (keys = ['allow_many' , 'a' ], sparse = True )
229
+ assert cfg == parsec_config_2 .sparse ['section' ]
230
+
231
+
232
+ @pytest .mark .parametrize ('keys, expected' , [
233
+ (['section' , 'name' ], 'test' ),
234
+ (['section' , 'a' ], InvalidConfigError ),
235
+ (['alloy_many' , 'anything' ], InvalidConfigError ),
236
+ (['allow_many' , 'anything' ], 'yup' ),
237
+ (['allow_many' , 'a' ], ItemNotFoundError ),
238
+ (['so_many' , 'legs' , 'horsepower' ], 123 ),
239
+ (['so_many' , 'legs' , 'color' ], ItemNotFoundError ),
240
+ (['so_many' , 'legs' , 'a' ], InvalidConfigError ),
241
+ (['so_many' , 'teeth' , 'horsepower' ], ItemNotFoundError ),
242
+ ])
243
+ def test_get__sparse (parsec_config_2 : ParsecConfig , keys , expected ):
244
+ if isinstance (expected , type ) and issubclass (expected , Exception ):
245
+ with pytest .raises (expected ):
246
+ parsec_config_2 .get (keys , sparse = True )
247
+ else :
248
+ assert parsec_config_2 .get (keys , sparse = True ) == expected
235
249
236
250
237
251
def test_mdump_none (config , sample_spec , capsys ):
@@ -288,12 +302,17 @@ def test_get_none(config, sample_spec):
288
302
289
303
def test__get_namespace_parents ():
290
304
"""It returns a list of parents and nothing else"""
291
- with Conf ('myconfig' ) as myconf :
292
- with Conf ('some_parent' ): # noqa: SIM117
293
- with Conf ('manythings' ):
294
- Conf ('<thing>' )
295
- with Conf ('other_parent' ):
296
- Conf ('other_thing' )
305
+ with Conf ('myconfig.cylc' ) as myconf :
306
+ with Conf ('a' ):
307
+ with Conf ('b' ):
308
+ with Conf ('<c>' ):
309
+ with Conf ('d' ):
310
+ Conf ('<e>' )
311
+ with Conf ('x' ):
312
+ Conf ('y' )
297
313
298
314
cfg = ParsecConfig (myconf )
299
- assert cfg .manyparents == [['some_parent' , 'manythings' ]]
315
+ assert cfg .manyparents == [
316
+ ['a' , 'b' ],
317
+ ['a' , 'b' , '__MANY__' , 'd' ],
318
+ ]
0 commit comments