Skip to content

Commit

Permalink
test.adapter.json: add BytesIO test
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhsjdhjs committed Mar 13, 2024
1 parent 40b420c commit 77846ff
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions test/adapter/json/test_json_serialization_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 77846ff

Please sign in to comment.