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