Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra committed Jul 16, 2023
1 parent 904046c commit 3c8adce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tests/codegen/handlers/test_validate_attributes_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions xsdata/codegen/handlers/validate_attributes_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 3c8adce

Please sign in to comment.