82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
"""
|
|
核心模块测试
|
|
"""
|
|
import pytest
|
|
from src.core.base import Base, create_uuid, create_text_element
|
|
from src.core.enums import Category, Encoding, CalibrationAccess
|
|
|
|
|
|
class TestBase:
|
|
"""Base 基类测试"""
|
|
|
|
def test_base_creation(self):
|
|
"""测试基本创建"""
|
|
base = Base(name="TestElement")
|
|
assert base.name == "TestElement"
|
|
assert base.id is None
|
|
assert base.parent is None
|
|
assert base.description is None
|
|
|
|
def test_base_with_parent(self):
|
|
"""测试带父元素的创建"""
|
|
parent = Base(name="Parent")
|
|
child = Base(name="Child", parent=parent)
|
|
assert child.parent == parent
|
|
assert child.parent_id == parent.id
|
|
|
|
def test_package_path(self):
|
|
"""测试包路径计算"""
|
|
parent = Base(name="Parent")
|
|
child = Base(name="Child", parent=parent)
|
|
assert child.package_path == "/Parent/Child"
|
|
|
|
def test_package_path_deep(self):
|
|
"""测试深层包路径"""
|
|
level1 = Base(name="Level1")
|
|
level2 = Base(name="Level2", parent=level1)
|
|
level3 = Base(name="Level3", parent=level2)
|
|
level4 = Base(name="Level4", parent=level3)
|
|
assert level4.package_path == "/Level1/Level2/Level3/Level4"
|
|
|
|
|
|
class TestUtilityFunctions:
|
|
"""工具函数测试"""
|
|
|
|
def test_create_uuid(self):
|
|
"""测试 UUID 生成"""
|
|
uuid1 = create_uuid()
|
|
uuid2 = create_uuid()
|
|
assert uuid1 != uuid2
|
|
assert len(uuid1) == 36
|
|
|
|
def test_create_text_element(self):
|
|
"""测试文本元素创建"""
|
|
import xml.dom.minidom as Dom
|
|
|
|
doc = Dom.Document()
|
|
element = create_text_element(doc, "TEST_TAG", "test_value")
|
|
|
|
assert element.tagName == "TEST_TAG"
|
|
assert element.firstChild.nodeValue == "test_value"
|
|
|
|
|
|
class TestEnums:
|
|
"""枚举类型测试"""
|
|
|
|
def test_category_enum(self):
|
|
"""测试 Category 枚举"""
|
|
assert Category.FIXED_LENGTH is not None
|
|
assert Category.VALUE is not None
|
|
assert Category.STRUCTURE is not None
|
|
assert Category.ARRAY is not None
|
|
|
|
def test_calibration_access_enum(self):
|
|
"""测试 CalibrationAccess 枚举"""
|
|
assert CalibrationAccess.READ_ONLY is not None
|
|
assert CalibrationAccess.READ_WRITE is not None
|
|
assert CalibrationAccess.NOT_ACCESSIBLE is not None
|
|
assert CalibrationAccess.NOT_SPECIFIED is not None
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pytest.main([__file__, "-v"]) |