- Moved all project files and directories (config, core, models, etc.) from edge_inference_service/ to the repository root ai_edge/ - Updated model path in config/settings.py to reflect new structure - Revised usage paths in __init__.py documentation
106 lines
2.7 KiB
Python
106 lines
2.7 KiB
Python
"""
|
|
结果上报模块单元测试
|
|
"""
|
|
|
|
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
from datetime import datetime
|
|
import sys
|
|
import os
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
class TestMQTTClient(unittest.TestCase):
|
|
"""测试MQTT客户端"""
|
|
|
|
def test_client_creation(self):
|
|
"""测试客户端创建"""
|
|
from core.result_reporter import MQTTClient
|
|
from config.settings import MQTTConfig
|
|
|
|
config = MQTTConfig(
|
|
broker_host="localhost",
|
|
broker_port=1883,
|
|
client_id="test_client"
|
|
)
|
|
|
|
client = MQTTClient(config)
|
|
|
|
self.assertEqual(client.config.broker_host, "localhost")
|
|
self.assertEqual(client.config.broker_port, 1883)
|
|
|
|
def test_client_status(self):
|
|
"""测试客户端状态"""
|
|
from core.result_reporter import MQTTClient
|
|
from config.settings import MQTTConfig
|
|
|
|
config = MQTTConfig()
|
|
client = MQTTClient(config)
|
|
|
|
status = client.get_status()
|
|
|
|
self.assertIn("connected", status)
|
|
self.assertIn("broker_host", status)
|
|
|
|
def test_performance_stats(self):
|
|
"""测试性能统计"""
|
|
from core.result_reporter import MQTTClient
|
|
from config.settings import MQTTConfig
|
|
|
|
config = MQTTConfig()
|
|
client = MQTTClient(config)
|
|
|
|
stats = client.get_performance_stats()
|
|
|
|
self.assertIn("messages_sent", stats)
|
|
self.assertIn("messages_received", stats)
|
|
|
|
|
|
class TestAlertReporter(unittest.TestCase):
|
|
"""测试告警上报器"""
|
|
|
|
def test_reporter_creation(self):
|
|
"""测试上报器创建"""
|
|
from core.result_reporter import AlertReporter
|
|
|
|
reporter = AlertReporter()
|
|
|
|
self.assertIsNotNone(reporter)
|
|
|
|
def test_get_status(self):
|
|
"""测试获取状态"""
|
|
from core.result_reporter import AlertReporter
|
|
|
|
reporter = AlertReporter()
|
|
|
|
status = reporter.get_status()
|
|
|
|
self.assertIn("stats", status)
|
|
|
|
|
|
class TestResultReporter(unittest.TestCase):
|
|
"""测试结果上报主类"""
|
|
|
|
def test_reporter_creation(self):
|
|
"""测试创建"""
|
|
from core.result_reporter import ResultReporter
|
|
|
|
reporter = ResultReporter()
|
|
|
|
self.assertIsNotNone(reporter)
|
|
|
|
def test_get_status(self):
|
|
"""测试获取状态"""
|
|
from core.result_reporter import ResultReporter
|
|
|
|
reporter = ResultReporter()
|
|
|
|
status = reporter.get_status()
|
|
|
|
self.assertIn("stats", status)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|