forked from huangxin/ailai
first commit
This commit is contained in:
34
CU/test_Catch_EMV.py
Normal file
34
CU/test_Catch_EMV.py
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
# 假设你的模块名为 CU,Catch 定义在 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()
|
||||
Reference in New Issue
Block a user