上传初版SDK
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
"""
|
||||
集成测试 - 完整 ARXML 文件生成
|
||||
"""
|
||||
import pytest
|
||||
from xml.dom.minidom import Document
|
||||
from src import (
|
||||
create_base_type,
|
||||
create_unit,
|
||||
create_data_constraint,
|
||||
create_compu_method,
|
||||
create_linear,
|
||||
create_boolean_type,
|
||||
create_value_type,
|
||||
create_structure_type,
|
||||
create_impl_value_type,
|
||||
create_sender_receiver_interface,
|
||||
SenderReceiverInterface,
|
||||
ApplicationStructureDataType,
|
||||
Category,
|
||||
CalibrationAccess,
|
||||
)
|
||||
|
||||
|
||||
class TestARXMLGeneration:
|
||||
"""ARXML 生成测试"""
|
||||
|
||||
def test_full_type_chain(self):
|
||||
"""测试完整的类型链(应用类型 -> 实现类型 -> 基础类型)"""
|
||||
base_type = create_base_type("UInt8", size=8)
|
||||
assert base_type.name == "UInt8"
|
||||
|
||||
impl_type = create_impl_value_type("ImplUInt8", base_type=base_type)
|
||||
assert impl_type.name == "ImplUInt8"
|
||||
assert impl_type.base_type == base_type
|
||||
|
||||
app_type = create_value_type("AppUInt8")
|
||||
assert app_type.name == "AppUInt8"
|
||||
|
||||
doc = Document()
|
||||
base_element = base_type.to_arxml(doc)
|
||||
assert base_element.tagName == "SW-BASE-TYPE"
|
||||
|
||||
impl_element = impl_type.to_arxml(doc)
|
||||
assert impl_element.tagName == "IMPLEMENTATION-DATA-TYPE"
|
||||
|
||||
app_element = app_type.to_arxml(doc)
|
||||
assert app_element.tagName == "APPLICATION-PRIMITIVE-DATA-TYPE"
|
||||
|
||||
def test_unit_with_compu_method(self):
|
||||
"""测试单位与计算方法关联"""
|
||||
unit = create_unit("kmh", display="km/h")
|
||||
|
||||
linear = create_linear(factor=0.01, offset=0)
|
||||
compu = create_compu_method("SpeedConversion", unit=unit, linear=linear)
|
||||
assert compu.unit == unit
|
||||
assert compu.linear == linear
|
||||
|
||||
def test_complex_structure(self):
|
||||
"""测试复杂结构体"""
|
||||
member1 = ApplicationStructureDataType.StructureElement(name="temperature")
|
||||
member2 = ApplicationStructureDataType.StructureElement(name="humidity")
|
||||
|
||||
struct = create_structure_type("EnvironmentData", elements=[member1, member2])
|
||||
assert len(struct.structure_elements) == 2
|
||||
|
||||
doc = Document()
|
||||
element = struct.to_arxml(doc)
|
||||
assert element.tagName == "APPLICATION-RECORD-DATA-TYPE"
|
||||
|
||||
def test_interface_creation(self):
|
||||
"""测试接口创建"""
|
||||
data_element = SenderReceiverInterface.DataElement(name="SpeedData")
|
||||
interface = create_sender_receiver_interface(
|
||||
"SpeedInterface",
|
||||
data_element=data_element,
|
||||
is_service=False
|
||||
)
|
||||
|
||||
assert interface.name == "SpeedInterface"
|
||||
assert interface.data_element == data_element
|
||||
|
||||
doc = Document()
|
||||
element = interface.to_arxml(doc)
|
||||
assert element.tagName == "SENDER-RECEIVER-INTERFACE"
|
||||
|
||||
def test_data_constraint_chain(self):
|
||||
"""测试数据约束链"""
|
||||
unit = create_unit("percent", display="%")
|
||||
constraint = create_data_constraint(
|
||||
"PercentageRange",
|
||||
lower=0,
|
||||
upper=100,
|
||||
unit=unit
|
||||
)
|
||||
|
||||
assert constraint.unit == unit
|
||||
assert constraint.lower == 0
|
||||
assert constraint.upper == 100
|
||||
|
||||
doc = Document()
|
||||
element = constraint.to_arxml(doc)
|
||||
assert element.tagName == "DATA-CONSTR"
|
||||
|
||||
def test_package_creation(self):
|
||||
"""测试包创建"""
|
||||
from src import create_package, create_base_type
|
||||
|
||||
base_type = create_base_type("TestType")
|
||||
pkg = create_package("TestPackage", elements=[base_type])
|
||||
|
||||
assert pkg.name == "TestPackage"
|
||||
assert len(pkg.elements) == 1
|
||||
assert pkg.get_element("TestType") == base_type
|
||||
|
||||
def test_package_to_arxml(self):
|
||||
"""测试包 ARXML 转换"""
|
||||
from src import create_package, create_base_type
|
||||
|
||||
base_type = create_base_type("PackageType")
|
||||
pkg = create_package("MyPackage", elements=[base_type])
|
||||
|
||||
doc = Document()
|
||||
element = pkg.to_arxml(doc)
|
||||
|
||||
assert element.tagName == "AR-PACKAGE"
|
||||
assert element.hasAttribute("UUID")
|
||||
|
||||
short_name = element.getElementsByTagName("SHORT-NAME")[0]
|
||||
assert short_name.firstChild.nodeValue == "MyPackage"
|
||||
|
||||
elements = element.getElementsByTagName("ELEMENTS")
|
||||
assert len(elements) == 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-v"])
|
||||
Reference in New Issue
Block a user