Skip to content

Commit

Permalink
Add pyqt-toolsw executable and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MHendricks committed Jan 5, 2024
1 parent ce393f0 commit a5f11c1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
10 changes: 8 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ Note:
Usage
-----

A program is provided available as ``Scripts/pyqt6-tools.exe`` or ``python -m pyqt6_tools``.
There are subcommands provided for each of Designer, QML Scene, and the QML Test Runner.
A program is provided available as ``Scripts/pyqt6-tools.exe``. There are
subcommands provided for each of Designer, QML Scene, and the QML Test Runner.
These wrapper commands provide additional functionality related to launching
the underlying programs. A larger set of Qt application are available as
subcommands of the ``Scripts/qt6-tools.exe`` program. In both cases, passing
Expand All @@ -81,6 +81,12 @@ environment variable ``DOT_ENV_DIRECTORY`` will be set to the directory
containing the ``.env`` file. With this extra variable you can specify paths
relative to the ``.env`` location.

There alternative ways to call ``Scripts/pyqt6-tools.exe``, ``python -m pyqt6_tools``
works the same way but allows you to choose the version of python to run the tools
with. On Windows if you create a shortcut to `pyqt6-tools.exe`, it will show a
command prompt that stays open for the duration of the launched application. You
can address this by using ``Scripts/pyqt6-toolsw.exe`` or ``pythonw -m pyqt6_tools``.

.. code-block:: powershell
PYQTDESIGNERPATH=${PYQTDESIGNERPATH};${DOT_ENV_DIRECTORY}/path/to/my/widgets
Expand Down
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def pad_version(v, segment_count=3):
["Qt6", "Qt5"],
["Qt6", "Qt 5"],
["6.4", "5.15"],
["pyuic6", "pyuic5"],
]
for a, b in replacements:
readme = readme.replace(a, b)
Expand Down Expand Up @@ -108,6 +109,9 @@ def pad_version(v, segment_count=3):
entry_points={
'console_scripts': [
'pyqt{major}-tools = pyqt{major}_tools.entrypoints:main'.format(major=pyqt_major_version),
],
'gui_scripts': [
'pyqt{major}-toolsw = pyqt{major}_tools.entrypoints:main'.format(major=pyqt_major_version),
]
}
)
28 changes: 18 additions & 10 deletions src/pyqt_tools/tests/test_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@
fspath = getattr(os, 'fspath', str)

scripts_path = pathlib.Path(sysconfig.get_path("scripts"))
executable_path_string = fspath(scripts_path.joinpath("pyqt{}-tools".format(major)))
# Use parametrize to test each method for launching pyqt-tools in a subprocess
executable_paths = (
"cmd",
[
[fspath(scripts_path.joinpath("pyqt{}-tools".format(major)))],
[fspath(scripts_path.joinpath("pyqt{}-toolsw".format(major)))],
[sys.executable, "-m", "pyqt{}_tools".format(major)],
]
)

vars_to_print = [
*pyqt_plugins.utilities.diagnostic_variables_to_print,
Expand All @@ -41,7 +49,8 @@ def environment_fixture():
return environment


def test_designer_creates_test_widget(tmp_path, environment):
@pytest.mark.parametrize(*executable_paths)
def test_designer_creates_test_widget(tmp_path, environment, cmd):
file_path = tmp_path/'tigger'
environment[pyqt_plugins.tests.testbutton.test_path_env_var] = fspath(file_path)

Expand All @@ -60,10 +69,7 @@ def test_designer_creates_test_widget(tmp_path, environment):

with pytest.raises(subprocess.TimeoutExpired):
subprocess.run(
[
executable_path_string,
'designer',
],
cmd + ['designer'],
check=True,
env=environment,
timeout=40,
Expand Down Expand Up @@ -127,7 +133,8 @@ def test_qmlscene_paints_test_item(tmp_path, environment):
reason="accepting failure until we figure out the problem".format(string_version),
strict=True,
)
def test_qmltestrunner_paints_test_item(tmp_path, environment):
@pytest.mark.parametrize(*executable_paths)
def test_qmltestrunner_paints_test_item(tmp_path, environment, cmd):
file_path = tmp_path/'piglet'
environment[pyqt_plugins.examples.exampleqmlitem.test_path_env_var] = fspath(file_path)

Expand All @@ -139,7 +146,7 @@ def test_qmltestrunner_paints_test_item(tmp_path, environment):

subprocess.run(
[
executable_path_string,
cmd,
'qmltestrunner',
'--',
'-input',
Expand All @@ -156,12 +163,13 @@ def test_qmltestrunner_paints_test_item(tmp_path, environment):
)


def test_installuic_does_not_fail(environment):
@pytest.mark.parametrize(*executable_paths)
def test_installuic_does_not_fail(environment, cmd):
pyqt_plugins.utilities.print_environment_variables(environment, *vars_to_print)

subprocess.run(
[
executable_path_string,
cmd,
'installuic',
],
check=True,
Expand Down

0 comments on commit a5f11c1

Please sign in to comment.