From 4cdcc243f76d89d3fa30ced39bf777c50f8029c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Wed, 13 Mar 2024 22:48:37 +0100 Subject: [PATCH] test.adapter.json: add `BytesIO` test --- ...test_json_serialization_deserialization.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/adapter/json/test_json_serialization_deserialization.py b/test/adapter/json/test_json_serialization_deserialization.py index 2d64af353..351b71845 100644 --- a/test/adapter/json/test_json_serialization_deserialization.py +++ b/test/adapter/json/test_json_serialization_deserialization.py @@ -16,6 +16,8 @@ example_aas_mandatory_attributes, example_submodel_template, create_example from basyx.aas.examples.data._helper import AASDataChecker +from typing import Iterable, IO + class JsonSerializationDeserializationTest(unittest.TestCase): def test_random_object_serialization_deserialization(self) -> None: @@ -41,15 +43,17 @@ def test_random_object_serialization_deserialization(self) -> None: 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() - 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 = read_aas_json_file(file, failsafe=False) - checker = AASDataChecker(raise_immediately=True) - example_aas.check_full_example(checker, json_object_store) + # test with TextIO and BinaryIO, which should both be supported + t: Iterable[IO] = (io.StringIO(), io.BytesIO()) + for file in t: + data = example_aas.create_full_example() + 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 = read_aas_json_file(file, failsafe=False) + checker = AASDataChecker(raise_immediately=True) + example_aas.check_full_example(checker, json_object_store) class JsonSerializationDeserializationTest2(unittest.TestCase):