feat: add ProcessDock process and port manager
This commit is contained in:
66
tests/test_gui.py
Normal file
66
tests/test_gui.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
from PySide6.QtWidgets import QApplication # noqa: E402
|
||||
|
||||
from processdock.ui import MainWindow # noqa: E402
|
||||
|
||||
|
||||
class StubService:
|
||||
def snapshot(self):
|
||||
return {"processes": [], "summary": {}, "warnings": [], "refreshed_at": "00:00:00"}
|
||||
|
||||
|
||||
class GuiSmokeTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
cls.application = QApplication.instance() or QApplication([])
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.window = MainWindow(service=StubService(), auto_refresh=False)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.window.close()
|
||||
self.application.processEvents()
|
||||
|
||||
def test_window_contains_table_search_and_detail_panel(self) -> None:
|
||||
self.assertEqual(self.window.model.columnCount(), 8)
|
||||
self.assertIn("端口", self.window.search_box.placeholderText())
|
||||
self.assertEqual(self.window.detail_panel.stack.currentIndex(), 0)
|
||||
|
||||
def test_filter_finds_port(self) -> None:
|
||||
process = {
|
||||
"pid": 4420,
|
||||
"name": "node.exe",
|
||||
"ports": [3000],
|
||||
"port_details": [{"protocol": "TCP", "address": "0.0.0.0", "port": 3000}],
|
||||
"cpu_percent": 3.0,
|
||||
"memory_bytes": 188743680,
|
||||
"memory_text": "180.0 MB",
|
||||
"memory_percent": 1.0,
|
||||
"username": "wang",
|
||||
"status": "running",
|
||||
"status_label": "运行中",
|
||||
"exe": r"D:\node\node.exe",
|
||||
"command": "node server.js",
|
||||
"create_time": 1.0,
|
||||
"create_time_text": "2026-07-17 08:20:11",
|
||||
"ppid": 100,
|
||||
"access_limited": False,
|
||||
"is_current": False,
|
||||
"can_terminate": True,
|
||||
"can_open_location": True,
|
||||
}
|
||||
self.window.model.set_processes([process])
|
||||
self.window.search_box.setText("3000")
|
||||
self.assertEqual(self.window.proxy.rowCount(), 1)
|
||||
self.window.search_box.setText("8080")
|
||||
self.assertEqual(self.window.proxy.rowCount(), 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user