四川信德建设有限公司网站可以直接进入网址的正能量大豆网
2026/4/17 20:02:04 网站建设 项目流程
四川信德建设有限公司网站,可以直接进入网址的正能量大豆网,php网站建设填空题,怎么下载ppt模板第 18 篇#xff1a;按依赖顺序 复杂度由低到高逐步推进pytest单元测试** 我们采用“依赖顺序 复杂度由低到高”的策略组织单元测试#xff0c;确保底层模块先通过测试#xff0c;上层模块再依赖可靠的基础。测试优先覆盖纯函数、无外部依赖的模块#xff0c;再逐步扩展…第 18 篇按依赖顺序 复杂度由低到高逐步推进pytest单元测试**我们采用“依赖顺序 复杂度由低到高”的策略组织单元测试确保底层模块先通过测试上层模块再依赖可靠的基础。测试优先覆盖纯函数、无外部依赖的模块再逐步扩展到涉及线程、信号、文件 I/O、模拟器等复杂模块。测试模块顺序依赖与复杂度递增core/protocol/pelco_protocol.py—— 最基础纯函数无外部依赖core/macro/standard.py—— CommandValidator、范围校验core/alarm/rules.py—— load/save/executecore/macro/parser.py—— lexer/parsercore/template/renderer.py—— 模板渲染core/utils/log_emitter.py—— 信号、缓冲区core/macro/commands.py—— 命令执行核心core/macro/engine.py—— 宏执行引擎core/serial/protocol.py—— 帧提取与解析core/serial/manager.py worker.py—— 串口管理与线程core/template/library.py—— 模板文件管理core/simulator/virtual_device.py—— 模拟器状态机18.1 core/protocol/pelco_protocol.py 单元测试测试文件tests/unit/test_pelco_protocol.py覆盖要点build_pelco_d / build_pelco_p不同参数组合parse_pelco_packetD/P 协议自动识别、PTZ、预置位、AUX、校验和错误、未知命令9 字节变体兼容性若启用边界值与非法帧处理运行命令pytest tests/unit/test_pelco_protocol.py -v --tbshort预期所有测试用例通过显示具体参数化测试名称及 PASS。18.2 core/macro/standard.py 单元测试测试文件tests/unit/test_standard.py覆盖要点常量、枚举完整性COMMAND_SPECS 结构校验validate_command正常、未知命令、参数数量/类型/范围错误E001~E004可选参数处理cam_id 默认值静态方法get_command_spec、list_all_commands、get_commands_by_category边界值speed ±100、preset 1~255、aux 1~8运行命令pytest tests/unit/test_standard.py -v --tbshort预期约 20 个测试全部通过。18.3 core/alarm/rules.py 单元测试测试文件tests/unit/test_alarm_rules.py覆盖要点load_alarm_rules / save_alarm_rules文件读写、空文件、异常处理execute_alarm_action不同 action 类型run_macro、load_template、notify、ack 等规则过滤enabled、alarm_code 匹配最后触发时间更新运行命令pytest tests/unit/test_alarm_rules.py -v --tbshort预期全部通过含 mock 文件 I/O 和动作执行。18.4 core/macro/parser.py 单元测试测试文件tests/unit/test_parser.py覆盖要点Lexertoken 识别数字、ID、字符串、注释、符号Parser简单命令、字符串、变量、loop、for、if/else、嵌套结构语法错误恢复不崩溃返回部分 AST位置信息line/column准确性运行命令pytest tests/unit/test_parser.py -v --tbshort18.5 core/template/renderer.py 单元测试测试文件tests/unit/test_renderer.py覆盖要点{{{name}}} → 原始值替换{{name}} → 类型转换int/float → 数字字符串、bool → “true”/“false”、str → 加引号缺少参数 → ValueError 日志空参数字典 → 返回原始脚本运行命令pytest tests/unit/test_renderer.py -v --tbshort18.6 core/utils/log_emitter.py 单元测试测试文件tests/unit/test_log_emitter.py覆盖要点单例模式get_log_emitter 返回同一实例各日志方法info、warning、error、send、receive、simulator、alarm信号发射缓冲区机制use_bufferTrue 时进入缓冲flush 后触发 logs_batcherror 触发 error_occurred 信号非法日志类型自动转为 info运行命令pytest tests/unit/test_log_emitter.py -v --tbshort18.7 core/macro/commands.py 单元测试测试文件tests/unit/test_commands.py覆盖要点各 cmd_xxx 方法ptz_control、zoom、focus、iris、preset、aux、pattern 等参数验证CommandValidator默认 cam_id 处理执行日志记录异常情况未知命令、无效参数运行命令pytest tests/unit/test_commands.py -v --covcore/macro/commands --cov-reportterm-missing18.8 core/macro/engine.py 单元测试测试文件tests/unit/test_macro_engine.py覆盖要点生命周期init、set_script、run、stop、pause/resumeAST 执行命令、loop、for、if信号started、stopped、error、progress、command_executed进度计算、检查点、缓存异常安全与日志运行命令pytest tests/unit/test_macro_engine.py -v --tbshort18.9 core/serial/protocol.py 单元测试测试文件tests/unit/test_serial_protocol.py覆盖要点detect_protocolD/P/未知extract_frame完整帧、不完整、校验失败parse_framePTZ、zoom、preset、query、错误帧、Pelco-P 未知命令校验和验证运行命令pytest tests/unit/test_serial_protocol.py -v --tbshort18.10 core/serial/manager.py worker.py 单元测试测试文件tests/unit/test_serial_manager_worker.py覆盖要点open/close/write/is_open信号转发opened、closed、error、data_received、parsed_received默认 cam_id 同步到控制方法运行命令pytest tests/unit/test_serial_manager_worker.py -v --tbshort18.11 core/template/library.py 单元测试测试文件tests/unit/test_template_library.py覆盖要点load/saveJSON 读写、异常处理find存在/不存在_validate_template合法/非法结构_create_default_templates缓存机制首次加载后复用运行命令pytest tests/unit/test_template_library.py -v --tbshort18.12 core/simulator/virtual_device.py 单元测试测试文件tests/unit/test_virtual_device.py覆盖要点process_commandACK、查询响应、错误响应update_from_commandPTZ、zoom、focus、iris、auxgenerate_response各查询类型状态范围限制pan/tilt/zoom运行命令pytest tests/unit/test_virtual_device.py -v --tbshort测试执行建议按顺序运行上述测试文件确保底层模块先通过。使用--cov生成覆盖率报告关注未覆盖分支。所有测试均使用 mock 避免真实串口/文件依赖保证快速稳定。通过后可继续集成测试serial protocol macro。下一阶段完成以上单元测试后我们进入集成测试阶段。上一篇 按照pytest自动化测试方案规划建立测试基础框架总目录Python开发软键盘全程总览下一篇

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询