diff --git a/README.md b/README.md index 6b933edf30ac4063b9120df25893fb20440848fa..2094113529de67266925e82f42d5626b20d0ec89 100644 --- a/README.md +++ b/README.md @@ -87,12 +87,12 @@ submodel.submodel_element.add(property) Serialize the `Submodel` to XML: ```python -import aas.adapter.xml.xml_serialization +from aas.adapter.xml import write_aas_xml_file data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() data.add(submodel) with open('Simple_Submodel.xml', 'w', encoding='utf-8') as f: - aas.adapter.xml.xml_serialization.write_aas_xml_file(file=f, data=data) + write_aas_xml_file(file=f, data=data) ``` diff --git a/aas/adapter/__init__.py b/aas/adapter/__init__.py index 6d19622cda1bba72ced87c201c40d447a4386f0c..0f42cc4aa56e48cc8a52af8917f7535e38e441d3 100644 --- a/aas/adapter/__init__.py +++ b/aas/adapter/__init__.py @@ -1,6 +1,8 @@ """ -This package contains different kind of adapter +This package contains different kinds of adapters. json - This package offers an adapter for serialization and deserialization of PyAAS objects to/from JSON + This package offers an adapter for serialization and deserialization of PyAAS objects to/from JSON. +xml + This package offers an adapter for serialization and deserialization of PyAAS objects to/from XML. """ diff --git a/aas/adapter/aasx.py b/aas/adapter/aasx.py index 65f170e637a22d1b56ee9f5bcc425277fa2f5f16..52db992efd778d69f868e44f9db09c1fecce0f60 100644 --- a/aas/adapter/aasx.py +++ b/aas/adapter/aasx.py @@ -31,8 +31,7 @@ import re from typing import Dict, Tuple, IO, Union, List, Set, Optional from .. import model -from .json.json_deserialization import read_json_aas_file -from .json.json_serialization import write_aas_json_file +from .json import read_aas_json_file, write_aas_json_file import pyecma376_2 from ..util import traversal @@ -212,7 +211,7 @@ class AASXReader: or content_type == "" and extension == "json": logger.debug("Parsing AAS objects from JSON stream in OPC part {} ...".format(part_name)) with self.reader.open_part(part_name) as p: - return read_json_aas_file(io.TextIOWrapper(p, encoding='utf-8-sig')) + return read_aas_json_file(io.TextIOWrapper(p, encoding='utf-8-sig')) else: logger.error("Could not determine part format of AASX part {} (Content Type: {}, extension: {}" .format(part_name, content_type, extension)) diff --git a/aas/adapter/couchdb.py b/aas/adapter/couchdb.py index 7380f66d8c23d4b210c2796bda174f926fbf2523..b52cc38b8266c2357e26e1b51d999ff858203469 100644 --- a/aas/adapter/couchdb.py +++ b/aas/adapter/couchdb.py @@ -50,7 +50,7 @@ import threading import logging from .. import model -from .json import json_serialization, json_deserialization +from .json import StrictAASFromJsonDecoder, AASToJsonEncoder logger = logging.getLogger(__name__) @@ -194,7 +194,7 @@ class CouchDBObjectStore(model.AbstractObjectStore): """ logger.debug("Adding object %s to CouchDB database ...", repr(x)) # Serialize data - data = json.dumps({'data': x}, cls=json_serialization.AASToJsonEncoder) + data = json.dumps({'data': x}, cls=AASToJsonEncoder) # Create and issue HTTP request (raises HTTPError on status != 200) request = urllib.request.Request( @@ -222,7 +222,7 @@ class CouchDBObjectStore(model.AbstractObjectStore): logger.debug("Committing changes of object %s based on revision %s to CouchDB database ...", repr(x), x.couchdb_revision) # Serialize data - data = json.dumps({'data': x, '_rev': x.couchdb_revision}, cls=json_serialization.AASToJsonEncoder) + data = json.dumps({'data': x, '_rev': x.couchdb_revision}, cls=AASToJsonEncoder) # Create and issue HTTP request (raises HTTPError on status != 200) request = urllib.request.Request( @@ -468,7 +468,7 @@ class CouchDBSubmodel(model.Submodel, CouchDBIdentifiable): pass -class CouchDBJSONDecoder(json_deserialization.StrictAASFromJsonDecoder): +class CouchDBJSONDecoder(StrictAASFromJsonDecoder): """ Special json.JSONDecoder class for deserializing AAS objects received from the CouchDB server diff --git a/aas/adapter/json/__init__.py b/aas/adapter/json/__init__.py index 596d1fe15cd723662a86bbb47aaec13054a97945..b84dee05597c4a27ebb92afd78077d11ff24d711 100644 --- a/aas/adapter/json/__init__.py +++ b/aas/adapter/json/__init__.py @@ -12,3 +12,6 @@ json_deserialization.py PyI40AAS object. A function `read_json_aas_file()` is provided to read all AAS objects within a JSON file and return them as PyI40AAS ObjectStore. """ + +from .json_serialization import AASToJsonEncoder, write_aas_json_file, object_store_to_json +from .json_deserialization import StrictAASFromJsonDecoder, AASFromJsonDecoder, read_aas_json_file diff --git a/aas/adapter/json/json_deserialization.py b/aas/adapter/json/json_deserialization.py index addd8741b2dd823438200b281a2d69ca76ab3964..2c29728a83144eb95e83adfda49bc8b46c8e4108 100644 --- a/aas/adapter/json/json_deserialization.py +++ b/aas/adapter/json/json_deserialization.py @@ -675,7 +675,7 @@ class StrictAASFromJsonDecoder(AASFromJsonDecoder): failsafe = False -def read_json_aas_file(file: IO, failsafe: bool = True) -> model.DictObjectStore: +def read_aas_json_file(file: IO, failsafe: bool = True) -> model.DictObjectStore: """ Read an Asset Adminstration Shell JSON file according to 'Details of the Asset Administration Shell', chapter 5.5 diff --git a/aas/adapter/xml/__init__.py b/aas/adapter/xml/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..795a355a01c8a8f55867603e1a2702f919c2417e 100644 --- a/aas/adapter/xml/__init__.py +++ b/aas/adapter/xml/__init__.py @@ -0,0 +1,11 @@ +""" +This package contains functionality for serialization and deserialization of PyI40AAS objects into/from XML. + +xml_serialization: + The module offers a function to write an ObjectStore to a given file. + +xml_deserialization.py + The module offers a function to create an ObjectStore from a given xml document. +""" + +from .xml_serialization import write_aas_xml_file diff --git a/aas/compliance_tool/cli.py b/aas/compliance_tool/cli.py index 87109fdf5c51db18985d617086b8c2c00b1ae97f..0ff65a040d2ede85712ce4d49a902dd01082ea9f 100644 --- a/aas/compliance_tool/cli.py +++ b/aas/compliance_tool/cli.py @@ -19,7 +19,7 @@ import argparse import logging from aas.compliance_tool import compliance_check_json as compliance_tool_json -from aas.adapter.json import json_serialization +from aas.adapter.json import write_aas_json_file from aas.examples.data import create_example from aas.compliance_tool.state_manager import ComplianceToolStateManager, Status @@ -68,7 +68,7 @@ def main(): manager.add_step('Write data to file') if args.json: - json_serialization.write_aas_json_file(file=file, data=data) + write_aas_json_file(file=file, data=data) manager.set_step_status(Status.SUCCESS) elif args.xml: # Todo: if xml serialization is done add code here diff --git a/aas/compliance_tool/compliance_check_json.py b/aas/compliance_tool/compliance_check_json.py index 7d58092722274c63316867d001e4e53ccfa9e049..d2a83711d5bea76da810a4b97a2ca5f6144f4780 100644 --- a/aas/compliance_tool/compliance_check_json.py +++ b/aas/compliance_tool/compliance_check_json.py @@ -146,7 +146,7 @@ def check_deserialization(file_path: str, state_manager: ComplianceToolStateMana state_manager.add_step('Read {} file and check if it is conform to the json schema'.format(file_info)) else: state_manager.add_step('Read file and check if it is conform to the json schema') - obj_store = json_deserialization.read_json_aas_file(file_to_be_checked, True) + obj_store = json_deserialization.read_aas_json_file(file_to_be_checked, True) state_manager.set_step_status_from_log() diff --git a/aas/examples/tutorial_serialization_deserialization_json.py b/aas/examples/tutorial_serialization_deserialization_json.py index 3416bedb70d5254fe6e2e1746e3704f396b75f1f..37c3be14cc966d1dc9561e17fd5a0ca009531bee 100755 --- a/aas/examples/tutorial_serialization_deserialization_json.py +++ b/aas/examples/tutorial_serialization_deserialization_json.py @@ -10,7 +10,7 @@ import json # Import all PyI40AAS classes from model package from aas import model -from aas.adapter.json import json_serialization, json_deserialization +from aas.adapter.json import AASToJsonEncoder, read_aas_json_file, write_aas_json_file, object_store_to_json from aas.model import Asset, AssetAdministrationShell, Submodel # In this tutorial you get a step by step guide how to serialize objects of the meta model according to @@ -58,13 +58,13 @@ aas = AssetAdministrationShell( # step 2: serialize an object to json and write it to file # ############################################################ # step 2.1: serialize an object to json -# json_serialization.AASToJsonEncoder is a custom JSONDecoder class for serializing Asset Administration Shell data +# AASToJsonEncoder is a custom JSONDecoder class for serializing Asset Administration Shell data # into the official JSON format according to 'Details of the Asset Administration Shell', chapter 5.5 # serialize an asset administration shell -json_data_object = json.loads(json.dumps(aas, cls=json_serialization.AASToJsonEncoder)) +json_data_object = json.loads(json.dumps(aas, cls=AASToJsonEncoder)) # serialize a property json_data_object = json.loads(json.dumps(submodel.submodel_element.get_referable('ExampleProperty'), - cls=json_serialization.AASToJsonEncoder)) + cls=AASToJsonEncoder)) # step 2.2: write json data to file # define a file stream, here an internal file stream is used. For an external file stream use # 'open('tutorial.json', 'w', encoding='utf-8')' for opening a json-File to write json data inside @@ -82,8 +82,8 @@ obj_store: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() obj_store.add(asset) obj_store.add(submodel) obj_store.add(aas) -# serialize the store using the function 'object_store_to_json' of the 'json_serialization' module -json_data_store = json_serialization.object_store_to_json(obj_store) +# serialize the store using the function 'object_store_to_json' of the 'json' module +json_data_store = object_store_to_json(obj_store) # step 2.2: write json data to file # define a file stream, here an internal file stream is used. For an external file stream use # 'open('tutorial.json', 'w', encoding='utf-8')' for opening a json-File to write json data inside @@ -93,7 +93,7 @@ json.dump(json_data_store, file_store) # serialize an object store and write it to a file can be done in one step using the function 'write_aas_json_file' file_store_2 = io.StringIO() -json_serialization.write_aas_json_file(file=file_store_2, data=obj_store) +write_aas_json_file(file=file_store_2, data=obj_store) ################################################################################################# # step 4: # read a json string from file and deserialize it into an object store of AAS objects # @@ -103,7 +103,7 @@ json_serialization.write_aas_json_file(file=file_store_2, data=obj_store) # we have to set the file pointer to the beginning cause we are using the same file stream. Normally, you do not need # to do this. file_store_2.seek(0) -json_object_store = json_deserialization.read_json_aas_file(file_store_2, failsafe=False) +json_object_store = read_aas_json_file(file_store_2, failsafe=False) # take a submodel out of the object store, for more details look at 'tutorial_storage.py' tmp_submodel: Submodel = json_object_store.get_identifiable( # type: ignore diff --git a/test/adapter/json/test_json_deserialization.py b/test/adapter/json/test_json_deserialization.py index 1de7c183af0132468a65f87603d3bd4824b00cbb..13caee01b5898d1d91d885794f854fd6ed8cd7f6 100644 --- a/test/adapter/json/test_json_deserialization.py +++ b/test/adapter/json/test_json_deserialization.py @@ -19,7 +19,7 @@ import io import json import logging import unittest -from aas.adapter.json import json_deserialization +from aas.adapter.json import AASFromJsonDecoder, StrictAASFromJsonDecoder, read_aas_json_file from aas import model @@ -32,9 +32,9 @@ class JsonDeserializationTest(unittest.TestCase): "conceptDescriptions": [] }""" with self.assertRaisesRegex(KeyError, r"submodels"): - json_deserialization.read_json_aas_file(io.StringIO(data), False) + read_aas_json_file(io.StringIO(data), False) with self.assertLogs(logging.getLogger(), level=logging.WARNING) as cm: - json_deserialization.read_json_aas_file(io.StringIO(data), True) + read_aas_json_file(io.StringIO(data), True) self.assertIn("submodels", cm.output[0]) def test_file_format_wrong_list(self) -> None: @@ -57,9 +57,9 @@ class JsonDeserializationTest(unittest.TestCase): ] }""" with self.assertRaisesRegex(TypeError, r"submodels.*Asset"): - json_deserialization.read_json_aas_file(io.StringIO(data), False) + read_aas_json_file(io.StringIO(data), False) with self.assertLogs(logging.getLogger(), level=logging.WARNING) as cm: - json_deserialization.read_json_aas_file(io.StringIO(data), True) + read_aas_json_file(io.StringIO(data), True) self.assertIn("submodels", cm.output[0]) self.assertIn("Asset", cm.output[0]) @@ -74,9 +74,9 @@ class JsonDeserializationTest(unittest.TestCase): ] }""" with self.assertRaisesRegex(TypeError, r"submodels.*'foo'"): - json_deserialization.read_json_aas_file(io.StringIO(data), False) + read_aas_json_file(io.StringIO(data), False) with self.assertLogs(logging.getLogger(), level=logging.WARNING) as cm: - json_deserialization.read_json_aas_file(io.StringIO(data), True) + read_aas_json_file(io.StringIO(data), True) self.assertIn("submodels", cm.output[0]) self.assertIn("'foo'", cm.output[0]) @@ -100,11 +100,11 @@ class JsonDeserializationTest(unittest.TestCase): ]""" # In strict mode, we should catch an exception with self.assertRaisesRegex(KeyError, r"identification"): - json.loads(data, cls=json_deserialization.StrictAASFromJsonDecoder) + json.loads(data, cls=StrictAASFromJsonDecoder) # In failsafe mode, we should get a log entry and the first Asset entry should be returned as untouched dict with self.assertLogs(logging.getLogger(), level=logging.WARNING) as cm: - parsed_data = json.loads(data, cls=json_deserialization.AASFromJsonDecoder) + parsed_data = json.loads(data, cls=AASFromJsonDecoder) self.assertIn("identification", cm.output[0]) self.assertIsInstance(parsed_data, list) self.assertEqual(3, len(parsed_data)) @@ -143,13 +143,13 @@ class JsonDeserializationTest(unittest.TestCase): # The broken object should not raise an exception, but log a warning, even in strict mode. with self.assertLogs(logging.getLogger(), level=logging.WARNING) as cm: with self.assertRaisesRegex(TypeError, r"SubmodelElement.*Asset"): - json.loads(data, cls=json_deserialization.StrictAASFromJsonDecoder) + json.loads(data, cls=StrictAASFromJsonDecoder) self.assertIn("modelType", cm.output[0]) # In failsafe mode, we should get a log entries for the broken object and the wrong type of the first two # submodelElements with self.assertLogs(logging.getLogger(), level=logging.WARNING) as cm: - parsed_data = json.loads(data, cls=json_deserialization.AASFromJsonDecoder) + parsed_data = json.loads(data, cls=AASFromJsonDecoder) self.assertGreaterEqual(len(cm.output), 3) self.assertIn("SubmodelElement", cm.output[1]) self.assertIn("SubmodelElement", cm.output[2]) @@ -168,7 +168,7 @@ class JsonDeserializationDerivingTest(unittest.TestCase): super().__init__(**kwargs) self.enhanced_attribute = "fancy!" - class EnhancedAASDecoder(json_deserialization.AASFromJsonDecoder): + class EnhancedAASDecoder(AASFromJsonDecoder): @classmethod def _construct_asset(cls, dct): return super()._construct_asset(dct, object_class=EnhancedAsset) diff --git a/test/adapter/json/test_json_serialization.py b/test/adapter/json/test_json_serialization.py index 0a86fabf571251d4af5f3f9f9f17e2b93c51835d..112a2b6d80e7e98ba89afac3eb0b43517c3653f4 100644 --- a/test/adapter/json/test_json_serialization.py +++ b/test/adapter/json/test_json_serialization.py @@ -15,7 +15,7 @@ import json import os from aas import model -from aas.adapter.json import json_serialization +from aas.adapter.json import AASToJsonEncoder, write_aas_json_file from jsonschema import validate # type: ignore from aas.examples.data import example_aas_missing_attributes, example_submodel_template, \ @@ -28,7 +28,7 @@ class JsonSerializationTest(unittest.TestCase): def test_serialize_object(self) -> None: test_object = model.Property("test_id_short", model.datatypes.String, category="PARAMETER", description={"en-us": "Germany", "de": "Deutschland"}) - json_data = json.dumps(test_object, cls=json_serialization.AASToJsonEncoder) + json_data = json.dumps(test_object, cls=AASToJsonEncoder) def test_random_object_serialization(self) -> None: asset_key = (model.Key(model.KeyElements.ASSET, True, "asset", model.KeyType.CUSTOM),) @@ -47,7 +47,7 @@ class JsonSerializationTest(unittest.TestCase): 'submodels': [submodel], 'assets': [], 'conceptDescriptions': [], - }, cls=json_serialization.AASToJsonEncoder) + }, cls=AASToJsonEncoder) json_data_new = json.loads(json_data) @@ -72,7 +72,7 @@ class JsonSerializationSchemaTest(unittest.TestCase): 'submodels': [submodel], 'assets': [], 'conceptDescriptions': [], - }, cls=json_serialization.AASToJsonEncoder) + }, cls=AASToJsonEncoder) json_data_new = json.loads(json_data) # load schema @@ -85,7 +85,7 @@ class JsonSerializationSchemaTest(unittest.TestCase): def test_aas_example_serialization(self) -> None: data = example_aas.create_full_example() file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) + write_aas_json_file(file=file, data=data) with open(JSON_SCHEMA_FILE, 'r') as json_file: aas_json_schema = json.load(json_file) @@ -100,7 +100,7 @@ class JsonSerializationSchemaTest(unittest.TestCase): data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() data.add(example_submodel_template.create_example_submodel_template()) file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) + write_aas_json_file(file=file, data=data) with open(JSON_SCHEMA_FILE, 'r') as json_file: aas_json_schema = json.load(json_file) @@ -114,7 +114,7 @@ class JsonSerializationSchemaTest(unittest.TestCase): def test_full_empty_example_serialization(self) -> None: data = example_aas_mandatory_attributes.create_full_example() file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) + write_aas_json_file(file=file, data=data) with open(JSON_SCHEMA_FILE, 'r') as json_file: aas_json_schema = json.load(json_file) @@ -128,7 +128,7 @@ class JsonSerializationSchemaTest(unittest.TestCase): def test_missing_serialization(self) -> None: data = example_aas_missing_attributes.create_full_example() file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) + write_aas_json_file(file=file, data=data) with open(JSON_SCHEMA_FILE, 'r') as json_file: aas_json_schema = json.load(json_file) @@ -143,7 +143,7 @@ class JsonSerializationSchemaTest(unittest.TestCase): data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() data.add(example_concept_description.create_iec61360_concept_description()) file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) + write_aas_json_file(file=file, data=data) with open(JSON_SCHEMA_FILE, 'r') as json_file: aas_json_schema = json.load(json_file) @@ -157,7 +157,7 @@ class JsonSerializationSchemaTest(unittest.TestCase): def test_full_example_serialization(self) -> None: data = create_example() file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) + write_aas_json_file(file=file, data=data) with open(JSON_SCHEMA_FILE, 'r') as json_file: aas_json_schema = json.load(json_file) diff --git a/test/adapter/json/test_json_serialization_deserialization.py b/test/adapter/json/test_json_serialization_deserialization.py index cce19f4d53f6e914827148abb645f30f9b4aa08b..980348bbec979c9b7b1ac6ef9b5ccfd18d29a64c 100644 --- a/test/adapter/json/test_json_serialization_deserialization.py +++ b/test/adapter/json/test_json_serialization_deserialization.py @@ -15,7 +15,7 @@ import os import unittest from aas import model -from aas.adapter.json import json_serialization, json_deserialization +from aas.adapter.json import AASToJsonEncoder, write_aas_json_file, read_aas_json_file from aas.examples.data import example_aas_missing_attributes, example_submodel_template, \ example_aas_mandatory_attributes, example_aas, example_concept_description @@ -41,22 +41,20 @@ class JsonSerializationDeserializationTest(unittest.TestCase): 'submodels': [submodel], 'assets': [], 'conceptDescriptions': [], - }, cls=json_serialization.AASToJsonEncoder) + }, cls=AASToJsonEncoder) json_data_new = json.loads(json_data) - # try deserializing the json string into a DictObjectStore of AAS objects with help of the json_deserialization - # module - json_object_store = json_deserialization.read_json_aas_file(io.StringIO(json_data), failsafe=False) + # try deserializing the json string into a DictObjectStore of AAS objects with help of the json module + json_object_store = read_aas_json_file(io.StringIO(json_data), failsafe=False) def test_example_serialization_deserialization(self) -> None: data = example_aas.create_full_example() file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) + write_aas_json_file(file=file, data=data) - # try deserializing the json string into a DictObjectStore of AAS objects with help of the json_deserialization - # module + # try deserializing the json string into a DictObjectStore of AAS objects with help of the json module file.seek(0) - json_object_store = json_deserialization.read_json_aas_file(file, failsafe=False) + json_object_store = read_aas_json_file(file, failsafe=False) checker = AASDataChecker(raise_immediately=True) example_aas.check_full_example(checker, json_object_store) @@ -65,12 +63,11 @@ class JsonSerializationDeserializationTest2(unittest.TestCase): def test_example_mandatory_attributes_serialization_deserialization(self) -> None: data = example_aas_mandatory_attributes.create_full_example() file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) + write_aas_json_file(file=file, data=data) - # try deserializing the json string into a DictObjectStore of AAS objects with help of the json_deserialization - # module + # try deserializing the json string into a DictObjectStore of AAS objects with help of the json module file.seek(0) - json_object_store = json_deserialization.read_json_aas_file(file, failsafe=False) + json_object_store = read_aas_json_file(file, failsafe=False) checker = AASDataChecker(raise_immediately=True) example_aas_mandatory_attributes.check_full_example(checker, json_object_store) @@ -79,11 +76,10 @@ class JsonSerializationDeserializationTest3(unittest.TestCase): def test_example_missing_attributes_serialization_deserialization(self) -> None: data = example_aas_missing_attributes.create_full_example() file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) - # try deserializing the json string into a DictObjectStore of AAS objects with help of the json_deserialization - # module + write_aas_json_file(file=file, data=data) + # try deserializing the json string into a DictObjectStore of AAS objects with help of the json module file.seek(0) - json_object_store = json_deserialization.read_json_aas_file(file, failsafe=False) + json_object_store = read_aas_json_file(file, failsafe=False) checker = AASDataChecker(raise_immediately=True) example_aas_missing_attributes.check_full_example(checker, json_object_store) @@ -93,11 +89,10 @@ class JsonSerializationDeserializationTest4(unittest.TestCase): data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() data.add(example_submodel_template.create_example_submodel_template()) file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) - # try deserializing the json string into a DictObjectStore of AAS objects with help of the json_deserialization - # module + write_aas_json_file(file=file, data=data) + # try deserializing the json string into a DictObjectStore of AAS objects with help of the json module file.seek(0) - json_object_store = json_deserialization.read_json_aas_file(file, failsafe=False) + json_object_store = read_aas_json_file(file, failsafe=False) checker = AASDataChecker(raise_immediately=True) example_submodel_template.check_full_example(checker, json_object_store) @@ -107,10 +102,9 @@ class JsonSerializationDeserializationTest5(unittest.TestCase): data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() data.add(example_concept_description.create_iec61360_concept_description()) file = io.StringIO() - json_serialization.write_aas_json_file(file=file, data=data) - # try deserializing the json string into a DictObjectStore of AAS objects with help of the json_deserialization - # module + write_aas_json_file(file=file, data=data) + # try deserializing the json string into a DictObjectStore of AAS objects with help of the json module file.seek(0) - json_object_store = json_deserialization.read_json_aas_file(file, failsafe=False) + json_object_store = read_aas_json_file(file, failsafe=False) checker = AASDataChecker(raise_immediately=True) example_concept_description.check_full_example(checker, json_object_store) diff --git a/test/adapter/xml/test_xml_serialization.py b/test/adapter/xml/test_xml_serialization.py index d9ad656fcb8fe6cd12b74a3f464993b66322c66c..8b0676b5b603483127af5336dc9e50fd73b8e388 100644 --- a/test/adapter/xml/test_xml_serialization.py +++ b/test/adapter/xml/test_xml_serialization.py @@ -14,7 +14,7 @@ from lxml import etree # type: ignore import os from aas import model -from aas.adapter.xml import xml_serialization +from aas.adapter.xml import write_aas_xml_file, xml_serialization from aas.examples.data import example_aas_missing_attributes, example_submodel_template, \ example_aas_mandatory_attributes, example_aas, example_concept_description @@ -47,7 +47,7 @@ class XMLSerializationTest(unittest.TestCase): test_data.add(submodel) test_file = io.BytesIO() - xml_serialization.write_aas_xml_file(file=test_file, data=test_data) + write_aas_xml_file(file=test_file, data=test_data) @unittest.skipUnless(os.path.exists(XML_SCHEMA_FILE), "XML Schema not found for validation") @@ -69,7 +69,7 @@ class XMLSerializationSchemaTest(unittest.TestCase): test_data.add(submodel) test_file = io.BytesIO() - xml_serialization.write_aas_xml_file(file=test_file, data=test_data) + write_aas_xml_file(file=test_file, data=test_data) # load schema aas_schema = etree.XMLSchema(file=XML_SCHEMA_FILE) @@ -82,7 +82,7 @@ class XMLSerializationSchemaTest(unittest.TestCase): def test_full_example_serialization(self) -> None: data = example_aas.create_full_example() file = io.BytesIO() - xml_serialization.write_aas_xml_file(file=file, data=data) + write_aas_xml_file(file=file, data=data) # load schema aas_schema = etree.XMLSchema(file=XML_SCHEMA_FILE) @@ -96,7 +96,7 @@ class XMLSerializationSchemaTest(unittest.TestCase): data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() data.add(example_submodel_template.create_example_submodel_template()) file = io.BytesIO() - xml_serialization.write_aas_xml_file(file=file, data=data) + write_aas_xml_file(file=file, data=data) # load schema aas_schema = etree.XMLSchema(file=XML_SCHEMA_FILE) @@ -109,7 +109,7 @@ class XMLSerializationSchemaTest(unittest.TestCase): def test_full_empty_example_serialization(self) -> None: data = example_aas_mandatory_attributes.create_full_example() file = io.BytesIO() - xml_serialization.write_aas_xml_file(file=file, data=data) + write_aas_xml_file(file=file, data=data) # load schema aas_schema = etree.XMLSchema(file=XML_SCHEMA_FILE) @@ -122,7 +122,7 @@ class XMLSerializationSchemaTest(unittest.TestCase): def test_missing_serialization(self) -> None: data = example_aas_missing_attributes.create_full_example() file = io.BytesIO() - xml_serialization.write_aas_xml_file(file=file, data=data) + write_aas_xml_file(file=file, data=data) # load schema aas_schema = etree.XMLSchema(file=XML_SCHEMA_FILE) @@ -136,7 +136,7 @@ class XMLSerializationSchemaTest(unittest.TestCase): data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() data.add(example_concept_description.create_iec61360_concept_description()) file = io.BytesIO() - xml_serialization.write_aas_xml_file(file=file, data=data) + write_aas_xml_file(file=file, data=data) # load schema aas_schema = etree.XMLSchema(file=XML_SCHEMA_FILE) diff --git a/test/compliance_tool/test_aas_compliance_tool.py b/test/compliance_tool/test_aas_compliance_tool.py index f09b52613d3d9b0f4d05889c8a4cb8d56a74ca2f..9f059918a1a14871117e0745b93f4a0ddd349aab 100644 --- a/test/compliance_tool/test_aas_compliance_tool.py +++ b/test/compliance_tool/test_aas_compliance_tool.py @@ -15,7 +15,7 @@ import unittest import aas.compliance_tool import tempfile -from aas.adapter.json import json_deserialization +from aas.adapter.json import read_aas_json_file from aas.examples.data import create_example from aas.examples.data._helper import AASDataChecker @@ -145,7 +145,7 @@ class ComplianceToolTest(unittest.TestCase): self.assertIn('SUCCESS: Write data to file', str(output.stdout)) with open(filename, "r", encoding='utf-8-sig') as f: - json_object_store = json_deserialization.read_json_aas_file(f, failsafe=False) + json_object_store = read_aas_json_file(f, failsafe=False) data = create_example() checker = AASDataChecker(raise_immediately=True) checker.check_object_store(json_object_store, data) @@ -207,7 +207,7 @@ class ComplianceToolTest(unittest.TestCase): self.assertIn('SUCCESS: Write data to file', str(output.stdout)) with open(filename, "r", encoding='utf-8-sig') as f: - json_object_store = json_deserialization.read_json_aas_file(f, failsafe=False) + json_object_store = read_aas_json_file(f, failsafe=False) data = create_example() checker = AASDataChecker(raise_immediately=True) checker.check_object_store(json_object_store, data)