54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
# tests/test_feeding_process.py
|
|
import unittest
|
|
from unittest.mock import patch, MagicMock
|
|
import sys
|
|
import os
|
|
from config.settings import app_set_config
|
|
|
|
# 添加项目根目录到Python路径
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
from feeding.process import FeedingProcess
|
|
|
|
|
|
class TestFeedingProcess(unittest.TestCase):
|
|
|
|
@patch('feeding.process.RelayController')
|
|
@patch('feeding.process.InverterController')
|
|
@patch('feeding.process.TransmitterController')
|
|
def test_initialization(self, mock_transmitter, mock_inverter, mock_relay):
|
|
"""测试初始化"""
|
|
# 创建模拟对象
|
|
mock_relay_instance = MagicMock()
|
|
mock_relay.return_value = mock_relay_instance
|
|
|
|
mock_inverter_instance = MagicMock()
|
|
mock_inverter.return_value = mock_inverter_instance
|
|
|
|
mock_transmitter_instance = MagicMock()
|
|
mock_transmitter.return_value = mock_transmitter_instance
|
|
|
|
# 创建系统实例
|
|
system = FeedingProcess()
|
|
|
|
# 验证初始化
|
|
self.assertIsNotNone(system)
|
|
self.assertFalse(system.state.running)
|
|
|
|
def test_set_feeding_parameters(self):
|
|
"""测试设置下料参数"""
|
|
with patch('feeding.process.RelayController'), \
|
|
patch('feeding.process.InverterController'), \
|
|
patch('feeding.process.TransmitterController'):
|
|
system = FeedingProcess()
|
|
#修改参数 app_set_config.single_batch_weight = 1500
|
|
app_set_config.min_required_weight = 300
|
|
app_set_config.target_vehicle_weight = 3000
|
|
|
|
self.assertEqual(app_set_config.target_vehicle_weight, 3000)
|
|
self.assertEqual(app_set_config.min_required_weight, 300)
|
|
self.assertEqual(app_set_config.single_batch_weight, 1500)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main() |