This repository has been archived by the owner on Nov 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make damaku distribution driven by signals
Also fixed test on headless environment like CI
- Loading branch information
1 parent
3a36074
commit f908298
Showing
4 changed files
with
113 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
import json | ||
import socket | ||
from PySide6.QtCore import QThread | ||
from PySide6.QtWidgets import QWidget | ||
import pytest | ||
from pytestqt.qtbot import QtBot | ||
from qdamakuengine.app import App, _DamakuDistributionSmoothly | ||
from qdamakuengine.app import App, _DamakuDistributionSmoothly # type:ignore | ||
|
||
|
||
def test_distribution(qtbot: QtBot): | ||
widget = QWidget() | ||
thread = QThread(widget) | ||
job = _DamakuDistributionSmoothly() | ||
thread.started.connect(job.start) | ||
thread.started.connect(job.start.emit) | ||
job.moveToThread(thread) | ||
thread.start() | ||
widget.show() | ||
with qtbot.waitSignal(job.damakuupdated, timeout=10000): | ||
job.add("Test-Damaku", "Pytest") | ||
job.stop() | ||
qtbot.addWidget(widget) | ||
with qtbot.waitSignal(job.damakuupdated, timeout=10000): | ||
job.add.emit("Test-Damaku", "Pytest") | ||
job.stop.emit() | ||
thread.quit() | ||
while not thread.isFinished(): | ||
if not thread.isFinished(): | ||
thread.wait() | ||
|
||
|
||
@pytest.mark.skip(reason="Need more work to know why s.recv hangs.") | ||
def test_app(qtbot: QtBot): | ||
app = App() | ||
app.show() | ||
qtbot.addWidget(app) | ||
# app.close() | ||
with socket.socket() as s: | ||
s.connect(("127.0.0.1", 2333)) | ||
s.sendall(json.dumps({"text": "Test-Damaku"}).encode()) | ||
data = s.recv(1024).decode() | ||
assert json.loads(data)["result"] == 0 | ||
app.dthread.quit() |