2026-03-13 21:04:19 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""
|
|
|
|
|
pytest 测试示例
|
|
|
|
|
"""
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
import pytest
|
|
|
|
|
import time
|
2026-04-07 09:51:38 +08:00
|
|
|
from core.system_state import SystemState,PD_StatusEnum
|
2026-03-13 21:04:19 +08:00
|
|
|
from core.system import FeedingControlSystem
|
|
|
|
|
from busisness.models import ArtifactInfo,FreqRecordModel
|
|
|
|
|
from busisness.blls import FreqRecordBll
|
2026-04-07 09:51:38 +08:00
|
|
|
from hardware.relay import RelayController
|
2026-03-13 21:04:19 +08:00
|
|
|
|
|
|
|
|
system=FeedingControlSystem()
|
2026-04-07 09:51:38 +08:00
|
|
|
system.state.current_mould=ArtifactInfo(MouldCode="SHR2F-8")
|
2026-03-13 21:04:19 +08:00
|
|
|
|
|
|
|
|
def test_pd_record_send():
|
|
|
|
|
"""测试派单记录发送"""
|
|
|
|
|
system.send_pd_data()
|
|
|
|
|
|
|
|
|
|
def test_api_process():
|
|
|
|
|
system._process_api_db()
|
|
|
|
|
|
2026-04-07 09:51:38 +08:00
|
|
|
|
|
|
|
|
|
2026-03-13 21:04:19 +08:00
|
|
|
def test_freq_record_send():
|
|
|
|
|
"""测试频率记录发送"""
|
|
|
|
|
bll=FreqRecordBll()
|
|
|
|
|
record_id=bll.insert_freq_record(FreqRecordModel(ArtifactID='12',ArtifactActionID=1,MouldCode="SHR2B3-5",Freq=100.0))
|
|
|
|
|
assert record_id > 0
|
|
|
|
|
|
2026-04-07 09:51:38 +08:00
|
|
|
def test_upper_to_jbl():
|
|
|
|
|
"""测试上料斗到搅拌楼"""
|
|
|
|
|
relay = RelayController()
|
|
|
|
|
relay.control_upper_to_jbl()
|
|
|
|
|
|
|
|
|
|
def test_upper_to_zd():
|
|
|
|
|
"""测试上料斗到料斗"""
|
|
|
|
|
relay = RelayController()
|
|
|
|
|
relay.control_upper_to_zd()
|
|
|
|
|
|
2026-03-13 21:04:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def add(a, b):
|
|
|
|
|
"""简单的加法函数"""
|
|
|
|
|
return a + b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_add():
|
|
|
|
|
"""测试加法函数"""
|
|
|
|
|
assert add(1, 2) == 4
|
|
|
|
|
assert add(0, 0) == 0
|
|
|
|
|
assert add(-1, 1) == 0
|
|
|
|
|
assert add(100, 200) == 300
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def multiply(a, b):
|
|
|
|
|
"""简单的乘法函数"""
|
|
|
|
|
return a * b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_multiply():
|
|
|
|
|
"""测试乘法函数"""
|
|
|
|
|
assert multiply(2, 3) == 6
|
|
|
|
|
assert multiply(0, 5) == 0
|
|
|
|
|
assert multiply(-2, 3) == -6
|
|
|
|
|
assert multiply(10, 10) == 100
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Calculator:
|
|
|
|
|
"""简单的计算器类"""
|
|
|
|
|
|
|
|
|
|
def add(self, a, b):
|
|
|
|
|
return a + b
|
|
|
|
|
|
|
|
|
|
def subtract(self, a, b):
|
|
|
|
|
return a - b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calculator():
|
|
|
|
|
"""测试计算器类"""
|
|
|
|
|
calc = Calculator()
|
|
|
|
|
assert calc.add(1, 2) == 3
|
|
|
|
|
assert calc.subtract(5, 2) == 3
|
|
|
|
|
assert calc.subtract(2, 5) == -3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("a, b, expected", [
|
|
|
|
|
(1, 2, 3),
|
|
|
|
|
(0, 0, 0),
|
|
|
|
|
(-1, 1, 0),
|
|
|
|
|
(100, 200, 300)
|
|
|
|
|
])
|
|
|
|
|
def test_add_parametrized(a, b, expected):
|
|
|
|
|
"""参数化测试加法函数"""
|
|
|
|
|
assert add(a, b) == expected
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
# 运行所有测试
|
|
|
|
|
|
|
|
|
|
system.opcua_client_feed.start()
|
2026-04-07 09:51:38 +08:00
|
|
|
system.opcua_client_feed.start_accept()
|
|
|
|
|
# system.start_opc_queue_thread()
|
|
|
|
|
|
|
|
|
|
# system.start_pd_thread()
|
|
|
|
|
# time.sleep(10)
|
|
|
|
|
# system.state.pd_status=PD_StatusEnum.PD_Ready
|
|
|
|
|
# test_pd_record_send()
|
2026-03-13 21:04:19 +08:00
|
|
|
# pytest.main([f'{__file__}::test_api_process'])
|
|
|
|
|
# pytest.main([f'{__file__}::test_freq_record_send'])
|
2026-04-07 09:51:38 +08:00
|
|
|
# pytest.main([f'{__file__}::test_upper_to_jbl'])
|
|
|
|
|
# relay = RelayController()
|
|
|
|
|
# relay.control(relay.UPPER_TO_ZD, 'close')
|
|
|
|
|
# relay.control(relay.UPPER_TO_JBL, 'close')
|
|
|
|
|
# pytest.main([f'{__file__}::test_upper_to_zd'])
|
|
|
|
|
|
2026-03-13 21:04:19 +08:00
|
|
|
while True:
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|