Skip to content
Snippets Groups Projects
Commit e7a19bef authored by Benedikt's avatar Benedikt
Browse files

fixed return of JSONtoXML for no error case

parent a0fd8d31
No related branches found
No related tags found
No related merge requests found
Pipeline #50887 passed
...@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" ...@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "dccXMLJSONConv" name = "dccXMLJSONConv"
version = "3.0.0.dev6" version = "3.0.0.dev7"
description = "Python module for converting XML DCC (https://www.ptb.de/dcc/) to JSON and vice versa" description = "Python module for converting XML DCC (https://www.ptb.de/dcc/) to JSON and vice versa"
authors = [{name = "Benedikt Seeger,Thomas Bruns, Vanessa Stehr", email = "benedikt.seeger@ptb.de"}] authors = [{name = "Benedikt Seeger,Thomas Bruns, Vanessa Stehr", email = "benedikt.seeger@ptb.de"}]
license = {text = "LGPL-2.1-or-later"} license = {text = "LGPL-2.1-or-later"}
......
...@@ -133,6 +133,11 @@ class XMLSchemaConverter: ...@@ -133,6 +133,11 @@ class XMLSchemaConverter:
return xml_str, converted_element, conversion_result[1] return xml_str, converted_element, conversion_result[1]
else: else:
raise Exception(f"Validation errors: {errors}") raise Exception(f"Validation errors: {errors}")
elif len(errors)==0:
#evrything is fine
converted_element = conversion_result[0] # we take all since we had a complete XML tree
xml_str = xmlschema.etree_tostring(converted_element, namespaces=self.schema.namespaces)
return xml_str, conversion_result[0], conversion_result[1]
except Exception as e: except Exception as e:
warnings.warn(f"JSON->XML Validation error: {e}. Attempting template insertion.") warnings.warn(f"JSON->XML Validation error: {e}. Attempting template insertion.")
dictKeys=list(input_data.keys()) dictKeys=list(input_data.keys())
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest import pytest
from dccXMLJSONConv.dccConv import XMLToJson,JSONToXML from dccXMLJSONConv.dccConv import XMLToJson,JSONToXML,DictToXML
import os import os
import json import json
def test_XMLToJson(): def test_XMLToJson():
...@@ -40,5 +40,6 @@ def test_XMLToJsonFunction(): ...@@ -40,5 +40,6 @@ def test_XMLToJsonFunction():
print(xml) print(xml)
print("DONE") print("DONE")
#TODO add this as testcase with an file in this repo #TODO add this as testcase with an file in this repo
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment