Show More
@@ -0,0 +1,48 b'' | |||||
|
1 | import os | |||
|
2 | import importlib | |||
|
3 | ||||
|
4 | import pytest | |||
|
5 | ||||
|
6 | from IPython.terminal.pt_inputhooks import set_qt_api, get_inputhook_name_and_func | |||
|
7 | ||||
|
8 | ||||
|
9 | guis_avail = [] | |||
|
10 | ||||
|
11 | ||||
|
12 | def _get_qt_vers(): | |||
|
13 | """If any version of Qt is available, this will populate `guis_avail` with 'qt' and 'qtx'. Due | |||
|
14 | to the import mechanism, we can't import multiple versions of Qt in one session.""" | |||
|
15 | for gui in ['qt', 'qt6', 'qt5', 'qt4']: | |||
|
16 | print(f'Trying {gui}') | |||
|
17 | try: | |||
|
18 | set_qt_api(gui) | |||
|
19 | importlib.import_module("IPython.terminal.pt_inputhooks.qt") | |||
|
20 | guis_avail.append(gui) | |||
|
21 | if 'QT_API' in os.environ.keys(): | |||
|
22 | del os.environ['QT_API'] | |||
|
23 | except ImportError: | |||
|
24 | pass # that version of Qt isn't available. | |||
|
25 | except RuntimeError: | |||
|
26 | pass # the version of IPython doesn't know what to do with this Qt version. | |||
|
27 | ||||
|
28 | ||||
|
29 | _get_qt_vers() | |||
|
30 | ||||
|
31 | ||||
|
32 | @pytest.mark.skipif(len(guis_avail) == 0, reason='No viable version of PyQt or PySide installed.') | |||
|
33 | def test_inputhook_qt(): | |||
|
34 | gui = guis_avail[0] | |||
|
35 | ||||
|
36 | # Choose a qt version and get the input hook function. This will import Qt... | |||
|
37 | get_inputhook_name_and_func(gui) | |||
|
38 | ||||
|
39 | # ...and now we're stuck with this version of Qt for good; can't switch. | |||
|
40 | for not_gui in ['qt6', 'qt5', 'qt4']: | |||
|
41 | if not_gui not in guis_avail: | |||
|
42 | break | |||
|
43 | ||||
|
44 | with pytest.raises(ImportError): | |||
|
45 | get_inputhook_name_and_func(not_gui) | |||
|
46 | ||||
|
47 | # A gui of 'qt' means "best available", or in this case, the last one that was used. | |||
|
48 | get_inputhook_name_and_func('qt') |
General Comments 0
You need to be logged in to leave comments.
Login now