Skip to content

Commit

Permalink
test: add coverage for QThread
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan committed Jun 18, 2024
1 parent ff70cd9 commit 1a3e77b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,14 @@ exclude_also = [
"def _link_splitters",
"def draw_mode",
"QtWidgets.QApplication(sys.argv)",
"QtWidgets.QMessageBox.question",
"if not qapp:",
"if execute is None:",
"qapp.exec()",
"if __name__ == __main__:",
"except varname.VarnameRetrievingError:",
"if TYPE_CHECKING:",
"QtCore.QThread",
"def _wrapped_for_coverage",
]

[tool.mypy]
Expand Down
13 changes: 13 additions & 0 deletions src/erlab/interactive/imagetool/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import functools
import os
import pickle
import socket
Expand Down Expand Up @@ -42,13 +43,25 @@ class ItoolManagerParseError(Exception):
"""Raised when the data received from the client cannot be parsed."""


def _coverage_resolve_trace(fn):
# https://github.com/nedbat/coveragepy/issues/686#issuecomment-634932753
@functools.wraps(fn)
def _wrapped_for_coverage(*args, **kwargs):
if threading._trace_hook:
sys.settrace(threading._trace_hook)
fn(*args, **kwargs)

return _wrapped_for_coverage


class _ManagerServer(QtCore.QThread):
sigReceived = QtCore.Signal(list, dict)

def __init__(self):
super().__init__()
self.stopped = threading.Event()

@_coverage_resolve_trace
def run(self):
self.stopped.clear()
soc = socket.socket()
Expand Down

0 comments on commit 1a3e77b

Please sign in to comment.