Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ _build
.cache
*.so

# coverage
.coverage.*.*.*

# logs
pip-log.txt

Expand Down
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,17 @@ build-backend = "poetry.core.masonry.api"
addopts = "-n auto"
markers = ["raises"]
testpaths = ["tests"]

[tool.coverage.run]
plugins = ["coverage_conditional_plugin"]

[tool.coverage.coverage_conditional_plugin.omit]
"sys_platform == 'win32'" = "qasync/_unix.py"
"sys_platform != 'win32'" = "qasync/_windows.py"

[tool.coverage.coverage_conditional_plugin.rules]
no_cover_if_windows = "sys_platform == 'win32'"
no_cover_if_unix = "sys_platform != 'win32'"

[tool.coverage.report]
show_missing = true
46 changes: 20 additions & 26 deletions qasync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@

QtModule = None


# Determining the Qt Python implementation is not coveraged,
# since these stuff can depend on the configurations on the
# testing machine.

# If QT_API env variable is given, use that or fail trying
qtapi_env = os.getenv("QT_API", "").strip().lower()
if qtapi_env:
if qtapi_env: # pragma: no cover
env_to_mod_map = {
"pyqt5": "PyQt5",
"pyqt6": "PyQt6",
Expand All @@ -51,14 +56,14 @@
QtModule = importlib.import_module(QtModuleName)

# If a Qt lib is already imported, use that
if not QtModule:
if not QtModule: # pragma: no cover
for QtModuleName in ("PyQt5", "PyQt6", "PySide2", "PySide6"):
if QtModuleName in sys.modules:
QtModule = sys.modules[QtModuleName]
break

# Try importing qt libs
if not QtModule:
if not QtModule: # pragma: no cover
for QtModuleName in ("PyQt5", "PyQt6", "PySide2", "PySide6"):
try:
QtModule = importlib.import_module(QtModuleName)
Expand All @@ -67,36 +72,23 @@
else:
break

if not QtModule:
if not QtModule: # pragma: no cover
raise ImportError("No Qt implementations found")

QtCore = importlib.import_module(QtModuleName + ".QtCore", package=QtModuleName)
QtGui = importlib.import_module(QtModuleName + ".QtGui", package=QtModuleName)
QtWidgets = importlib.import_module(QtModuleName + ".QtWidgets", package=QtModuleName)
QApplication = QtWidgets.QApplication

if QtModuleName == "PyQt5":
from PyQt5 import QtWidgets
if QtModuleName == "PyQt5": # pragma: no cover
from PyQt5.QtCore import pyqtSlot as Slot
Comment thread
johnzhou721 marked this conversation as resolved.
Outdated

QApplication = QtWidgets.QApplication

elif QtModuleName == "PyQt6":
from PyQt6 import QtWidgets
elif QtModuleName == "PyQt6": # pragma: no cover
from PyQt6.QtCore import pyqtSlot as Slot

QApplication = QtWidgets.QApplication

elif QtModuleName == "PySide2":
from PySide2 import QtWidgets
elif QtModuleName == "PySide2": # pragma: no cover
from PySide2.QtCore import Slot

QApplication = QtWidgets.QApplication

elif QtModuleName == "PySide6":
from PySide6 import QtWidgets
elif QtModuleName == "PySide6": # pragma: no cover
from PySide6.QtCore import Slot

QApplication = QtWidgets.QApplication

Comment on lines +80 to -103

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: I simplified the importing of QApplication in the process; importing Slot gets no-covered because there's really nothing we need to test here; adding PyQt5 etc conditionals would be a huge waste of time.

from ._common import with_logger # noqa


Expand Down Expand Up @@ -170,7 +162,9 @@ def __init__(self, max_workers=10, stack_size=None):
super().__init__()
self.__max_workers = max_workers
self.__queue = Queue()
if stack_size is None:
# No cover the whole thing because we cannot test
# some of the configurations.
if stack_size is None: # pragma: no cover
# Match cpython/Python/thread_pthread.h
if sys.platform.startswith("darwin"):
stack_size = 16 * 2**20
Expand Down Expand Up @@ -760,12 +754,12 @@ def __log_error(cls, *args, **kwds):

QSelectorEventLoop = type("QSelectorEventLoop", (_QEventLoop, _SelectorEventLoop), {})

if os.name == "nt":
if os.name == "nt": # pragma: no_cover_if_unix
from ._windows import _ProactorEventLoop

QIOCPEventLoop = type("QIOCPEventLoop", (_QEventLoop, _ProactorEventLoop), {})
QEventLoop = QIOCPEventLoop
else:
else: # pragma: no_cover_if_windows
QEventLoop = QSelectorEventLoop


Expand Down
4 changes: 3 additions & 1 deletion qasync/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def with_logger(cls):
module = cls.__module__
if module is not None:
cls_name = module + "." + cls_name
else:
# This is just an internal helper function; edge cases
# like this need not be tested, so no cover.
else: # pragma: no cover
raise AssertionError
setattr(cls, attr_name, logging.getLogger(cls_name))
return cls
7 changes: 0 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
level=logging.DEBUG, format="%(levelname)s\t%(filename)s:%(lineno)s %(message)s"
)


if os.name == "nt":
collect_ignore = ["qasync/_unix.py"]
else:
collect_ignore = ["qasync/_windows.py"]
Comment thread
johnzhou721 marked this conversation as resolved.


@fixture(scope="session")
def application():
from qasync import QApplication
Expand Down