@@ -428,32 +428,94 @@ def default_metadata_dict(**kwargs: Any) -> dict[str, Any]:
428428 return d
429429
430430
431- def test_fail_on_invalid_key () -> None :
432- ArrayV3Metadata .from_dict (default_metadata_dict ())
433- # Metadata contains invalid keys
434- with pytest .raises (ValueError , match = re .escape ("Unexpected zarr metadata keys: ['unknown']" )):
435- ArrayV3Metadata .from_dict (default_metadata_dict (unknown = "value" ))
436- # accepts invalid key with must_understand=false
437- ArrayV3Metadata .from_dict (
438- default_metadata_dict (unknown = {"name" : "value" , "must_understand" : False })
439- )
440- # Named configuration contains invalid keys
441- with pytest .raises (
442- ValueError ,
443- match = re .escape (
444- "Named configuration expects keys 'name' and 'configuration'. Got ['name', 'unknown', 'configuration']."
431+ @pytest .mark .parametrize (
432+ ("metadata_dict" , "is_valid" , "fail_msg" ),
433+ [
434+ (default_metadata_dict (), True , "" ),
435+ (
436+ default_metadata_dict (unknown = "value" ),
437+ False ,
438+ "Unexpected zarr metadata keys: ['unknown']" ,
445439 ),
446- ):
447- ArrayV3Metadata .from_dict (
448- default_metadata_dict (codecs = [{"name" : "bytes" , "unknown" : {}, "configuration" : {}}])
449- )
450-
451- # accepts invalid key with must_understand=false
452- ArrayV3Metadata .from_dict (
453- default_metadata_dict (
454- codecs = [{"name" : "bytes" , "configuration" : {}, "unknown" : {"must_understand" : False }}]
455- )
456- )
440+ (default_metadata_dict (unknown = {"name" : "value" , "must_understand" : False }), True , "" ),
441+ (
442+ default_metadata_dict (codecs = [{"name" : "bytes" , "unknown" : {}, "configuration" : {}}]),
443+ False ,
444+ "Named configuration expects keys 'name' and 'configuration'. Got ['name', 'unknown', 'configuration']." ,
445+ ),
446+ (
447+ default_metadata_dict (
448+ codecs = [
449+ {"name" : "bytes" , "configuration" : {}, "unknown" : {"must_understand" : False }}
450+ ]
451+ ),
452+ True ,
453+ "" ,
454+ ),
455+ (
456+ default_metadata_dict (data_type = {"name" : "int8" , "value" : {"must_understand" : False }}),
457+ True ,
458+ "" ,
459+ ),
460+ (
461+ default_metadata_dict (
462+ chunk_key_encoding = {
463+ "name" : "default" ,
464+ "configuration" : {"unknown" : {"name" : "value" , "must_understand" : False }},
465+ }
466+ ),
467+ True ,
468+ "" ,
469+ ),
470+ (
471+ default_metadata_dict (
472+ chunk_key_encoding = {"name" : "default" , "configuration" : {"unknown" : "value" }}
473+ ),
474+ False ,
475+ "The chunk key encoding expects a 'separator' key. Got ['unknown']." ,
476+ ),
477+ (default_metadata_dict (chunk_key_encoding = "default" ), True , "" ),
478+ (default_metadata_dict (chunk_key_encoding = "invalid" ), False , "" ),
479+ (
480+ default_metadata_dict (
481+ chunk_grid = {"name" : "regular" , "configuration" : {"chunk_shape" : [2 ]}}
482+ ),
483+ True ,
484+ "" ,
485+ ),
486+ (
487+ default_metadata_dict (
488+ chunk_grid = {
489+ "name" : "regular" ,
490+ "configuration" : {"chunk_shape" : [2 ], "unknown" : "value" },
491+ }
492+ ),
493+ False ,
494+ "The chunk grid expects a 'chunk_shape' key. Got ['chunk_shape', 'unknown']." ,
495+ ),
496+ (
497+ default_metadata_dict (
498+ chunk_grid = {
499+ "name" : "regular" ,
500+ "configuration" : {
501+ "chunk_shape" : [2 ],
502+ "unknown" : {"name" : "value" , "must_understand" : False },
503+ },
504+ }
505+ ),
506+ True ,
507+ "" ,
508+ ),
509+ ],
510+ )
511+ def test_fail_on_invalid_metadata_key (
512+ metadata_dict : dict [str , Any ], is_valid : bool , fail_msg : str
513+ ) -> None :
514+ if is_valid :
515+ ArrayV3Metadata .from_dict (metadata_dict )
516+ else :
517+ with pytest .raises (ValueError , match = re .escape (fail_msg )):
518+ ArrayV3Metadata .from_dict (metadata_dict )
457519
458520
459521@pytest .mark .parametrize (
0 commit comments