@@ -100,15 +100,23 @@ def test_bases(self):
100100
101101
102102@pytest .fixture (params = CubeMetadata ._fields )
103+ # Fixture to parametrise tests over all CubeMetadata fields.
103104def fieldname (request ):
104105 return request .param
105106
106107
107108@pytest .fixture (params = ["strict" , "lenient" ])
109+ # Fixture to parametrise tests over strict/lenient behaviour.
108110def op_leniency (request ):
109111 return request .param
110112
111113
114+ @pytest .fixture (params = ["attributes" , "global_attributes" ])
115+ # Fixture to parametrise atrribute tests over global/local attributes fields.
116+ def attributes_fieldname (request ):
117+ return request .param
118+
119+
112120class Test___eq__ :
113121 @pytest .fixture (autouse = True )
114122 def setup (self ):
@@ -226,13 +234,13 @@ def test_op_different__value(self, fieldname, op_leniency):
226234 assert lmetadata .__eq__ (rmetadata ) == expect_success
227235 assert rmetadata .__eq__ (lmetadata ) == expect_success
228236
229- # TODO: generalise attribute testing to global_attributes
230-
231- def test_op_different__attribute_extra ( self , op_leniency ):
237+ def test_op_different__attribute_extra (
238+ self , attributes_fieldname , op_leniency
239+ ):
232240 # Check when one set of attributes has an extra entry.
233241 is_lenient = op_leniency == "lenient"
234242 lmetadata = self .cls (** self .lvalues )
235- self .rvalues ["attributes" ]["_extra_" ] = 1
243+ self .rvalues [attributes_fieldname ]["_extra_" ] = 1
236244 rmetadata = self .cls (** self .rvalues )
237245 # This counts as equal *only* in the lenient case.
238246 expect_success = is_lenient
@@ -243,11 +251,13 @@ def test_op_different__attribute_extra(self, op_leniency):
243251 assert lmetadata .__eq__ (rmetadata ) == expect_success
244252 assert rmetadata .__eq__ (lmetadata ) == expect_success
245253
246- def test_op_different__attribute_value (self , op_leniency ):
254+ def test_op_different__attribute_value (
255+ self , attributes_fieldname , op_leniency
256+ ):
247257 # lhs and rhs have different values for an attribute, both strict + lenient.
248258 is_lenient = op_leniency == "lenient"
249- self .lvalues ["attributes" ]["_extra_" ] = mock .sentinel .value1
250- self .rvalues ["attributes" ]["_extra_" ] = mock .sentinel .value2
259+ self .lvalues [attributes_fieldname ]["_extra_" ] = mock .sentinel .value1
260+ self .rvalues [attributes_fieldname ]["_extra_" ] = mock .sentinel .value2
251261 lmetadata = self .cls (** self .lvalues )
252262 rmetadata = self .cls (** self .rvalues )
253263 with mock .patch (
@@ -422,15 +432,19 @@ def test_op_different__value(self, fieldname, op_leniency):
422432 assert lmetadata .combine (rmetadata )._asdict () == expected
423433 assert rmetadata .combine (lmetadata )._asdict () == expected
424434
425- # TODO: generalise attribute testing to global_attributes
426-
427- def test_op_different__attribute_extra ( self , op_leniency ):
435+ def test_op_different__attribute_extra (
436+ self , attributes_fieldname , op_leniency
437+ ):
428438 # One field has an extra attribute, both strict + lenient.
429439 is_lenient = op_leniency == "lenient"
430440
431- self .lvalues ["attributes" ] = {"_a_common_" : mock .sentinel .dummy }
432- self .rvalues ["attributes" ] = self .lvalues ["attributes" ].copy ()
433- self .rvalues ["attributes" ]["_extra_" ] = mock .sentinel .testvalue
441+ self .lvalues [attributes_fieldname ] = {
442+ "_a_common_" : mock .sentinel .dummy
443+ }
444+ self .rvalues [attributes_fieldname ] = self .lvalues [
445+ attributes_fieldname
446+ ].copy ()
447+ self .rvalues [attributes_fieldname ]["_extra_" ] = mock .sentinel .testvalue
434448 lmetadata = self .cls (** self .lvalues )
435449 rmetadata = self .cls (** self .rvalues )
436450
@@ -448,15 +462,17 @@ def test_op_different__attribute_extra(self, op_leniency):
448462 assert lmetadata .combine (rmetadata )._asdict () == expected
449463 assert rmetadata .combine (lmetadata )._asdict () == expected
450464
451- def test_op_different__attribute_value (self , op_leniency ):
465+ def test_op_different__attribute_value (
466+ self , attributes_fieldname , op_leniency
467+ ):
452468 # lhs and rhs have different values for an attribute, both strict + lenient.
453469 is_lenient = op_leniency == "lenient"
454470
455- self .lvalues ["attributes" ] = {
471+ self .lvalues [attributes_fieldname ] = {
456472 "_a_common_" : self .dummy ,
457473 "_b_common_" : mock .sentinel .value1 ,
458474 }
459- self .lvalues ["attributes" ] = {
475+ self .lvalues [attributes_fieldname ] = {
460476 "_a_common_" : self .dummy ,
461477 "_b_common_" : mock .sentinel .value2 ,
462478 }
@@ -466,7 +482,7 @@ def test_op_different__attribute_value(self, op_leniency):
466482 # Result has entirely EMPTY attributes (whether strict or lenient).
467483 # TODO: is this maybe a mistake of the existing implementation ?
468484 expected = self .lvalues .copy ()
469- expected ["attributes" ] = None
485+ expected [attributes_fieldname ] = None
470486
471487 with mock .patch (
472488 "iris.common.metadata._LENIENT" , return_value = is_lenient
@@ -605,24 +621,24 @@ def test_op_different__value(self, fieldname, op_leniency):
605621 assert lmetadata .difference (rmetadata )._asdict () == ldiff_metadata
606622 assert rmetadata .difference (lmetadata )._asdict () == rdiff_metadata
607623
608- # TODO: generalise attribute testing to global_attributes
609-
610- def test_op_different__attribute_extra ( self , op_leniency ):
624+ def test_op_different__attribute_extra (
625+ self , attributes_fieldname , op_leniency
626+ ):
611627 # One field has an extra attribute, both strict + lenient.
612628 is_lenient = op_leniency == "lenient"
613- self .lvalues ["attributes" ] = {"_a_common_" : self .dummy }
629+ self .lvalues [attributes_fieldname ] = {"_a_common_" : self .dummy }
614630 lmetadata = self .cls (** self .lvalues )
615631 rvalues = deepcopy (self .lvalues )
616- rvalues ["attributes" ]["_b_extra_" ] = mock .sentinel .extra
632+ rvalues [attributes_fieldname ]["_b_extra_" ] = mock .sentinel .extra
617633 rmetadata = self .cls (** rvalues )
618634
619635 if not is_lenient :
620636 # In this case, attributes returns a "difference dictionary"
621637 diffentry = tuple ([{}, {"_b_extra_" : mock .sentinel .extra }])
622638 lexpected = self .none ._asdict ()
623- lexpected ["attributes" ] = diffentry
639+ lexpected [attributes_fieldname ] = diffentry
624640 rexpected = lexpected .copy ()
625- rexpected ["attributes" ] = diffentry [::- 1 ]
641+ rexpected [attributes_fieldname ] = diffentry [::- 1 ]
626642
627643 with mock .patch (
628644 "iris.common.metadata._LENIENT" , return_value = is_lenient
@@ -636,15 +652,17 @@ def test_op_different__attribute_extra(self, op_leniency):
636652 assert lmetadata .difference (rmetadata )._asdict () == lexpected
637653 assert rmetadata .difference (lmetadata )._asdict () == rexpected
638654
639- def test_op_different__attribute_value (self , op_leniency ):
655+ def test_op_different__attribute_value (
656+ self , attributes_fieldname , op_leniency
657+ ):
640658 # lhs and rhs have different values for an attribute, both strict + lenient.
641659 is_lenient = op_leniency == "lenient"
642- self .lvalues ["attributes" ] = {
660+ self .lvalues [attributes_fieldname ] = {
643661 "_a_common_" : self .dummy ,
644662 "_b_extra_" : mock .sentinel .value1 ,
645663 }
646664 lmetadata = self .cls (** self .lvalues )
647- self .rvalues ["attributes" ] = {
665+ self .rvalues [attributes_fieldname ] = {
648666 "_a_common_" : self .dummy ,
649667 "_b_extra_" : mock .sentinel .value2 ,
650668 }
@@ -658,9 +676,9 @@ def test_op_different__attribute_value(self, op_leniency):
658676 ]
659677 )
660678 lexpected = self .none ._asdict ()
661- lexpected ["attributes" ] = diffentry
679+ lexpected [attributes_fieldname ] = diffentry
662680 rexpected = lexpected .copy ()
663- rexpected ["attributes" ] = diffentry [::- 1 ]
681+ rexpected [attributes_fieldname ] = diffentry [::- 1 ]
664682
665683 with mock .patch (
666684 "iris.common.metadata._LENIENT" , return_value = is_lenient
0 commit comments