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 8f7e789
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
20 changes: 20 additions & 0 deletions tests/codegen/handlers/test_create_compound_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 8f7e789

Please sign in to comment.