Skip to content

Commit 4360660

Browse files
committed
sdk test: add ASSXReader get_thumbnail test
The method get_thumbnail() of the AASXReader class was not covered by unit tests at all. This commit adds full coverage.
1 parent 66b1943 commit 4360660

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

sdk/test/adapter/aasx/test.png

834 Bytes
Loading

sdk/test/adapter/aasx/test_aasx.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import tempfile
1212
import unittest
1313
import warnings
14+
from pathlib import Path
1415

1516
import pyecma376_2
1617
from basyx.aas import model
@@ -207,6 +208,50 @@ def test_reading_core_properties(self) -> None:
207208
finally:
208209
os.unlink(filename)
209210

211+
def test_get_thumbnail(self) -> None:
212+
with tempfile.TemporaryDirectory() as tmpdir:
213+
# ---- Arange ----
214+
tmpdir_path = Path(tmpdir)
215+
216+
data = model.DictIdentifiableStore([
217+
model.AssetAdministrationShell(
218+
id_="http://example.org/Test_AAS",
219+
asset_information=model.AssetInformation(
220+
global_asset_id="http://example.org/Test_Asset"
221+
)
222+
)
223+
])
224+
225+
with aasx.AASXWriter(tmpdir_path / "test_thumbnail.aasx") as writer:
226+
writer.write_aas(
227+
'http://example.org/Test_AAS',
228+
data, aasx.DictSupplementaryFileContainer(), write_json=False
229+
)
230+
with open(Path(__file__).parent / "test.png", "rb") as png:
231+
thumbnail = png.read()
232+
writer.write_thumbnail("/aasx/thumbnail.png", bytearray(thumbnail), "image/png")
233+
234+
# ---- Act ----
235+
with aasx.AASXReader(tmpdir_path / "test_thumbnail.aasx") as reader:
236+
new_thumbnail = reader.get_thumbnail()
237+
238+
# ---- Assert ----
239+
self.assertEqual(new_thumbnail, thumbnail)
240+
241+
def test_missing_thumbnail(self) -> None:
242+
# ---- Arange ----
243+
filename = self._create_test_aasx()
244+
245+
try:
246+
# ---- Act ----
247+
with aasx.AASXReader(filename) as reader:
248+
thumbnail = reader.get_thumbnail()
249+
250+
# ---- Assert ----
251+
self.assertIsNone(thumbnail)
252+
finally:
253+
os.unlink(filename)
254+
210255
def test_read_into(self) -> None:
211256
filename = self._create_test_aasx()
212257

0 commit comments

Comments
 (0)