Skip to content

Commit e6bb57c

Browse files
committed
Merge branch 'develop' of github.com:eclipse-basyx/basyx-python-sdk into fix/428
2 parents 1bb1c65 + 2e1932b commit e6bb57c

3 files changed

Lines changed: 107 additions & 7 deletions

File tree

etc/scripts/set_copyright_year.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# Run this script with --check to have it raise an error if it
1414
# would change anything.
1515

16+
# Initialise a variable to track if any error occurred
17+
EXIT_CODE=0
1618

1719
# Set CHECK_MODE based on whether --check is passed
1820
CHECK_MODE=false
@@ -33,7 +35,8 @@ while read -rd $'\0' year file; do
3335

3436
if $CHECK_MODE && [[ "$current_year" != "$year" ]]; then
3537
echo "Error: Copyright year mismatch in file $file. Expected $year, found $current_year."
36-
exit 1
38+
# Set ERROR_CODE to 1 to indicate mismatch
39+
ERROR_CODE=1
3740
fi
3841

3942
if ! $CHECK_MODE && [[ "$current_year" != "$year" ]]; then
@@ -42,3 +45,4 @@ while read -rd $'\0' year file; do
4245
fi
4346
done < <(git ls-files -z "$@" | xargs -0I{} git log -1 -z --format="%cd {}" --date="format:%Y" -- "{}")
4447

48+
exit $EXIT_CODE

sdk/basyx/aas/adapter/xml/xml_serialization.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2025 the Eclipse BaSyx Authors
1+
# Copyright (c) 2026 the Eclipse BaSyx Authors
22
#
33
# This program and the accompanying materials are made available under the terms of the MIT License, available in
44
# the LICENSE file of this project.
@@ -899,10 +899,6 @@ def object_to_xml_element(obj: object) -> etree._Element:
899899
return value_reference_pair_to_xml(obj)
900900
elif isinstance(obj, model.ConceptDescription):
901901
return concept_description_to_xml(obj)
902-
elif isinstance(obj, model.LangStringSet):
903-
# FIXME: `lang_string_set_to_xml` expects `tag` parameter, `tag` doesn't have default value
904-
# Issue: https://github.com/eclipse-basyx/basyx-python-sdk/issues/397
905-
return lang_string_set_to_xml(obj) # type: ignore[call-arg]
906902
elif isinstance(obj, model.EmbeddedDataSpecification):
907903
return embedded_data_specification_to_xml(obj)
908904
elif isinstance(obj, model.DataSpecificationIEC61360):

sdk/test/adapter/aasx/test_aasx.py

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2025 the Eclipse BaSyx Authors
1+
# Copyright (c) 2026 the Eclipse BaSyx Authors
22
#
33
# This program and the accompanying materials are made available under the terms of the MIT License, available in
44
# the LICENSE file of this project.
@@ -152,6 +152,106 @@ def test_writing_reading_example_aas(self) -> None:
152152
os.unlink(filename)
153153

154154

155+
class AASXReaderTest(unittest.TestCase):
156+
def _create_test_aasx(self) -> str:
157+
data = example_aas.create_full_example()
158+
files = aasx.DictSupplementaryFileContainer()
159+
160+
with open(os.path.join(os.path.dirname(__file__), 'TestFile.pdf'), 'rb') as f:
161+
files.add_file("/TestFile.pdf", f, "application/pdf")
162+
f.seek(0)
163+
164+
# Core properties
165+
cp = pyecma376_2.OPCCoreProperties()
166+
cp.created = datetime.datetime.now()
167+
cp.creator = "Eclipse BaSyx Python Testing Framework"
168+
169+
fd, filename = tempfile.mkstemp(suffix=".aasx")
170+
os.close(fd)
171+
172+
with aasx.AASXWriter(filename) as writer:
173+
writer.write_aas(
174+
'https://acplt.org/Test_AssetAdministrationShell',
175+
data, files, write_json=False
176+
)
177+
writer.write_core_properties(cp)
178+
179+
return filename
180+
181+
def test_init_file_handling(self) -> None:
182+
# Missing file assertion test
183+
with self.assertRaises(FileNotFoundError):
184+
aasx.AASXReader("does_not_exist.aasx")
185+
186+
# Invalid file assertion test
187+
fd, invalid_path = tempfile.mkstemp()
188+
os.write(fd, b"not a file")
189+
os.close(fd)
190+
191+
try:
192+
with self.assertRaises(ValueError):
193+
aasx.AASXReader(invalid_path)
194+
finally:
195+
os.unlink(invalid_path)
196+
197+
def test_reading_core_properties(self) -> None:
198+
filename = self._create_test_aasx()
199+
200+
try:
201+
with aasx.AASXReader(filename) as reader:
202+
cp = reader.get_core_properties()
203+
204+
self.assertIsInstance(cp.created, datetime.datetime)
205+
self.assertEqual(cp.creator, "Eclipse BaSyx Python Testing Framework")
206+
self.assertIsNone(cp.lastModifiedBy)
207+
finally:
208+
os.unlink(filename)
209+
210+
def test_read_into(self) -> None:
211+
filename = self._create_test_aasx()
212+
213+
try:
214+
objects: model.DictObjectStore[model.Identifiable] = model.DictObjectStore()
215+
files = aasx.DictSupplementaryFileContainer()
216+
217+
with warnings.catch_warnings(record=True) as w:
218+
with aasx.AASXReader(filename) as reader:
219+
ids = reader.read_into(objects, files)
220+
221+
assert isinstance(w, list)
222+
self.assertEqual(0, len(w)) # Ensure no warnings were raised
223+
224+
self.assertGreater(len(ids), 0) # Ensure at least one AAS was read
225+
self.assertGreater(len(objects), 0) # Ensure objects were populated
226+
self.assertGreater(len(files), 0)
227+
self.assertEqual(
228+
files.get_content_type("/TestFile.pdf"),
229+
"application/pdf"
230+
)
231+
finally:
232+
os.unlink(filename)
233+
234+
def test_supplementary_file_integrity(self) -> None:
235+
filename = self._create_test_aasx()
236+
237+
try:
238+
objects: model.DictObjectStore[model.Identifiable] = model.DictObjectStore()
239+
files = aasx.DictSupplementaryFileContainer()
240+
241+
with aasx.AASXReader(filename) as reader:
242+
reader.read_into(objects, files)
243+
244+
buf = io.BytesIO()
245+
files.write_file("/TestFile.pdf", buf)
246+
247+
self.assertEqual(
248+
hashlib.sha1(buf.getvalue()).hexdigest(),
249+
"78450a66f59d74c073bf6858db340090ea72a8b1"
250+
)
251+
finally:
252+
os.unlink(filename)
253+
254+
155255
class AASXWriterReferencedSubmodelsTest(unittest.TestCase):
156256

157257
def test_only_referenced_submodels(self):

0 commit comments

Comments
 (0)