armodel 1.7.7__py3-none-any.whl → 1.7.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- armodel/cli/arxml_dump_cli.py +33 -22
- armodel/cli/arxml_format_cli.py +25 -13
- armodel/models/M2/AUTOSARTemplates/AutosarTopLevelStructure.py +64 -29
- armodel/models/M2/AUTOSARTemplates/BswModuleTemplate/BswBehavior.py +322 -63
- armodel/models/M2/AUTOSARTemplates/BswModuleTemplate/BswOverview.py +134 -35
- armodel/models/M2/AUTOSARTemplates/CommonStructure/InternalBehavior.py +10 -1
- armodel/models/M2/AUTOSARTemplates/CommonStructure/TriggerDeclaration.py +18 -2
- armodel/models/M2/AUTOSARTemplates/ECUCDescriptionTemplate.py +20 -19
- armodel/models/M2/AUTOSARTemplates/EcuResourceTemplate/HwElementCategory.py +59 -0
- armodel/models/M2/AUTOSARTemplates/EcuResourceTemplate/__init__.py +145 -0
- armodel/models/M2/AUTOSARTemplates/GenericStructure/GeneralTemplateClasses/ARPackage.py +214 -156
- armodel/models/M2/AUTOSARTemplates/GenericStructure/GeneralTemplateClasses/Identifiable.py +60 -32
- armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/Components/__init__.py +63 -42
- armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/Composition/__init__.py +1 -0
- armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/EndToEndProtection.py +13 -6
- armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/PortInterface/__init__.py +111 -38
- armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/SwcInternalBehavior/AccessCount.py +9 -1
- armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/SwcInternalBehavior/ModeDeclarationGroup.py +5 -4
- armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/SwcInternalBehavior/__init__.py +9 -1
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/DataMapping.py +167 -5
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/{ECUResourceMapping.py → EcuResourceMapping.py} +4 -3
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/Fibex/Fibex4Can/CanTopology.py +31 -21
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/Fibex/Fibex4Ethernet/EthernetFrame.py +5 -3
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/Fibex/Fibex4Flexray/FlexrayCommunication.py +76 -0
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/Fibex/Fibex4Flexray/FlexrayTopology.py +654 -0
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/Fibex/Fibex4Flexray/__init__.py +0 -0
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/Fibex/FibexCore/CoreCommunication.py +64 -31
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/Fibex/FibexCore/CoreTopology.py +158 -40
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/Fibex/FibexCore/EcuInstance.py +19 -6
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/InstanceRefs.py +2 -0
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/Transformer/__init__.py +524 -0
- armodel/models/M2/AUTOSARTemplates/SystemTemplate/__init__.py +15 -13
- armodel/models/__init__.py +5 -1
- armodel/parser/abstract_arxml_parser.py +34 -30
- armodel/parser/arxml_parser.py +1196 -525
- armodel/parser/file_parser.py +5 -3
- armodel/tests/test_armodel/models/test_ar_package.py +6 -11
- armodel/tests/test_armodel/models/test_port_interface.py +116 -117
- armodel/tests/test_armodel/parser/test_bsw_module_descriiption.py +109 -109
- armodel/tests/test_armodel/parser/test_sw_components.py +38 -27
- armodel/tests/test_armodel/parser/test_system.py +2 -8
- armodel/transformer/__init__.py +0 -0
- armodel/transformer/abstract.py +6 -0
- armodel/transformer/admin_data.py +31 -0
- armodel/writer/abstract_arxml_writer.py +22 -29
- armodel/writer/arxml_writer.py +1198 -477
- {armodel-1.7.7.dist-info → armodel-1.7.8.dist-info}/METADATA +41 -1
- {armodel-1.7.7.dist-info → armodel-1.7.8.dist-info}/RECORD +52 -43
- {armodel-1.7.7.dist-info → armodel-1.7.8.dist-info}/LICENSE +0 -0
- {armodel-1.7.7.dist-info → armodel-1.7.8.dist-info}/WHEEL +0 -0
- {armodel-1.7.7.dist-info → armodel-1.7.8.dist-info}/entry_points.txt +0 -0
- {armodel-1.7.7.dist-info → armodel-1.7.8.dist-info}/top_level.txt +0 -0
|
@@ -11,11 +11,12 @@ from .... import ARXMLParser, ARXMLWriter
|
|
|
11
11
|
|
|
12
12
|
import logging
|
|
13
13
|
|
|
14
|
+
|
|
14
15
|
class TestBswMD:
|
|
15
16
|
def setup_method(self):
|
|
16
17
|
logger = logging.getLogger()
|
|
17
18
|
formatter = logging.Formatter('[%(levelname)s] : %(message)s')
|
|
18
|
-
logging.basicConfig(format='[%(levelname)s] : %(message)s', level
|
|
19
|
+
logging.basicConfig(format='[%(levelname)s] : %(message)s', level=logging.DEBUG)
|
|
19
20
|
log_file = 'pytest_armodel.log'
|
|
20
21
|
|
|
21
22
|
file_handler = logging.FileHandler(log_file)
|
|
@@ -30,170 +31,169 @@ class TestBswMD:
|
|
|
30
31
|
|
|
31
32
|
def test_ar_packages(self):
|
|
32
33
|
document = AUTOSAR.getInstance()
|
|
33
|
-
root_pkgs = sorted(document.getARPackages(), key
|
|
34
|
-
assert(len(root_pkgs) == 2)
|
|
35
|
-
assert(root_pkgs[0].getShortName() == "AUTOSAR_BswM")
|
|
36
|
-
assert(root_pkgs[1].getShortName() == "EB_BswM_TxDxM1I14R0")
|
|
34
|
+
root_pkgs = sorted(document.getARPackages(), key=lambda pkg: pkg.short_name)
|
|
35
|
+
assert (len(root_pkgs) == 2)
|
|
36
|
+
assert (root_pkgs[0].getShortName() == "AUTOSAR_BswM")
|
|
37
|
+
assert (root_pkgs[1].getShortName() == "EB_BswM_TxDxM1I14R0")
|
|
37
38
|
|
|
38
|
-
root_pkg_0_pkgs = sorted(root_pkgs[0].getARPackages(), key
|
|
39
|
-
assert(len(root_pkg_0_pkgs) == 3)
|
|
39
|
+
root_pkg_0_pkgs = sorted(root_pkgs[0].getARPackages(), key=lambda pkg: pkg.short_name)
|
|
40
|
+
assert (len(root_pkg_0_pkgs) == 3)
|
|
40
41
|
|
|
41
|
-
bsw_module_desc_pkg = root_pkg_0_pkgs[0] # type:ARPackage
|
|
42
|
-
assert(bsw_module_desc_pkg.getShortName() == "BswModuleDescriptions")
|
|
42
|
+
bsw_module_desc_pkg = root_pkg_0_pkgs[0] # type:ARPackage
|
|
43
|
+
assert (bsw_module_desc_pkg.getShortName() == "BswModuleDescriptions")
|
|
43
44
|
|
|
44
45
|
root_pkg_1_pkgs = root_pkgs[1].getARPackages()
|
|
45
|
-
assert(len(root_pkg_1_pkgs) == 1)
|
|
46
|
+
assert (len(root_pkg_1_pkgs) == 1)
|
|
46
47
|
|
|
47
48
|
def test_bsw_module_description(self):
|
|
48
49
|
document = AUTOSAR.getInstance()
|
|
49
50
|
|
|
50
51
|
pkg = document.find("/AUTOSAR_BswM/BswModuleDescriptions") # type: ARPackage
|
|
51
52
|
bsw_module_descs = pkg.getBswModuleDescriptions()
|
|
52
|
-
assert(len(bsw_module_descs) == 1)
|
|
53
|
+
assert (len(bsw_module_descs) == 1)
|
|
53
54
|
|
|
54
55
|
bsw_module_desc = bsw_module_descs[0]
|
|
55
|
-
assert(bsw_module_desc.getShortName() == "BswM")
|
|
56
|
-
assert(bsw_module_desc.moduleId.getText() == "34")
|
|
57
|
-
assert(bsw_module_desc.moduleId.getValue() == 34)
|
|
56
|
+
assert (bsw_module_desc.getShortName() == "BswM")
|
|
57
|
+
assert (bsw_module_desc.moduleId.getText() == "34")
|
|
58
|
+
assert (bsw_module_desc.moduleId.getValue() == 34)
|
|
58
59
|
|
|
59
60
|
# verify the provided entries
|
|
60
|
-
assert(len(bsw_module_desc.implementedEntryRefs) == 2)
|
|
61
|
-
assert(bsw_module_desc.implementedEntryRefs[0].getDest() == "BSW-MODULE-ENTRY")
|
|
62
|
-
assert(bsw_module_desc.implementedEntryRefs[0].getValue() == "/AUTOSAR_BswM/BswModuleEntrys/BswM_Init")
|
|
63
|
-
assert(bsw_module_desc.implementedEntryRefs[1].getDest() == "BSW-MODULE-ENTRY")
|
|
64
|
-
assert(bsw_module_desc.implementedEntryRefs[1].getValue() == "/AUTOSAR_BswM/BswModuleEntrys/BswM_MainFunction")
|
|
61
|
+
assert (len(bsw_module_desc.implementedEntryRefs) == 2)
|
|
62
|
+
assert (bsw_module_desc.implementedEntryRefs[0].getDest() == "BSW-MODULE-ENTRY")
|
|
63
|
+
assert (bsw_module_desc.implementedEntryRefs[0].getValue() == "/AUTOSAR_BswM/BswModuleEntrys/BswM_Init")
|
|
64
|
+
assert (bsw_module_desc.implementedEntryRefs[1].getDest() == "BSW-MODULE-ENTRY")
|
|
65
|
+
assert (bsw_module_desc.implementedEntryRefs[1].getValue() == "/AUTOSAR_BswM/BswModuleEntrys/BswM_MainFunction")
|
|
65
66
|
|
|
66
|
-
assert(len(bsw_module_desc.
|
|
67
|
-
behavior = bsw_module_desc.
|
|
68
|
-
assert(behavior.short_name == "InternalBehavior_0")
|
|
67
|
+
assert (len(bsw_module_desc.getInternalBehaviors()) == 1)
|
|
68
|
+
behavior = bsw_module_desc.getInternalBehaviors()[0]
|
|
69
|
+
assert (behavior.short_name == "InternalBehavior_0")
|
|
69
70
|
|
|
70
|
-
assert(len(behavior.getDataTypeMappingRefs()) == 1)
|
|
71
|
+
assert (len(behavior.getDataTypeMappingRefs()) == 1)
|
|
71
72
|
data_type_mapping_ref = behavior.getDataTypeMappingRefs()[0]
|
|
72
|
-
assert(data_type_mapping_ref.getDest() == "DATA-TYPE-MAPPING-SET")
|
|
73
|
-
assert(data_type_mapping_ref.getValue() == "/BswMMode/DataTypeMappingSets/BswMModeMapping")
|
|
73
|
+
assert (data_type_mapping_ref.getDest() == "DATA-TYPE-MAPPING-SET")
|
|
74
|
+
assert (data_type_mapping_ref.getValue() == "/BswMMode/DataTypeMappingSets/BswMModeMapping")
|
|
74
75
|
|
|
75
|
-
assert(len(behavior.getExclusiveAreas()) == 1)
|
|
76
|
-
assert(behavior.getExclusiveAreas()[0].short_name == "SCHM_BSWM_EXCLUSIVE_AREA")
|
|
76
|
+
assert (len(behavior.getExclusiveAreas()) == 1)
|
|
77
|
+
assert (behavior.getExclusiveAreas()[0].short_name == "SCHM_BSWM_EXCLUSIVE_AREA")
|
|
77
78
|
|
|
78
|
-
assert(len(behavior.getBswSchedulableEntities()) == 1)
|
|
79
|
+
assert (len(behavior.getBswSchedulableEntities()) == 1)
|
|
79
80
|
entity = behavior.getBswSchedulableEntities()[0]
|
|
80
|
-
assert(entity.short_name == "BswM_MainFunction")
|
|
81
|
-
assert(entity.minimumStartInterval is not None)
|
|
82
|
-
assert(entity.minimumStartIntervalMs is not None)
|
|
83
|
-
assert(len(entity.getCanEnterExclusiveAreaRefs()) == 1)
|
|
84
|
-
assert(entity.getCanEnterExclusiveAreaRefs()[0].getDest() == "EXCLUSIVE-AREA")
|
|
85
|
-
assert(entity.getCanEnterExclusiveAreaRefs()[0].getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/SCHM_BSWM_EXCLUSIVE_AREA")
|
|
86
|
-
assert(entity.implementedEntryRef.getDest() == "BSW-MODULE-ENTRY")
|
|
87
|
-
assert(entity.implementedEntryRef.getValue() == "/AUTOSAR_BswM/BswModuleEntrys/BswM_MainFunction")
|
|
88
|
-
|
|
89
|
-
assert(len(behavior.getBswTimingEvents()) == 1)
|
|
81
|
+
assert (entity.short_name == "BswM_MainFunction")
|
|
82
|
+
assert (entity.minimumStartInterval is not None)
|
|
83
|
+
assert (entity.minimumStartIntervalMs is not None)
|
|
84
|
+
assert (len(entity.getCanEnterExclusiveAreaRefs()) == 1)
|
|
85
|
+
assert (entity.getCanEnterExclusiveAreaRefs()[0].getDest() == "EXCLUSIVE-AREA")
|
|
86
|
+
assert (entity.getCanEnterExclusiveAreaRefs()[0].getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/SCHM_BSWM_EXCLUSIVE_AREA") # noqa E501
|
|
87
|
+
assert (entity.implementedEntryRef.getDest() == "BSW-MODULE-ENTRY")
|
|
88
|
+
assert (entity.implementedEntryRef.getValue() == "/AUTOSAR_BswM/BswModuleEntrys/BswM_MainFunction")
|
|
89
|
+
|
|
90
|
+
assert (len(behavior.getBswTimingEvents()) == 1)
|
|
90
91
|
event = behavior.getBswTimingEvents()[0]
|
|
91
|
-
assert(event.short_name == "TimingEvent_MainFunction")
|
|
92
|
-
assert(event.startsOnEventRef.getDest() == "BSW-SCHEDULABLE-ENTITY")
|
|
93
|
-
assert(event.startsOnEventRef.getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/BswM_MainFunction")
|
|
94
|
-
assert(event.period.getValue() == 0.02)
|
|
95
|
-
assert(event.period.getText() == "0.02")
|
|
96
|
-
assert(event.periodMs == 20)
|
|
92
|
+
assert (event.short_name == "TimingEvent_MainFunction")
|
|
93
|
+
assert (event.startsOnEventRef.getDest() == "BSW-SCHEDULABLE-ENTITY")
|
|
94
|
+
assert (event.startsOnEventRef.getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/BswM_MainFunction")
|
|
95
|
+
assert (event.period.getValue() == 0.02)
|
|
96
|
+
assert (event.period.getText() == "0.02")
|
|
97
|
+
assert (event.periodMs == 20)
|
|
97
98
|
|
|
98
99
|
def test_bsw_module_entries(self):
|
|
99
100
|
document = AUTOSAR.getInstance()
|
|
100
101
|
|
|
101
102
|
pkg = document.find("/AUTOSAR_BswM/BswModuleEntrys") # type: ARPackage
|
|
102
|
-
entries = sorted(pkg.getBswModuleEntries(), key=
|
|
103
|
-
assert(len(entries) == 2)
|
|
104
|
-
|
|
105
|
-
assert(entries[0].getShortName() == "BswM_Init")
|
|
106
|
-
assert(entries[0].getServiceId().getValue() == 0)
|
|
107
|
-
assert(entries[0].getIsReentrant().getValue()
|
|
108
|
-
assert(entries[0].getIsSynchronous().getValue()
|
|
109
|
-
assert(entries[0].getCallType().getText() == "REGULAR")
|
|
110
|
-
assert(entries[0].getExecutionContext().getText() == "UNSPECIFIED")
|
|
111
|
-
assert(entries[0].getSwServiceImplPolicy().getText() == "STANDARD")
|
|
112
|
-
|
|
113
|
-
assert(entries[1].getShortName() == "BswM_MainFunction")
|
|
114
|
-
assert(entries[1].getServiceId().getValue() == 3)
|
|
115
|
-
assert(entries[1].getIsReentrant().getValue()
|
|
116
|
-
assert(entries[1].getIsSynchronous().getValue()
|
|
117
|
-
assert(entries[1].getCallType().getText() == "SCHEDULED")
|
|
118
|
-
assert(entries[1].getExecutionContext().getText() == "TASK")
|
|
119
|
-
assert(entries[1].getSwServiceImplPolicy().getText() == "STANDARD")
|
|
103
|
+
entries = sorted(pkg.getBswModuleEntries(), key=lambda entry: entry.short_name)
|
|
104
|
+
assert (len(entries) == 2)
|
|
105
|
+
|
|
106
|
+
assert (entries[0].getShortName() == "BswM_Init")
|
|
107
|
+
assert (entries[0].getServiceId().getValue() == 0)
|
|
108
|
+
assert (entries[0].getIsReentrant().getValue() is False)
|
|
109
|
+
assert (entries[0].getIsSynchronous().getValue() is True)
|
|
110
|
+
assert (entries[0].getCallType().getText() == "REGULAR")
|
|
111
|
+
assert (entries[0].getExecutionContext().getText() == "UNSPECIFIED")
|
|
112
|
+
assert (entries[0].getSwServiceImplPolicy().getText() == "STANDARD")
|
|
113
|
+
|
|
114
|
+
assert (entries[1].getShortName() == "BswM_MainFunction")
|
|
115
|
+
assert (entries[1].getServiceId().getValue() == 3)
|
|
116
|
+
assert (entries[1].getIsReentrant().getValue() is False)
|
|
117
|
+
assert (entries[1].getIsSynchronous().getValue() is True)
|
|
118
|
+
assert (entries[1].getCallType().getText() == "SCHEDULED")
|
|
119
|
+
assert (entries[1].getExecutionContext().getText() == "TASK")
|
|
120
|
+
assert (entries[1].getSwServiceImplPolicy().getText() == "STANDARD")
|
|
120
121
|
|
|
121
122
|
def test_bsw_module_swc_bsw_mapping(self):
|
|
122
123
|
document = AUTOSAR.getInstance()
|
|
123
124
|
|
|
124
125
|
pkg = document.find("/AUTOSAR_BswM/SwcBswMappings") # type: ARPackage
|
|
125
126
|
mappings = pkg.getSwcBswMappings()
|
|
126
|
-
assert(len(mappings) == 1)
|
|
127
|
+
assert (len(mappings) == 1)
|
|
127
128
|
|
|
128
|
-
assert(mappings[0].bswBehaviorRef.getDest() == "BSW-INTERNAL-BEHAVIOR")
|
|
129
|
-
assert(mappings[0].bswBehaviorRef.getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
|
|
129
|
+
assert (mappings[0].bswBehaviorRef.getDest() == "BSW-INTERNAL-BEHAVIOR")
|
|
130
|
+
assert (mappings[0].bswBehaviorRef.getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
|
|
130
131
|
|
|
131
|
-
assert(len(mappings[0].getRunnableMappings()) == 1)
|
|
132
|
+
assert (len(mappings[0].getRunnableMappings()) == 1)
|
|
132
133
|
runnable_mapping = mappings[0].getRunnableMappings()[0]
|
|
133
|
-
assert(runnable_mapping.getBswEntityRef().getDest() == "BSW-SCHEDULABLE-ENTITY")
|
|
134
|
-
assert(runnable_mapping.getBswEntityRef().getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/BswM_MainFunction")
|
|
135
|
-
assert(runnable_mapping.getSwcRunnableRef().getDest() == "RUNNABLE-ENTITY")
|
|
136
|
-
assert(runnable_mapping.getSwcRunnableRef().getValue() == "/AUTOSAR_BswM/SwComponentTypes/BswM/BswMInternalBehavior/RES_MainFunction")
|
|
134
|
+
assert (runnable_mapping.getBswEntityRef().getDest() == "BSW-SCHEDULABLE-ENTITY")
|
|
135
|
+
assert (runnable_mapping.getBswEntityRef().getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/BswM_MainFunction")
|
|
136
|
+
assert (runnable_mapping.getSwcRunnableRef().getDest() == "RUNNABLE-ENTITY")
|
|
137
|
+
assert (runnable_mapping.getSwcRunnableRef().getValue() == "/AUTOSAR_BswM/SwComponentTypes/BswM/BswMInternalBehavior/RES_MainFunction")
|
|
137
138
|
|
|
138
139
|
def test_bsw_module_implementation(self):
|
|
139
140
|
document = AUTOSAR.getInstance()
|
|
140
141
|
|
|
141
142
|
pkg = document.find("/EB_BswM_TxDxM1I14R0/Implementations") # type: ARPackage
|
|
142
|
-
assert(len(pkg.getBswImplementations()) == 1)
|
|
143
|
+
assert (len(pkg.getBswImplementations()) == 1)
|
|
143
144
|
impl = pkg.getBswImplementations()[0]
|
|
144
|
-
assert(impl.short_name == "BswImplementation_0")
|
|
145
|
-
assert(len(impl.getCodeDescriptors()) == 1)
|
|
145
|
+
assert (impl.short_name == "BswImplementation_0")
|
|
146
|
+
assert (len(impl.getCodeDescriptors()) == 1)
|
|
146
147
|
|
|
147
148
|
code_desc = impl.getCodeDescriptors()[0]
|
|
148
|
-
assert(code_desc.short_name == "Files")
|
|
149
|
-
assert(len(code_desc.getArtifactDescriptors()) == 21)
|
|
150
|
-
assert(len(code_desc.getArtifactDescriptors("SWSRC")) == 4)
|
|
151
|
-
assert(len(code_desc.getArtifactDescriptors("SWHDR")) == 15)
|
|
152
|
-
assert(len(code_desc.getArtifactDescriptors("SWMAKE")) == 2)
|
|
149
|
+
assert (code_desc.short_name == "Files")
|
|
150
|
+
assert (len(code_desc.getArtifactDescriptors()) == 21)
|
|
151
|
+
assert (len(code_desc.getArtifactDescriptors("SWSRC")) == 4)
|
|
152
|
+
assert (len(code_desc.getArtifactDescriptors("SWHDR")) == 15)
|
|
153
|
+
assert (len(code_desc.getArtifactDescriptors("SWMAKE")) == 2)
|
|
153
154
|
|
|
154
|
-
artifact_descs = sorted(code_desc.getArtifactDescriptors("SWMAKE"), key
|
|
155
|
-
assert(artifact_descs[0].getShortLabel().getValue() == "make::BswM_defs.mak")
|
|
156
|
-
assert(artifact_descs[0].getCategory().getValue() == "SWMAKE")
|
|
157
|
-
assert(artifact_descs[1].getShortLabel().getValue() == "make::BswM_rules.mak")
|
|
158
|
-
assert(artifact_descs[1].getCategory().getValue() == "SWMAKE")
|
|
155
|
+
artifact_descs = sorted(code_desc.getArtifactDescriptors("SWMAKE"), key=lambda o: o.getShortLabel().getValue()) # type: List[AutosarEngineeringObject] # noqa E501
|
|
156
|
+
assert (artifact_descs[0].getShortLabel().getValue() == "make::BswM_defs.mak")
|
|
157
|
+
assert (artifact_descs[0].getCategory().getValue() == "SWMAKE")
|
|
158
|
+
assert (artifact_descs[1].getShortLabel().getValue() == "make::BswM_rules.mak")
|
|
159
|
+
assert (artifact_descs[1].getCategory().getValue() == "SWMAKE")
|
|
159
160
|
|
|
160
|
-
assert(impl.programmingLanguage.getValue() == "C")
|
|
161
|
+
assert (impl.programmingLanguage.getValue() == "C")
|
|
161
162
|
|
|
162
|
-
assert(impl.resourceConsumption.short_name == "ResourceConsumption")
|
|
163
|
-
assert(len(impl.resourceConsumption.getMemorySections()) == 8)
|
|
163
|
+
assert (impl.resourceConsumption.short_name == "ResourceConsumption")
|
|
164
|
+
assert (len(impl.resourceConsumption.getMemorySections()) == 8)
|
|
164
165
|
|
|
165
166
|
section = impl.resourceConsumption.getMemorySection("CODE")
|
|
166
|
-
assert(section.short_name == "CODE")
|
|
167
|
-
assert(section.alignment
|
|
168
|
-
assert(section.swAddrMethodRef.getDest() == "SW-ADDR-METHOD")
|
|
169
|
-
assert(section.swAddrMethodRef.getValue() == "/AUTOSAR_MemMap/SwAddrMethods/CODE")
|
|
167
|
+
assert (section.short_name == "CODE")
|
|
168
|
+
assert (section.alignment is None)
|
|
169
|
+
assert (section.swAddrMethodRef.getDest() == "SW-ADDR-METHOD")
|
|
170
|
+
assert (section.swAddrMethodRef.getValue() == "/AUTOSAR_MemMap/SwAddrMethods/CODE")
|
|
170
171
|
|
|
171
172
|
section = impl.resourceConsumption.getMemorySection("VAR_NO_INIT_UNSPECIFIED")
|
|
172
|
-
assert(section.short_name == "VAR_NO_INIT_UNSPECIFIED")
|
|
173
|
-
assert(section.alignment.getText() == "UNSPECIFIED")
|
|
174
|
-
assert(section.swAddrMethodRef.getDest() == "SW-ADDR-METHOD")
|
|
175
|
-
assert(section.swAddrMethodRef.getValue() == "/AUTOSAR_MemMap/SwAddrMethods/VAR_NOINIT")
|
|
176
|
-
|
|
177
|
-
assert(impl.vendorId.getValue() == 1)
|
|
178
|
-
assert(impl.swVersion.getValue() == "1.14.1")
|
|
179
|
-
assert(impl.swcBswMappingRef.getDest() == "SWC-BSW-MAPPING")
|
|
180
|
-
assert(impl.swcBswMappingRef.getValue() == "/AUTOSAR_BswM/SwcBswMappings/SwcBswMapping_0")
|
|
181
|
-
assert(impl.arReleaseVersion.getValue() == "4.0.3")
|
|
182
|
-
assert(impl.behaviorRef.getDest() == "BSW-INTERNAL-BEHAVIOR")
|
|
183
|
-
assert(impl.behaviorRef.getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
|
|
173
|
+
assert (section.short_name == "VAR_NO_INIT_UNSPECIFIED")
|
|
174
|
+
assert (section.alignment.getText() == "UNSPECIFIED")
|
|
175
|
+
assert (section.swAddrMethodRef.getDest() == "SW-ADDR-METHOD")
|
|
176
|
+
assert (section.swAddrMethodRef.getValue() == "/AUTOSAR_MemMap/SwAddrMethods/VAR_NOINIT")
|
|
177
|
+
|
|
178
|
+
assert (impl.vendorId.getValue() == 1)
|
|
179
|
+
assert (impl.swVersion.getValue() == "1.14.1")
|
|
180
|
+
assert (impl.swcBswMappingRef.getDest() == "SWC-BSW-MAPPING")
|
|
181
|
+
assert (impl.swcBswMappingRef.getValue() == "/AUTOSAR_BswM/SwcBswMappings/SwcBswMapping_0")
|
|
182
|
+
assert (impl.arReleaseVersion.getValue() == "4.0.3")
|
|
183
|
+
assert (impl.behaviorRef.getDest() == "BSW-INTERNAL-BEHAVIOR")
|
|
184
|
+
assert (impl.behaviorRef.getValue() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
|
|
184
185
|
|
|
185
186
|
def test_get_implementation(self):
|
|
186
187
|
document = AUTOSAR.getInstance()
|
|
187
188
|
impl = document.getImplementation("/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
|
|
188
|
-
assert(impl.getFullName() == "/EB_BswM_TxDxM1I14R0/Implementations/BswImplementation_0")
|
|
189
|
-
assert(isinstance(impl, BswImplementation))
|
|
189
|
+
assert (impl.getFullName() == "/EB_BswM_TxDxM1I14R0/Implementations/BswImplementation_0")
|
|
190
|
+
assert (isinstance(impl, BswImplementation))
|
|
190
191
|
|
|
191
192
|
def test_get_behavior(self):
|
|
192
193
|
document = AUTOSAR.getInstance()
|
|
193
194
|
behavior = document.getBehavior("/EB_BswM_TxDxM1I14R0/Implementations/BswImplementation_0")
|
|
194
|
-
assert(behavior.getFullName() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
|
|
195
|
-
assert(isinstance(behavior, BswInternalBehavior))
|
|
196
|
-
|
|
195
|
+
assert (behavior.getFullName() == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
|
|
196
|
+
assert (isinstance(behavior, BswInternalBehavior))
|
|
197
197
|
|
|
198
198
|
def test_load_save(self):
|
|
199
199
|
document = AUTOSAR.getInstance()
|
|
@@ -204,7 +204,7 @@ class TestBswMD:
|
|
|
204
204
|
writer = ARXMLWriter()
|
|
205
205
|
writer.save("data/generated.arxml", document)
|
|
206
206
|
|
|
207
|
-
assert(filecmp.cmp("src/armodel/tests/test_files/SoftwareComponents.arxml", "data/generated.arxml", shallow
|
|
207
|
+
assert (filecmp.cmp("src/armodel/tests/test_files/SoftwareComponents.arxml", "data/generated.arxml", shallow=False) is True)
|
|
208
208
|
|
|
209
209
|
def test_bswm_bswmd_arxml_loading_and_saving(self):
|
|
210
210
|
document = AUTOSAR.getInstance()
|
|
@@ -215,4 +215,4 @@ class TestBswMD:
|
|
|
215
215
|
writer = ARXMLWriter()
|
|
216
216
|
writer.save("data/generated_BswM_Bswmd.arxml", document)
|
|
217
217
|
|
|
218
|
-
assert(filecmp.cmp("src/armodel/tests/test_files/BswM_Bswmd.arxml", "data/generated_BswM_Bswmd.arxml", shallow
|
|
218
|
+
assert (filecmp.cmp("src/armodel/tests/test_files/BswM_Bswmd.arxml", "data/generated_BswM_Bswmd.arxml", shallow=False) is True)
|
|
@@ -18,61 +18,61 @@ class TestSWComponents:
|
|
|
18
18
|
document = AUTOSAR.getInstance()
|
|
19
19
|
root_pkgs = sorted(document.getARPackages(), key = lambda pkg: pkg.getShortName())
|
|
20
20
|
|
|
21
|
-
assert(len(root_pkgs) == 1)
|
|
22
|
-
assert("DemoApplication" == root_pkgs[0].getShortName())
|
|
21
|
+
assert (len(root_pkgs) == 1)
|
|
22
|
+
assert ("DemoApplication" == root_pkgs[0].getShortName())
|
|
23
23
|
|
|
24
24
|
def test_sw_component(self):
|
|
25
25
|
document = AUTOSAR.getInstance()
|
|
26
26
|
sw_component = document.find("/DemoApplication/SwComponentTypes/SWC_CyclicCounter")
|
|
27
|
-
assert(sw_component.getShortName() == 'SWC_CyclicCounter')
|
|
28
|
-
assert(isinstance(sw_component, AtomicSwComponentType))
|
|
27
|
+
assert (sw_component.getShortName() == 'SWC_CyclicCounter')
|
|
28
|
+
assert (isinstance(sw_component, AtomicSwComponentType))
|
|
29
29
|
|
|
30
30
|
def test_get_implementation(self):
|
|
31
31
|
document = AUTOSAR.getInstance()
|
|
32
32
|
impl = document.getImplementation("/DemoApplication/SwComponentTypes/SWC_CyclicCounter/IB_SWC_CyclicCounter")
|
|
33
|
-
assert(impl.getFullName() == "/DemoApplication/SwcImplementations/Impl_SWC_CyclicCounter")
|
|
34
|
-
assert(isinstance(impl, SwcImplementation))
|
|
33
|
+
assert (impl.getFullName() == "/DemoApplication/SwcImplementations/Impl_SWC_CyclicCounter")
|
|
34
|
+
assert (isinstance(impl, SwcImplementation))
|
|
35
35
|
|
|
36
36
|
def test_get_behavior(self):
|
|
37
37
|
document = AUTOSAR.getInstance()
|
|
38
38
|
behavior = document.getBehavior("/DemoApplication/SwcImplementations/Impl_SWC_CyclicCounter")
|
|
39
|
-
assert(behavior.getFullName() == "/DemoApplication/SwComponentTypes/SWC_CyclicCounter/IB_SWC_CyclicCounter")
|
|
40
|
-
assert(isinstance(behavior, InternalBehavior))
|
|
39
|
+
assert (behavior.getFullName() == "/DemoApplication/SwComponentTypes/SWC_CyclicCounter/IB_SWC_CyclicCounter")
|
|
40
|
+
assert (isinstance(behavior, InternalBehavior))
|
|
41
41
|
|
|
42
42
|
def test_composition_sw_component_types(self):
|
|
43
43
|
document = AUTOSAR.getInstance()
|
|
44
|
-
sw_component = document.find("/DemoApplication/SwComponentTypes/TopLevelComposition")
|
|
45
|
-
assert(sw_component.short_name == "TopLevelComposition")
|
|
46
|
-
assert(isinstance(sw_component, CompositionSwComponentType))
|
|
47
|
-
|
|
48
|
-
assert(len(
|
|
44
|
+
sw_component = document.find("/DemoApplication/SwComponentTypes/TopLevelComposition")
|
|
45
|
+
assert (sw_component.short_name == "TopLevelComposition")
|
|
46
|
+
assert (isinstance(sw_component, CompositionSwComponentType))
|
|
47
|
+
ports = sw_component.getPorts()
|
|
48
|
+
assert (len(ports) == 2)
|
|
49
49
|
|
|
50
50
|
def test_composition_sw_component_types_sw_connectors(self):
|
|
51
51
|
document = AUTOSAR.getInstance()
|
|
52
|
-
sw_component = document.find("/DemoApplication/SwComponentTypes/TopLevelComposition")
|
|
53
|
-
assert(isinstance(sw_component, CompositionSwComponentType))
|
|
54
|
-
assert(len(sw_component.getSwConnectors()) == 6)
|
|
55
|
-
assert(len(sw_component.getAssemblySwConnectors()) == 3)
|
|
56
|
-
assert(len(sw_component.getDelegationSwConnectors()) == 3)
|
|
52
|
+
sw_component = document.find("/DemoApplication/SwComponentTypes/TopLevelComposition")
|
|
53
|
+
assert (isinstance(sw_component, CompositionSwComponentType))
|
|
54
|
+
assert (len(sw_component.getSwConnectors()) == 6)
|
|
55
|
+
assert (len(sw_component.getAssemblySwConnectors()) == 3)
|
|
56
|
+
assert (len(sw_component.getDelegationSwConnectors()) == 3)
|
|
57
57
|
|
|
58
58
|
connector_name_list = set()
|
|
59
59
|
for sw_connector in sw_component.getAssemblySwConnectors():
|
|
60
60
|
connector_name_list.add(sw_connector.short_name)
|
|
61
61
|
|
|
62
|
-
assert(connector_name_list == set(['a6a18805580c94537a4c82f6c289a4d', 'ac681652833fb4b12b920adab33a73b', 'ac681652833fb4b12b920adab33a73c']))
|
|
62
|
+
assert (connector_name_list == set(['a6a18805580c94537a4c82f6c289a4d', 'ac681652833fb4b12b920adab33a73b', 'ac681652833fb4b12b920adab33a73c']))
|
|
63
63
|
|
|
64
64
|
sw_component.removeElement("a6a18805580c94537a4c82f6c289a4d")
|
|
65
|
-
assert(len(sw_component.getAssemblySwConnectors()) == 2)
|
|
65
|
+
assert (len(sw_component.getAssemblySwConnectors()) == 2)
|
|
66
66
|
|
|
67
67
|
# remove all the AssemblySwConnector
|
|
68
68
|
sw_component.removeAllAssemblySwConnector()
|
|
69
|
-
assert(len(sw_component.getAssemblySwConnectors()) == 0)
|
|
70
|
-
assert(len(sw_component.getDelegationSwConnectors()) == 3)
|
|
69
|
+
assert (len(sw_component.getAssemblySwConnectors()) == 0)
|
|
70
|
+
assert (len(sw_component.getDelegationSwConnectors()) == 3)
|
|
71
71
|
|
|
72
72
|
# remove all the DelegationSwConnector
|
|
73
73
|
sw_component.removeAllDelegationSwConnector()
|
|
74
|
-
assert(len(sw_component.getAssemblySwConnectors()) == 0)
|
|
75
|
-
assert(len(sw_component.getDelegationSwConnectors()) == 0)
|
|
74
|
+
assert (len(sw_component.getAssemblySwConnectors()) == 0)
|
|
75
|
+
assert (len(sw_component.getDelegationSwConnectors()) == 0)
|
|
76
76
|
|
|
77
77
|
def test_bswm_mode_arxml_loading_and_saving(self):
|
|
78
78
|
document = AUTOSAR.getInstance()
|
|
@@ -83,9 +83,20 @@ class TestSWComponents:
|
|
|
83
83
|
writer = ARXMLWriter()
|
|
84
84
|
writer.save("data/generated_AUTOSAR_Datatypes.arxml", document)
|
|
85
85
|
|
|
86
|
-
assert(filecmp.cmp("src/armodel/tests/test_files/BswMMode.arxml", "data/generated_AUTOSAR_Datatypes.arxml", shallow = False) == True)
|
|
86
|
+
assert (filecmp.cmp("src/armodel/tests/test_files/BswMMode.arxml", "data/generated_AUTOSAR_Datatypes.arxml", shallow = False) == True)
|
|
87
87
|
|
|
88
|
-
def
|
|
88
|
+
def test_sw_record_demo_arxml_loading_and_saving(self):
|
|
89
|
+
document = AUTOSAR.getInstance()
|
|
90
|
+
document.clear()
|
|
91
|
+
parser = ARXMLParser()
|
|
92
|
+
parser.load("src/armodel/tests/test_files/SwRecordDemo.arxml", document)
|
|
93
|
+
|
|
94
|
+
writer = ARXMLWriter()
|
|
95
|
+
writer.save("data/generated_SwRecordDemo.arxml", document)
|
|
96
|
+
|
|
97
|
+
assert (filecmp.cmp("src/armodel/tests/test_files/SwRecordDemo.arxml", "data/generated_SwRecordDemo.arxml", shallow = False) == True)
|
|
98
|
+
|
|
99
|
+
def test_application_data_type_blueprint_arxml_loading_and_saving(self):
|
|
89
100
|
document = AUTOSAR.getInstance()
|
|
90
101
|
document.clear()
|
|
91
102
|
parser = ARXMLParser()
|
|
@@ -94,7 +105,7 @@ class TestSWComponents:
|
|
|
94
105
|
writer = ARXMLWriter()
|
|
95
106
|
writer.save("data/generated_AUTOSAR_MOD_AISpecification_ApplicationDataType_Blueprint.arxml", document)
|
|
96
107
|
|
|
97
|
-
|
|
108
|
+
assert (filecmp.cmp("test_files/AUTOSAR_MOD_AISpecification_ApplicationDataType_Blueprint.arxml", "data/generated_AUTOSAR_MOD_AISpecification_ApplicationDataType_Blueprint.arxml", shallow = False) == True)
|
|
98
109
|
|
|
99
110
|
|
|
100
111
|
|
|
@@ -3,13 +3,13 @@ from ....writer.arxml_writer import ARXMLWriter
|
|
|
3
3
|
from ....parser.arxml_parser import ARXMLParser
|
|
4
4
|
from ....models.M2.AUTOSARTemplates.AutosarTopLevelStructure import AUTOSAR
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
class TestSystemTemplate:
|
|
7
8
|
def setup_method(self):
|
|
8
9
|
document = AUTOSAR.getInstance()
|
|
9
10
|
document.clear()
|
|
10
11
|
parser = ARXMLParser()
|
|
11
12
|
parser.load("src/armodel/tests/test_files/CanSystem.arxml", document)
|
|
12
|
-
|
|
13
13
|
|
|
14
14
|
def test_can_system_arxml_loading_and_saving(self):
|
|
15
15
|
document = AUTOSAR.getInstance()
|
|
@@ -20,10 +20,4 @@ class TestSystemTemplate:
|
|
|
20
20
|
writer = ARXMLWriter()
|
|
21
21
|
writer.save("data/generated_CanSystem.arxml", document)
|
|
22
22
|
|
|
23
|
-
assert(filecmp.cmp("src/armodel/tests/test_files/CanSystem.arxml", "data/generated_CanSystem.arxml", shallow
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
assert (filecmp.cmp("src/armodel/tests/test_files/CanSystem.arxml", "data/generated_CanSystem.arxml", shallow=False) is True)
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from ..models.M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.ARPackage import ARPackage
|
|
3
|
+
from ..models.M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.Identifiable import Describable, Identifiable
|
|
4
|
+
from ..models.M2.AUTOSARTemplates.AutosarTopLevelStructure import AUTOSAR
|
|
5
|
+
from ..transformer.abstract import AbstractTransformer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AdminDataTransformer(AbstractTransformer):
|
|
9
|
+
def __init__(self):
|
|
10
|
+
super().__init__()
|
|
11
|
+
self.logger = logging.getLogger()
|
|
12
|
+
|
|
13
|
+
def process_pkg(self, pkg: ARPackage):
|
|
14
|
+
for sub_package in pkg.getARPackages():
|
|
15
|
+
self.process_pkg(sub_package)
|
|
16
|
+
|
|
17
|
+
self.logger.debug("Remove AdminData of <%s>", pkg.getShortName())
|
|
18
|
+
pkg.removeAdminData()
|
|
19
|
+
|
|
20
|
+
for element in pkg.getElements():
|
|
21
|
+
if isinstance(element, Describable):
|
|
22
|
+
self.logger.debug("Remove AdminData of <%s>", element.getShortName())
|
|
23
|
+
element.removeAdminData()
|
|
24
|
+
elif isinstance(element, Identifiable):
|
|
25
|
+
self.logger.debug("Remove AdminData of <%s>", element.getShortName())
|
|
26
|
+
element.removeAdminData()
|
|
27
|
+
|
|
28
|
+
def remove(self, root: AUTOSAR):
|
|
29
|
+
root.removeAdminData()
|
|
30
|
+
for pkg in root.getARPackages():
|
|
31
|
+
self.process_pkg(pkg)
|
|
@@ -8,13 +8,15 @@ import logging
|
|
|
8
8
|
import xml.etree.cElementTree as ET
|
|
9
9
|
|
|
10
10
|
from ..models.M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.ArObject import ARObject
|
|
11
|
-
from ..models.M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.PrimitiveTypes import ARFloat, ARLiteral, ARNumerical, Integer, TimeValue
|
|
11
|
+
from ..models.M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.PrimitiveTypes import ARFloat, ARLiteral, ARNumerical, Integer, TimeValue
|
|
12
|
+
from ..models.M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.PrimitiveTypes import RefType, ARBoolean
|
|
13
|
+
|
|
12
14
|
|
|
13
15
|
class AbstractARXMLWriter:
|
|
14
16
|
__metaclass__ = ABCMeta
|
|
15
17
|
|
|
16
|
-
def __init__(self, options
|
|
17
|
-
if type(self)
|
|
18
|
+
def __init__(self, options=None) -> None:
|
|
19
|
+
if type(self) is AbstractARXMLWriter:
|
|
18
20
|
raise NotImplementedError("AbstractARXMLWriter is an abstract class.")
|
|
19
21
|
|
|
20
22
|
self.options = {}
|
|
@@ -25,7 +27,7 @@ class AbstractARXMLWriter:
|
|
|
25
27
|
self._processOptions(options=options)
|
|
26
28
|
|
|
27
29
|
self.nsmap = {
|
|
28
|
-
"xmlns": "http://autosar.org/schema/r4.0",
|
|
30
|
+
"xmlns": "http://autosar.org/schema/r4.0",
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
def _processOptions(self, options):
|
|
@@ -34,23 +36,23 @@ class AbstractARXMLWriter:
|
|
|
34
36
|
self.options['warning'] = options['warning']
|
|
35
37
|
|
|
36
38
|
def _raiseError(self, error_msg):
|
|
37
|
-
if (self.options['warning']
|
|
39
|
+
if (self.options['warning'] is True):
|
|
38
40
|
self.logger.error(Fore.RED + error_msg + Fore.WHITE)
|
|
39
41
|
else:
|
|
40
42
|
raise ValueError(error_msg)
|
|
41
43
|
|
|
42
44
|
def notImplemented(self, error_msg):
|
|
43
|
-
if (self.options['warning']
|
|
45
|
+
if (self.options['warning'] is True):
|
|
44
46
|
self.logger.error(Fore.RED + error_msg + Fore.WHITE)
|
|
45
47
|
else:
|
|
46
48
|
raise NotImplementedError(error_msg)
|
|
47
49
|
|
|
48
50
|
def writeARObjectAttributes(self, element: ET.Element, ar_obj: ARObject):
|
|
49
51
|
if ar_obj.timestamp is not None:
|
|
50
|
-
self.logger.debug("Timestamp: %s" % ar_obj.timestamp)
|
|
52
|
+
# self.logger.debug("Timestamp: %s" % ar_obj.timestamp)
|
|
51
53
|
element.attrib['T'] = ar_obj.timestamp
|
|
52
54
|
if ar_obj.uuid is not None:
|
|
53
|
-
self.logger.debug("UUID: %s" % ar_obj.uuid)
|
|
55
|
+
# self.logger.debug("UUID: %s" % ar_obj.uuid)
|
|
54
56
|
element.attrib['UUID'] = ar_obj.uuid
|
|
55
57
|
|
|
56
58
|
'''
|
|
@@ -78,14 +80,7 @@ class AbstractARXMLWriter:
|
|
|
78
80
|
|
|
79
81
|
def setChildElementOptionalPositiveInteger(self, element: ET.Element, key: str, value: Integer):
|
|
80
82
|
self.setChildElementOptionalNumericalValue(element, key, value)
|
|
81
|
-
|
|
82
|
-
def setChildElementOptionalLiteral(self, element: ET.Element, key: str, literal: ARLiteral):
|
|
83
|
-
if literal is not None:
|
|
84
|
-
child_element = ET.SubElement(element, key)
|
|
85
|
-
self.writeARObjectAttributes(child_element, literal)
|
|
86
|
-
if literal._value is not None:
|
|
87
|
-
child_element.text = str(literal._value)
|
|
88
|
-
|
|
83
|
+
|
|
89
84
|
def setChildElementOptionalRevisionLabelString(self, element: ET.Element, key: str, literal: ARLiteral):
|
|
90
85
|
self.setChildElementOptionalLiteral(element, key, literal)
|
|
91
86
|
|
|
@@ -111,7 +106,6 @@ class AbstractARXMLWriter:
|
|
|
111
106
|
self.setChildElementOptionalFloatValue(element, key, value)
|
|
112
107
|
|
|
113
108
|
def setChildElementOptionalBooleanValue(self, element: ET.Element, key: str, value: ARBoolean) -> ET.Element:
|
|
114
|
-
child_element = None
|
|
115
109
|
if value is not None:
|
|
116
110
|
child_element = ET.SubElement(element, key)
|
|
117
111
|
self.writeARObjectAttributes(child_element, value)
|
|
@@ -119,30 +113,29 @@ class AbstractARXMLWriter:
|
|
|
119
113
|
return element
|
|
120
114
|
|
|
121
115
|
def setChildElementOptionalLiteral(self, element: ET.Element, key: str, value: ARLiteral) -> ET.Element:
|
|
122
|
-
child_element = None
|
|
123
116
|
if value is not None:
|
|
124
117
|
child_element = ET.SubElement(element, key)
|
|
125
118
|
self.writeARObjectAttributes(child_element, value)
|
|
126
119
|
child_element.text = value.getText()
|
|
127
|
-
return element
|
|
128
|
-
|
|
120
|
+
return element
|
|
121
|
+
|
|
129
122
|
def patch_xml(self, xml: str) -> str:
|
|
130
|
-
xml = re.sub(r"\<([\w-]+)\/\>",r"<\1></\1>", xml)
|
|
131
|
-
xml = re.sub(r"<(
|
|
132
|
-
xml = re.sub(r""", '"', xml)
|
|
123
|
+
xml = re.sub(r"\<([\w-]+)\/\>", r"<\1></\1>", xml)
|
|
124
|
+
# xml = re.sub(r"<([\w-]+)\s+(\w+)=(\"[\w-]+\")\/>", r"<\1 \2=\3></\1>", xml)
|
|
125
|
+
# xml = re.sub(r""", '"', xml)
|
|
133
126
|
return xml
|
|
134
127
|
|
|
135
128
|
def saveToFile(self, filename, root: ET.Element):
|
|
136
|
-
if sys.version_info <= (3,9):
|
|
137
|
-
xml = ET.tostring(root, encoding
|
|
129
|
+
if sys.version_info <= (3, 9):
|
|
130
|
+
xml = ET.tostring(root, encoding="UTF-8", short_empty_elements=False)
|
|
138
131
|
else:
|
|
139
|
-
xml = ET.tostring(root, encoding
|
|
132
|
+
xml = ET.tostring(root, encoding="UTF-8", xml_declaration=True, short_empty_elements=False)
|
|
140
133
|
|
|
141
134
|
dom = minidom.parseString(xml.decode())
|
|
142
|
-
xml = dom.toprettyxml(indent
|
|
135
|
+
xml = dom.toprettyxml(indent=" ", encoding="UTF-8")
|
|
143
136
|
|
|
144
137
|
text = self.patch_xml(xml.decode())
|
|
145
138
|
|
|
146
139
|
with open(filename, "w", encoding="utf-8") as f_out:
|
|
147
|
-
#f_out.write(xml.decode())
|
|
148
|
-
f_out.write(text)
|
|
140
|
+
# f_out.write(xml.decode())
|
|
141
|
+
f_out.write(text)
|