test_entrypoints.py
4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import os
import pathlib
import subprocess
import sysconfig
import pytest
from .. import _import_it
from .. import major
from .. import version
from .. import string_version
qt_tools = _import_it('qt_tools')
pyqt_plugins = _import_it('pyqt_plugins')
_import_it('pyqt_plugins', 'examples', 'exampleqmlitem')
_import_it('pyqt_plugins', 'tests', 'testbutton')
_import_it('pyqt_plugins', 'tests', 'testbuttonplugin')
_import_it('pyqt_plugins', 'utilities')
fspath = getattr(os, 'fspath', str)
scripts_path = pathlib.Path(sysconfig.get_path("scripts"))
executable_path_string = fspath(scripts_path.joinpath("pyqt{}-tools".format(major)))
vars_to_print = [
*pyqt_plugins.utilities.diagnostic_variables_to_print,
pyqt_plugins.examples.exampleqmlitem.test_path_env_var,
pyqt_plugins.tests.testbutton.test_path_env_var,
]
@pytest.fixture(name='environment')
def environment_fixture():
environment = pyqt_plugins.create_environment(os.environ)
pyqt_plugins.utilities.mutate_qml_path(environment, paths=qml2_import_paths)
environment['QT_DEBUG_PLUGINS'] = '1'
return environment
def test_designer_creates_test_widget(tmp_path, environment):
file_path = tmp_path/'tigger'
environment[pyqt_plugins.tests.testbutton.test_path_env_var] = fspath(file_path)
widget_plugin_path = pathlib.Path(
pyqt_plugins.tests.testbuttonplugin.__file__,
).parent
environment.update(pyqt_plugins.utilities.add_to_env_var_path_list(
env=environment,
name='PYQTDESIGNERPATH',
before=[fspath(widget_plugin_path)],
after=[''],
))
pyqt_plugins.utilities.print_environment_variables(environment, *vars_to_print)
with pytest.raises(subprocess.TimeoutExpired):
subprocess.run(
[
executable_path_string,
'designer',
],
check=True,
env=environment,
timeout=40,
)
assert (
file_path.read_bytes()
== pyqt_plugins.tests.testbutton.test_file_contents
)
qml2_import_paths = (pyqt_plugins.utilities.fspath(pyqt_plugins.root),)
# https://www.riverbankcomputing.com/pipermail/pyqt/2021-May/043916.html
@pytest.mark.skipif(
(6,) <= version <= (6, 1, 0),
reason="QML not supported for v6 through v6.1.0: {}".format(string_version),
)
def test_qmlscene_paints_test_item(tmp_path, environment):
file_path = tmp_path/'eeyore'
environment[pyqt_plugins.examples.exampleqmlitem.test_path_env_var] = fspath(file_path)
qml_example_path = pyqt_plugins.utilities.fspath(
pathlib.Path(pyqt_plugins.examples.__file__).parent / 'qmlapp.qml'
)
pyqt_plugins.utilities.print_environment_variables(environment, *vars_to_print)
with pytest.raises(subprocess.TimeoutExpired):
subprocess.run(
[
fspath(qt_tools.application_path('qmlscene')),
fspath(qml_example_path),
],
check=True,
env=environment,
timeout=40,
)
assert (
file_path.read_bytes()
== pyqt_plugins.examples.exampleqmlitem.test_file_contents
)
# https://www.riverbankcomputing.com/pipermail/pyqt/2021-May/043916.html
@pytest.mark.skipif(
(6,) <= version <= (6, 1, 0),
reason="QML not supported for v6 through v6.1.0: {}".format(string_version),
)
def test_qmltestrunner_paints_test_item(tmp_path, environment):
file_path = tmp_path/'piglet'
environment[pyqt_plugins.examples.exampleqmlitem.test_path_env_var] = fspath(file_path)
qml_test_path = pyqt_plugins.utilities.fspath(
pathlib.Path(pyqt_plugins.examples.__file__).parent / 'qmltest.qml'
)
pyqt_plugins.utilities.print_environment_variables(environment, *vars_to_print)
subprocess.run(
[
executable_path_string,
'qmltestrunner',
'--',
'-input',
qml_test_path,
],
check=True,
env=environment,
timeout=40,
)
assert (
file_path.read_bytes()
== pyqt_plugins.examples.exampleqmlitem.test_file_contents
)
def test_installuic_does_not_fail(environment):
pyqt_plugins.utilities.print_environment_variables(environment, *vars_to_print)
subprocess.run(
[
executable_path_string,
'installuic',
],
check=True,
env=environment,
timeout=40,
)