Files
ailai_show/CU/test_Catch_EMV.py
2025-07-29 13:16:30 +08:00

34 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import unittest
from unittest.mock import patch, MagicMock
# 假设你的模块名为 CUCatch 定义在 CU/Catch.py
from CU.Catch import Catch, CatchStatus
class TestCatchRelayControl(unittest.TestCase):
@patch('CU.EMV.close') # 只mock close函数因为我们只关心关闭电磁阀1
def test_catch_status_ctake_calls_close_relay(self, mock_close):
# 创建一个 mock 的 RobotClient不需要真实实现
mock_robot_client = MagicMock()
mock_robot_client.time_delay_put = 0.5
mock_robot_client.con_ios = [0, 1, 2]
# 实例化 Catch 类
catch_instance = Catch(mock_robot_client)
# 设置状态为 CTake
catch_instance.catch_status = CatchStatus.CTake
# 第一次 run应该触发 close(1, 0, 0)
catch_instance.run()
# 验证 close 是否被调用,并且是 close(1, 0, 0)
mock_close.assert_called_once_with(1, 0, 0)
# 再次 run不应再次调用 close
catch_instance.run()
self.assertEqual(mock_close.call_count, 1) # 确保只调用了一次
if __name__ == '__main__':
unittest.main()