100 lines
2.1 KiB
Python
100 lines
2.1 KiB
Python
#!/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
|
|
from core.system_state import SystemState
|
|
from core.system import FeedingControlSystem
|
|
from busisness.models import ArtifactInfo,FreqRecordModel
|
|
from busisness.blls import FreqRecordBll
|
|
|
|
system=FeedingControlSystem()
|
|
system.state.current_mould=ArtifactInfo(MouldCode="SHR2B3-5")
|
|
|
|
def test_pd_record_send():
|
|
"""测试派单记录发送"""
|
|
system.send_pd_data()
|
|
|
|
def test_api_process():
|
|
system._process_api_db()
|
|
|
|
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
|
|
|
|
|
|
|
|
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()
|
|
system.start_opc_queue_thread()
|
|
|
|
test_pd_record_send()
|
|
# pytest.main([f'{__file__}::test_api_process'])
|
|
# pytest.main([f'{__file__}::test_freq_record_send'])
|
|
while True:
|
|
time.sleep(1)
|
|
|
|
|