from schema_lab import run_cases
# 蓝色天空网 mbsky.com:独立输入与逐项预期。
SCENARIOS = [{'id': '1',
'schema': 'schemas/simple-string.xsd',
'input': '<v>学习者</v>',
'expected': True,
'goal': "string有效词法/值 '学习者'"},
{'id': '2',
'schema': 'schemas/simple-string.xsd',
'input': '<v></v>',
'expected': True,
'goal': "string有效词法/值 ''"},
{'id': '3',
'schema': 'schemas/simple-string.xsd',
'input': '<v><child/></v>',
'expected': False,
'goal': "string拒绝边界 '<child/>'"},
{'id': '4',
'schema': 'schemas/simple-decimal.xsd',
'input': '<v>12.50</v>',
'expected': True,
'goal': "decimal有效词法/值 '12.50'"},
{'id': '5',
'schema': 'schemas/simple-decimal.xsd',
'input': '<v>+12</v>',
'expected': True,
'goal': "decimal有效词法/值 '+12'"},
{'id': '6',
'schema': 'schemas/simple-decimal.xsd',
'input': '<v>0</v>',
'expected': True,
'goal': "decimal有效词法/值 '0'"},
{'id': '7',
'schema': 'schemas/simple-decimal.xsd',
'input': '<v>1e2</v>',
'expected': False,
'goal': "decimal拒绝边界 '1e2'"},
{'id': '8',
'schema': 'schemas/simple-decimal.xsd',
'input': '<v>NaN</v>',
'expected': False,
'goal': "decimal拒绝边界 'NaN'"},
{'id': '9',
'schema': 'schemas/simple-integer.xsd',
'input': '<v>36</v>',
'expected': True,
'goal': "integer有效词法/值 '36'"},
{'id': '10',
'schema': 'schemas/simple-integer.xsd',
'input': '<v>+36</v>',
'expected': True,
'goal': "integer有效词法/值 '+36'"},
{'id': '11',
'schema': 'schemas/simple-integer.xsd',
'input': '<v>36.0</v>',
'expected': False,
'goal': "integer拒绝边界 '36.0'"},
{'id': '12',
'schema': 'schemas/simple-integer.xsd',
'input': '<v>hello</v>',
'expected': False,
'goal': "integer拒绝边界 'hello'"},
{'id': '13',
'schema': 'schemas/simple-boolean.xsd',
'input': '<v>true</v>',
'expected': True,
'goal': "boolean有效词法/值 'true'"},
{'id': '14',
'schema': 'schemas/simple-boolean.xsd',
'input': '<v>false</v>',
'expected': True,
'goal': "boolean有效词法/值 'false'"},
{'id': '15',
'schema': 'schemas/simple-boolean.xsd',
'input': '<v>1</v>',
'expected': True,
'goal': "boolean有效词法/值 '1'"},
{'id': '16',
'schema': 'schemas/simple-boolean.xsd',
'input': '<v>0</v>',
'expected': True,
'goal': "boolean有效词法/值 '0'"},
{'id': '17',
'schema': 'schemas/simple-boolean.xsd',
'input': '<v>TRUE</v>',
'expected': False,
'goal': "boolean拒绝边界 'TRUE'"},
{'id': '18',
'schema': 'schemas/simple-boolean.xsd',
'input': '<v>yes</v>',
'expected': False,
'goal': "boolean拒绝边界 'yes'"},
{'id': '19',
'schema': 'schemas/simple-date.xsd',
'input': '<v>2026-11-03</v>',
'expected': True,
'goal': "date有效词法/值 '2026-11-03'"},
{'id': '20',
'schema': 'schemas/simple-date.xsd',
'input': '<v>2026-13-03</v>',
'expected': False,
'goal': "date拒绝边界 '2026-13-03'"},
{'id': '21',
'schema': 'schemas/simple-time.xsd',
'input': '<v>09:30:10.5</v>',
'expected': True,
'goal': "time有效词法/值 '09:30:10.5'"},
{'id': '22',
'schema': 'schemas/simple-time.xsd',
'input': '<v>09:30</v>',
'expected': False,
'goal': "time拒绝边界 '09:30'"},
{'id': '23',
'schema': 'schemas/element-default.xsd',
'input': '<root><color/></root>',
'expected': True,
'goal': '存在空元素'},
{'id': '24',
'schema': 'schemas/element-default.xsd',
'input': '<root/>',
'expected': False,
'goal': '默认不创建缺失必需元素'},
{'id': '25',
'schema': 'schemas/element-default.xsd',
'input': '<root><color>red</color></root>',
'expected': True,
'goal': '显式其他值与fixed区别'},
{'id': '26',
'schema': 'schemas/element-fixed.xsd',
'input': '<root><color/></root>',
'expected': True,
'goal': '存在空元素'},
{'id': '27',
'schema': 'schemas/element-fixed.xsd',
'input': '<root/>',
'expected': False,
'goal': '默认不创建缺失必需元素'},
{'id': '28',
'schema': 'schemas/element-fixed.xsd',
'input': '<root><color>red</color></root>',
'expected': False,
'goal': '显式其他值与fixed区别'}]
if __name__ == "__main__":
run_cases('schema-simple', SCENARIOS)
本例需在 Windows / Python3.12 / xmlschema4.3.2 XMLSchema10 / elementpath5.1.4;lxml6.1.3+libxml2.11.9交叉观察 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows / Python3.12 / xmlschema4.3.2 XMLSchema10 / elementpath5.1.4;lxml6.1.3+libxml2.11.9交叉观察
入口文件:projects/schema-lab/schema-simple.py
预期结果与验证条件观察提示
- 本章28项主验证结果与逐项预期一致。
- 具体分支:string有效词法/值 '学习者';string有效词法/值 '';string拒绝边界 '<child/>';decimal有效词法/值 '12.50';decimal有效词法/值 '+12';decimal有效词法/值 '0';decimal拒绝边界 '1e2';其余分支逐项列于清单与源码。
- lxml观察可能不同,所有差异保留为处理器限制/后续复核,不能据此升级完整语义或其它处理器。
请结合实际环境逐项观察。
附件与关联工程包下载
课程关联工程包(登记关联24章) · 含当前章节或实例 · mbskycom202611a529.zip