|
11 | 11 | import tempfile |
12 | 12 | import unittest |
13 | 13 | import warnings |
| 14 | +from pathlib import Path |
14 | 15 |
|
15 | 16 | import pyecma376_2 |
16 | 17 | from basyx.aas import model |
@@ -207,6 +208,50 @@ def test_reading_core_properties(self) -> None: |
207 | 208 | finally: |
208 | 209 | os.unlink(filename) |
209 | 210 |
|
| 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 | + |
210 | 255 | def test_read_into(self) -> None: |
211 | 256 | filename = self._create_test_aasx() |
212 | 257 |
|
|
0 commit comments