diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0cfb4b4b..57157467 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,6 +62,7 @@ jobs: sudo apt-get install --yes libgl1 # Required to stubtest QtMultimedia sudo apt-get install --yes libpulse-mainloop-glib0 + sudo apt-get install --yes libgl1 libgl1-mesa-dev xvfb x11-utils libdbus-1-3 libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 - name: Install run: | pip install --upgrade pip setuptools wheel diff --git a/CHANGELOG.md b/CHANGELOG.md index 394ea18f..f3d0302e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). detected by latest mypy 0.930 * [#183](https://github.com/python-qt-tools/PyQt5-stubs/pull/183) Add missing operations on QSize * [#189](https://github.com/python-qt-tools/PyQt5-stubs/pull/189) Fix QListWidget, QTreeWidget and QTableWidget so that their respective items are now optional in many places when used as argument or return value +* [#165](https://github.com/python-qt-tools/PyQt5-stubs/pull/165) allow `None` as argument for `QLineEdit.setText()` + ## 5.15.2.0 ### Added diff --git a/PyQt5-stubs/QtWidgets.pyi b/PyQt5-stubs/QtWidgets.pyi index bff16524..09275fec 100644 --- a/PyQt5-stubs/QtWidgets.pyi +++ b/PyQt5-stubs/QtWidgets.pyi @@ -7147,7 +7147,7 @@ class QLineEdit(QWidget): def undo(self) -> None: ... def selectAll(self) -> None: ... def clear(self) -> None: ... - def setText(self, a0: str) -> None: ... + def setText(self, a0: typing.Optional[str]) -> None: ... def hasAcceptableInput(self) -> bool: ... def setInputMask(self, inputMask: str) -> None: ... def inputMask(self) -> str: ... diff --git a/setup.py b/setup.py index 83938fe4..202093d9 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,7 @@ def find_version(*file_paths): packages=["PyQt5-stubs"], extras_require={ "build": ["docker==4.2.0"], - "dev": ["mypy", "pytest"], + "dev": ["mypy", "pytest", "pytest-xvfb"], }, classifiers=[ "Development Status :: 4 - Beta", diff --git a/tests/qlineedit.py b/tests/qlineedit.py new file mode 100644 index 00000000..542ed44f --- /dev/null +++ b/tests/qlineedit.py @@ -0,0 +1,6 @@ +"""Tests for QLineEdit.""" +from PyQt5.QtWidgets import QLineEdit + +# test that QLineEdit.setText() accepts None as parameter +edit = QLineEdit() +edit.setText(None) diff --git a/tests/test_stubs.py b/tests/test_stubs.py index 2ed54b44..a8be39f9 100644 --- a/tests/test_stubs.py +++ b/tests/test_stubs.py @@ -2,11 +2,21 @@ from pathlib import Path import pytest from mypy import api +from PyQt5.QtWidgets import QApplication TESTS_DIR = Path(__file__).parent +@pytest.fixture(name="qapplication", scope="session") +def qapplication_fixture(): + application = QApplication.instance() + if application is None: + application = QApplication([]) + + return application + + def gen_tests(): """List of all tests files included in the directory tests""" for path in TESTS_DIR.glob('*.py'): @@ -53,7 +63,7 @@ def test_stubs_qflags() -> None: list(gen_tests()), ids=[v.name for v in gen_tests()] ) -def test_files(filepath): +def test_files(filepath, qapplication): """Run the test files to make sure they work properly.""" code = filepath.read_text(encoding='utf-8') exec(compile(code, filepath, 'exec'), {}) diff --git a/tox.ini b/tox.ini index 726866b3..eebb4306 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ setenv: linux: OS_MARKER = linux macos: OS_MARKER = macos windows: OS_MARKER = windows + QT_DEBUG_PLUGINS = 1 extras = dev commands =