@@ -265,23 +265,25 @@ def read(self) -> Iterator[ParamTestData]:
265265 """
266266 text = self .path .read_text (encoding = self .encoding )
267267 node = yaml .compose (text , yaml .SafeLoader )
268- if not isinstance (node , yaml .SequenceNode ):
268+ if not isinstance (node , yaml .MappingNode ):
269269 raise TypeError (f"Expected sequence, got { type (node )} " )
270- data = yaml .safe_load (text )
270+ data : dict = yaml .safe_load (text )
271271 assert len (node .value ) == len (data ), "YAML node count mismatch"
272- item_node : yaml .Node
273- for index , (item_node , item ) in enumerate (zip (node .value , data )):
274- line = item_node .start_mark .line + 1
272+ title_node : yaml .Node
273+ for index , ((title_node , _ ), (title , item )) in enumerate (
274+ zip (node .value , data .items ())
275+ ):
276+ line = title_node .start_mark .line + 1
275277 if not isinstance (item , dict ):
276278 raise TypeError (
277- f"Expected mapping at line { line } , got { type (item_node )} "
279+ f"Expected mapping value at line { line } , got { type (item )} "
278280 )
279- for key in ("title" , " content" , "expected" ):
281+ for key in ("content" , "expected" ):
280282 if key not in item :
281283 raise KeyError (f"Missing '{ key } ' key for item at line { line } " )
282284 yield ParamTestData (
283285 line ,
284- item [ " title" ] ,
286+ title ,
285287 item .get ("description" ),
286288 item ["content" ],
287289 item ["expected" ],
@@ -326,7 +328,7 @@ def regen_file(self, data: ParamTestData, actual: Any, **kwargs: Any) -> None:
326328 # TODO ideally here we would maintain comments and formatting
327329 # perhaps using ruamel.yaml, although that is a pain
328330 new = yaml .safe_load (self .path .read_text (encoding = self .encoding ))
329- new [data .index ]["expected" ] = actual
331+ new [data .title ]["expected" ] = actual
330332 text = yaml .dump (
331333 new , Dumper = CustomDumper , default_flow_style = False , sort_keys = False
332334 )
0 commit comments