From a17f3853b44ab1694f065dbd18af06c544a93978 Mon Sep 17 00:00:00 2001 From: Davide Brunato Date: Mon, 23 Dec 2019 18:28:26 +0100 Subject: [PATCH] Fix group encoding errors - TestEncoding.test_encode_unordered_content_2(): last test now raises the correct message (fixed index calculation for missing content tail) --- xmlschema/tests/validation/test_encoding.py | 6 ++---- xmlschema/validators/groups.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/xmlschema/tests/validation/test_encoding.py b/xmlschema/tests/validation/test_encoding.py index be96c6a3..ff530f9f 100644 --- a/xmlschema/tests/validation/test_encoding.py +++ b/xmlschema/tests/validation/test_encoding.py @@ -371,12 +371,10 @@ def test_encode_unordered_content_2(self): expected=u'\nhelloabc\n10\ntrue\n', indent=0, cdata_prefix='#' ) - from xmlschema.converters import XMLSchemaConverter - # FIXME: UnorderedConverter do not work, an XMLSchemaValidationError is expected!! self.check_encode( - xsd_component=schema.elements['A'], converter=XMLSchemaConverter, unordered=True, + xsd_component=schema.elements['A'], data=ordered_dict_class([('B1', 'abc'), ('B2', 10), ('#1', 'hello')]), - expected=u'\nhelloabc\n10\n', indent=0, cdata_prefix='#' + expected=XMLSchemaValidationError, indent=0, cdata_prefix='#' ) def test_strict_trailing_content(self): diff --git a/xmlschema/validators/groups.py b/xmlschema/validators/groups.py index 3a3cd434..83a8059c 100644 --- a/xmlschema/validators/groups.py +++ b/xmlschema/validators/groups.py @@ -787,7 +787,7 @@ def iter_encode(self, element_data, validation='lax', **kwargs): if model.element is not None: for particle, occurs, expected in model.stop(): - errors.append((index - cdata_index, particle, occurs, expected)) + errors.append((index - cdata_index + 1, particle, occurs, expected)) if children: if children[-1].tail is None: