-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathtest_compliance_check_aasx.py
More file actions
173 lines (151 loc) · 9.35 KB
/
test_compliance_check_aasx.py
File metadata and controls
173 lines (151 loc) · 9.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Copyright (c) 2025 the Eclipse BaSyx Authors
#
# This program and the accompanying materials are made available under the terms of the MIT License, available in
# the LICENSE file of this project.
#
# SPDX-License-Identifier: MIT
import os
import unittest
from aas_compliance_tool import compliance_check_aasx as compliance_tool
from aas_compliance_tool.state_manager import ComplianceToolStateManager, Status
class ComplianceToolAASXTest(unittest.TestCase):
def test_check_deserialization(self) -> None:
manager = ComplianceToolStateManager()
script_dir = os.path.dirname(__file__)
file_path_1 = os.path.join(script_dir, 'files/test_not_found.aasx')
compliance_tool.check_deserialization(file_path_1, manager)
self.assertEqual(2, len(manager.steps))
self.assertEqual(Status.FAILED, manager.steps[0].status)
# we should expect a FileNotFound error here since the file does not exist and that is the first error
# aasx.py will throw if you try to open a file that does not exist.
self.assertIn("No such file or directory:", manager.format_step(0, verbose_level=1))
self.assertEqual(Status.NOT_EXECUTED, manager.steps[1].status)
# Todo add more tests for checking wrong aasx files
manager.steps = []
file_path_5 = os.path.join(script_dir, 'files/test_demo_full_example_xml.aasx')
compliance_tool.check_deserialization(file_path_5, manager)
self.assertEqual(2, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
manager.steps = []
file_path_5 = os.path.join(script_dir, 'files/test_demo_full_example_json.aasx')
compliance_tool.check_deserialization(file_path_5, manager)
self.assertEqual(2, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
def test_check_aas_example(self) -> None:
manager = ComplianceToolStateManager()
script_dir = os.path.dirname(__file__)
file_path_2 = os.path.join(script_dir, 'files/test_demo_full_example_xml.aasx')
compliance_tool.check_aas_example(file_path_2, manager)
self.assertEqual(4, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
self.assertEqual(Status.SUCCESS, manager.steps[2].status)
self.assertEqual(Status.SUCCESS, manager.steps[3].status)
manager.steps = []
file_path_3 = os.path.join(script_dir, 'files/test_demo_full_example_json.aasx')
compliance_tool.check_aas_example(file_path_3, manager)
self.assertEqual(4, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
self.assertEqual(Status.SUCCESS, manager.steps[2].status)
self.assertEqual(Status.SUCCESS, manager.steps[3].status)
manager.steps = []
file_path_4 = os.path.join(script_dir, 'files/test_demo_full_example_xml_wrong_attribute.aasx')
compliance_tool.check_aas_example(file_path_4, manager)
self.assertEqual(4, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
self.assertEqual(Status.FAILED, manager.steps[2].status)
self.assertEqual('FAILED: Check if data is equal to example data\n - ERROR: Attribute id_short of '
'AssetAdministrationShell[https://example.org/Test_AssetAdministrationShell] must be == '
'TestAssetAdministrationShell (value=\'TestAssetAdministrationShell123\')',
manager.format_step(2, verbose_level=1))
self.assertEqual(Status.NOT_EXECUTED, manager.steps[3].status)
def test_check_aasx_files_equivalence(self) -> None:
manager = ComplianceToolStateManager()
script_dir = os.path.dirname(__file__)
file_path_1 = os.path.join(script_dir, 'files/test_demo_full_example_xml.aasx')
file_path_2 = os.path.join(script_dir, 'files/test_empty.aasx')
compliance_tool.check_aasx_files_equivalence(file_path_1, file_path_2, manager)
self.assertEqual(6, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
self.assertEqual(Status.SUCCESS, manager.steps[2].status)
self.assertEqual(Status.SUCCESS, manager.steps[3].status)
self.assertEqual(Status.FAILED, manager.steps[4].status)
self.assertEqual(Status.NOT_EXECUTED, manager.steps[5].status)
manager.steps = []
compliance_tool.check_aasx_files_equivalence(file_path_2, file_path_1, manager)
self.assertEqual(6, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
self.assertEqual(Status.SUCCESS, manager.steps[2].status)
self.assertEqual(Status.SUCCESS, manager.steps[3].status)
self.assertEqual(Status.FAILED, manager.steps[4].status)
self.assertEqual(Status.NOT_EXECUTED, manager.steps[5].status)
manager.steps = []
file_path_3 = os.path.join(script_dir, 'files/test_demo_full_example_xml.aasx')
file_path_4 = os.path.join(script_dir, 'files/test_demo_full_example_json.aasx')
compliance_tool.check_aasx_files_equivalence(file_path_3, file_path_4, manager)
self.assertEqual(6, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
self.assertEqual(Status.SUCCESS, manager.steps[2].status)
self.assertEqual(Status.SUCCESS, manager.steps[3].status)
self.assertEqual(Status.SUCCESS, manager.steps[4].status)
self.assertEqual(Status.SUCCESS, manager.steps[5].status)
manager.steps = []
file_path_3 = os.path.join(script_dir, 'files/test_demo_full_example_xml.aasx')
file_path_4 = os.path.join(script_dir, 'files/test_demo_full_example_xml_wrong_attribute.aasx')
compliance_tool.check_aasx_files_equivalence(file_path_3, file_path_4, manager)
self.assertEqual(6, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
self.assertEqual(Status.SUCCESS, manager.steps[2].status)
self.assertEqual(Status.SUCCESS, manager.steps[3].status)
self.assertEqual(Status.FAILED, manager.steps[4].status)
self.assertEqual('FAILED: Check if data in files are equal\n - ERROR: Attribute id_short of '
'AssetAdministrationShell[https://example.org/Test_AssetAdministrationShell] must be == '
'TestAssetAdministrationShell123 (value=\'TestAssetAdministrationShell\')',
manager.format_step(4, verbose_level=1))
manager.steps = []
compliance_tool.check_aasx_files_equivalence(file_path_4, file_path_3, manager)
self.assertEqual(6, len(manager.steps))
self.assertEqual(Status.SUCCESS, manager.steps[0].status)
self.assertEqual(Status.SUCCESS, manager.steps[1].status)
self.assertEqual(Status.SUCCESS, manager.steps[2].status)
self.assertEqual(Status.SUCCESS, manager.steps[3].status)
self.assertEqual(Status.FAILED, manager.steps[4].status)
self.assertEqual('FAILED: Check if data in files are equal\n - ERROR: Attribute id_short of '
'AssetAdministrationShell[https://example.org/Test_AssetAdministrationShell] must be == '
'TestAssetAdministrationShell (value=\'TestAssetAdministrationShell123\')',
manager.format_step(4, verbose_level=1))
self.assertEqual(Status.NOT_EXECUTED, manager.steps[5].status)
def test_check_schema(self):
manager = ComplianceToolStateManager()
script_dir = os.path.dirname(__file__)
file_path_2 = os.path.join(script_dir, 'files/test_demo_full_example_json.aasx')
compliance_tool.check_schema(file_path_2, manager)
self.assertEqual(4, len(manager.steps))
for i in range(4):
self.assertEqual(Status.SUCCESS, manager.steps[i].status)
manager.steps = []
file_path_3 = os.path.join(script_dir, 'files/test_demo_full_example_xml.aasx')
compliance_tool.check_schema(file_path_3, manager)
self.assertEqual(4, len(manager.steps))
for i in range(4):
self.assertEqual(Status.SUCCESS, manager.steps[i].status)
manager.steps = []
file_path_4 = os.path.join(script_dir, 'files/test_demo_full_example_xml_wrong_attribute.aasx')
compliance_tool.check_schema(file_path_4, manager)
self.assertEqual(4, len(manager.steps))
for i in range(4):
self.assertEqual(Status.SUCCESS, manager.steps[i].status)
manager.steps = []
file_path_5 = os.path.join(script_dir, 'files/test_empty.aasx')
compliance_tool.check_schema(file_path_5, manager)
self.assertEqual(2, len(manager.steps))
for i in range(2):
self.assertEqual(Status.SUCCESS, manager.steps[i].status)