diff --git a/tests/codegen/handlers/test_create_compound_fields.py b/tests/codegen/handlers/test_create_compound_fields.py index 8da61fed..903adcda 100644 --- a/tests/codegen/handlers/test_create_compound_fields.py +++ b/tests/codegen/handlers/test_create_compound_fields.py @@ -266,3 +266,23 @@ def test_sum_counters(self): result = self.processor.sum_counters(counters) self.assertEqual((0, 3), (sum(result[0]), sum(result[1]))) + + def test_update_counters(self): + attr = AttrFactory.create() + attr.restrictions.min_occurs = 2 + attr.restrictions.max_occurs = 3 + attr.restrictions.path = [("c", 0, 1, 1)] + + counters = {} + self.processor.update_counters(attr, counters) + + expected = {("c", 0, 1, 1): {"max": [3], "min": [0]}} + self.assertEqual(expected, counters) + + attr.restrictions.min_occurs = 2 + attr.restrictions.path = [("c", 0, 2, 1)] + + counters = {} + self.processor.update_counters(attr, counters) + expected = {("c", 0, 2, 1): {"max": [3], "min": [2]}} + self.assertEqual(expected, counters) diff --git a/tests/codegen/handlers/test_validate_attributes_overrides.py b/tests/codegen/handlers/test_validate_attributes_overrides.py index 78da4350..af25d29d 100644 --- a/tests/codegen/handlers/test_validate_attributes_overrides.py +++ b/tests/codegen/handlers/test_validate_attributes_overrides.py @@ -102,12 +102,19 @@ def test_validate_override(self): attr_b.fixed = attr_a.fixed attr_a.restrictions.tokens = not attr_b.restrictions.tokens attr_a.restrictions.nillable = not attr_b.restrictions.nillable + attr_a.restrictions.min_occurs = 0 + attr_b.restrictions.min_occurs = 1 + attr_a.restrictions.max_occurs = 0 + attr_b.restrictions.max_occurs = 1 + self.processor.validate_override(target, attr_a, attr_b) self.assertEqual(1, len(target.attrs)) # Restrictions are compatible again attr_a.restrictions.tokens = attr_b.restrictions.tokens attr_a.restrictions.nillable = attr_b.restrictions.nillable + attr_a.restrictions.min_occurs = attr_b.restrictions.min_occurs = 1 + attr_a.restrictions.max_occurs = attr_b.restrictions.max_occurs = 1 self.processor.validate_override(target, attr_a, attr_b) self.assertEqual(0, len(target.attrs)) diff --git a/xsdata/codegen/handlers/validate_attributes_overrides.py b/xsdata/codegen/handlers/validate_attributes_overrides.py index ae73cc1b..9e93bfc9 100644 --- a/xsdata/codegen/handlers/validate_attributes_overrides.py +++ b/xsdata/codegen/handlers/validate_attributes_overrides.py @@ -60,8 +60,8 @@ def validate_override(cls, target: Class, attr: Attr, source_attr: Attr): and bool_eq(attr.mixed, source_attr.mixed) and bool_eq(attr.restrictions.tokens, source_attr.restrictions.tokens) and bool_eq(attr.restrictions.nillable, source_attr.restrictions.nillable) - and bool_eq(attr.restrictions.is_optional, source_attr.restrictions.is_optional) - and bool_eq(attr.restrictions.is_prohibited, source_attr.restrictions.is_prohibited) + and bool_eq(attr.is_prohibited, source_attr.is_prohibited) + and bool_eq(attr.is_optional, source_attr.is_optional) ): cls.remove_attribute(target, attr)