Skip to content

Commit 79625a9

Browse files
committed
compliance_tool: fix aasx file equivalence
Previously the aasx file equivalence check would 1. still execute subsequent steps if the loading of one file fails. This was caused by checking only if `state_manager.status is Status.FAILED`, missing that `Status.NOT_EXECUTED > Status.FAILED`. 2. use blank assertions to ensure core_properties `created` attribute is of type `datetime.datetime`. This resulted in the compliance_tool failing with `AssertionError` in cases that were caused by (1). Status guards for fast-failing are now corrected to take `Status.NOT_EXECUTED` into account. The assertions are removed and replaced with `DataChecker` checks to inform the user gracefully on problems. `cast(...)` is used to inform the type-checker about the `isinstance(...)` result.
1 parent d98b5a6 commit 79625a9

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

compliance_tool/aas_compliance_tool/compliance_check_aasx.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414
import datetime
1515
import logging
16-
from typing import Optional, Tuple
16+
from typing import Optional, Tuple, cast
1717
import io
1818
from lxml import etree # type: ignore
1919

@@ -224,7 +224,7 @@ def check_aasx_files_equivalence(file_path_1: str, file_path_2: str, state_manag
224224

225225
identifiable_store_2, files_2, cp_2 = check_deserialization(file_path_2, state_manager, 'second')
226226

227-
if state_manager.status is Status.FAILED:
227+
if state_manager.status >= Status.FAILED:
228228
state_manager.add_step('Check if data in files are equal')
229229
state_manager.set_step_status(Status.NOT_EXECUTED)
230230
state_manager.add_step('Check if core properties are equal')
@@ -244,18 +244,30 @@ def check_aasx_files_equivalence(file_path_1: str, file_path_2: str, state_manag
244244

245245
state_manager.add_log_records_from_data_checker(checker)
246246

247-
if state_manager.status is Status.FAILED:
247+
if state_manager.status >= Status.FAILED:
248248
state_manager.add_step('Check if core properties are equal')
249249
state_manager.set_step_status(Status.NOT_EXECUTED)
250250
return
251251

252252
state_manager.add_step('Check if core properties are equal')
253253
checker2 = DataChecker(raise_immediately=False)
254-
assert (isinstance(cp_1.created, datetime.datetime))
255-
assert (isinstance(cp_2.created, datetime.datetime))
256-
duration = cp_1.created - cp_2.created
254+
checker2.check(isinstance(cp_1.created, datetime.datetime),
255+
"core property created of first file must be of type datetime",
256+
created=type(cp_1.created))
257+
checker2.check(isinstance(cp_2.created, datetime.datetime),
258+
"core property created of second file must be of type datetime",
259+
created=type(cp_2.created))
260+
261+
if any(True for _ in checker2.failed_checks):
262+
state_manager.add_log_records_from_data_checker(checker2)
263+
return
264+
265+
duration = cast(datetime.datetime, cp_1.created) - cast(datetime.datetime, cp_2.created)
257266
checker2.check(duration.microseconds < 20, "created must be {}".format(cp_1.created), value=cp_2.created)
258267
checker2.check(cp_1.creator == cp_2.creator, "creator must be {}".format(cp_1.creator), value=cp_2.creator)
259268
checker2.check(cp_1.lastModifiedBy == cp_2.lastModifiedBy, "lastModifiedBy must be {}".format(cp_1.lastModifiedBy),
260269
value=cp_2.lastModifiedBy)
270+
checker2.check(cp_1.revision == cp_2.revision, "revision must be {}".format(cp_2.revision), revision=cp_1.revision)
271+
checker2.check(cp_1.version == cp_2.version, "version must be {}".format(cp_2.version), version=cp_1.version)
272+
checker2.check(cp_1.title == cp_2.title, "title must be {}".format(cp_2.title), title=cp_1.title)
261273
state_manager.add_log_records_from_data_checker(checker2)

0 commit comments

Comments
 (0)