Skip to content

Commit

Permalink
validate_xml_doc: Add package version to the raised exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ycouce-cdd committed Apr 9, 2021
1 parent 94a2df1 commit cc0a347
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cl_sii/libs/xml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import signxml.exceptions
import xml.parsers.expat
import xml.parsers.expat.errors
from cl_sii import __version__
from lxml.etree import ElementBase as XmlElement # noqa: F401
# note: 'lxml.etree.ElementTree' is a **function**, not a class.
from lxml.etree import _ElementTree as XmlElementTree # noqa: F401
Expand Down Expand Up @@ -306,7 +307,7 @@ def validate_xml_doc(xml_schema: XmlSchema, xml_doc: XmlElement) -> None:
# Simplest and safest way to get the error message.
# Error example:
# "Element 'DTE': No matching global declaration available for the validation root., line 2" # noqa: E501
validation_error_msg = str(exc)
validation_error_msg = str(exc) + f". cl-sii Python lib version {__version__}"

raise XmlSchemaDocValidationError(validation_error_msg) from exc

Expand Down
19 changes: 13 additions & 6 deletions tests/test_dte_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import date, datetime

import cl_sii.dte.constants
from cl_sii import __version__
from cl_sii.dte.data_models import DteDataL2
from cl_sii.libs import crypto_utils
from cl_sii.libs import encoding_utils
Expand Down Expand Up @@ -88,7 +89,8 @@ def test_validate_dte_xml_fail_dte_1(self) -> None:
self.assertSequenceEqual(
cm.exception.args,
("Element 'DTE': No matching global declaration available for the validation root., "
"line 2", )
"line 2."
f" cl-sii Python lib version {__version__}", )
)

def test_validate_dte_xml_fail_dte_2(self) -> None:
Expand All @@ -104,7 +106,8 @@ def test_validate_dte_xml_fail_dte_2(self) -> None:
self.assertSequenceEqual(
cm.exception.args,
("Element 'DTE': No matching global declaration available for the validation root., "
"line 2", )
"line 2."
f" cl-sii Python lib version {__version__}", )
)

def test_validate_dte_xml_fail_dte_3(self) -> None:
Expand All @@ -120,7 +123,8 @@ def test_validate_dte_xml_fail_dte_3(self) -> None:
self.assertSequenceEqual(
cm.exception.args,
("Element 'DTE': No matching global declaration available for the validation root., "
"line 2", )
"line 2."
f" cl-sii Python lib version {__version__}", )
)


Expand Down Expand Up @@ -150,7 +154,8 @@ def test_clean_dte_xml_ok_1(self) -> None:
self.assertSequenceEqual(
cm.exception.args,
("Element 'DTE': No matching global declaration available for the validation root., "
"line 2", )
"line 2."
f" cl-sii Python lib version {__version__}", )
)

xml_doc_cleaned, modified = clean_dte_xml(
Expand Down Expand Up @@ -224,7 +229,8 @@ def test_clean_dte_xml_ok_2(self) -> None:
self.assertSequenceEqual(
cm.exception.args,
("Element 'DTE': No matching global declaration available for the validation root., "
"line 2", )
"line 2."
f" cl-sii Python lib version {__version__}", )
)

xml_doc_cleaned, modified = clean_dte_xml(
Expand Down Expand Up @@ -298,7 +304,8 @@ def test_clean_dte_xml_ok_3(self) -> None:
self.assertSequenceEqual(
cm.exception.args,
("Element 'DTE': No matching global declaration available for the validation root., "
"line 2", )
"line 2."
f" cl-sii Python lib version {__version__}", )
)

xml_doc_cleaned, modified = clean_dte_xml(
Expand Down

0 comments on commit cc0a347

Please sign in to comment.