Beispiel #1
0
def test_gui_api_qt(renderer_interactive_pyvistaqt):
    """Test GUI API with the Qt backend."""
    import mne
    mne.MNE_PYVISTAQT_BACKEND_TEST = True
    _, api = _check_qt_version(return_api=True)
    n_warn = int(api in ('PySide6', 'PyQt6'))
    test_gui_api(None, None, n_warn=n_warn)
Beispiel #2
0
def pixel_ratio():
    """Get the pixel ratio."""
    from mne.viz.backends.tests._utils import has_pyvista
    if not has_pyvista() or not _check_qt_version():
        return 1.
    from qtpy.QtWidgets import QApplication, QMainWindow
    _ = QApplication.instance() or QApplication([])
    window = QMainWindow()
    ratio = float(window.devicePixelRatio())
    window.close()
    return ratio
Beispiel #3
0
def _check_skip_backend(name):
    from mne.viz.backends.tests._utils import (has_pyvista, has_imageio_ffmpeg,
                                               has_pyvistaqt)
    if name in ('pyvistaqt', 'notebook'):
        if not has_pyvista():
            pytest.skip("Test skipped, requires pyvista.")
        if not has_imageio_ffmpeg():
            pytest.skip("Test skipped, requires imageio-ffmpeg")
    if name == 'pyvistaqt' and not _check_qt_version():
        pytest.skip("Test skipped, requires Qt.")
    if name == 'pyvistaqt' and not has_pyvistaqt():
        pytest.skip("Test skipped, requires pyvistaqt")
Beispiel #4
0
def test_theme_colors(pg_backend, theme, monkeypatch, tmp_path):
    """Test that theme colors propagate properly."""
    darkdetect = pytest.importorskip('darkdetect')
    monkeypatch.setenv('_MNE_FAKE_HOME_DIR', str(tmp_path))
    monkeypatch.delenv('MNE_BROWSER_THEME', raising=False)
    # make it seem like the system is always in light mode
    monkeypatch.setattr(darkdetect, 'theme', lambda: 'light')
    raw = RawArray(np.zeros((1, 1000)), create_info(1, 1000., 'eeg'))
    _, api = _check_qt_version(return_api=True)
    if api in ('PyQt6', 'PySide6') and theme == 'dark':
        ctx = pytest.warns(RuntimeWarning, match='not yet supported')
        return_early = True
    else:
        ctx = nullcontext()
        return_early = False
    with ctx:
        fig = raw.plot(theme=theme)
    if return_early:
        return  # we could add a ton of conditionals below, but KISS
    is_dark = _qt_is_dark(fig)
    # on Darwin these checks get complicated, so don't bother for now
    if sys.platform != 'darwin':
        if theme == 'dark':
            assert is_dark, theme
        elif theme == 'light':
            assert not is_dark, theme
        else:
            got_dark = darkdetect.theme().lower() == 'dark'
            assert is_dark is got_dark

    def assert_correct_darkness(widget, want_dark):
        __tracebackhide__ = True  # noqa
        # This should work, but it just picks up the parent in the errant case!
        bgcolor = widget.palette().color(widget.backgroundRole()).getRgbF()[:3]
        dark = rgb_to_hls(*bgcolor)[1] < 0.5
        assert dark == want_dark, f'{widget} dark={dark} want_dark={want_dark}'
        # ... so we use a more direct test
        colors = _pixmap_to_ndarray(widget.grab())[:, :, :3]
        dark = colors.mean() < 0.5
        assert dark == want_dark, f'{widget} dark={dark} want_dark={want_dark}'

    for widget in (fig.mne.toolbar, fig.statusBar()):
        assert_correct_darkness(widget, is_dark)
Beispiel #5
0
def _check_pyqtgraph(request):
    # Check Qt
    qt_version, api = _check_qt_version(return_api=True)
    if (not qt_version) or _compare_version(qt_version, '<', '5.12'):
        pytest.skip(f'Qt API {api} has version {qt_version} '
                    f'but pyqtgraph needs >= 5.12!')
    try:
        import mne_qt_browser  # noqa: F401
        # Check mne-qt-browser version
        lower_2_0 = _compare_version(mne_qt_browser.__version__, '<', '0.2.0')
        m_name = request.function.__module__
        f_name = request.function.__name__
        if lower_2_0 and m_name in pre_2_0_skip_modules:
            pytest.skip(f'Test-Module "{m_name}" was skipped for'
                        f' mne-qt-browser < 0.2.0')
        elif lower_2_0 and f_name in pre_2_0_skip_funcs:
            pytest.skip(f'Test "{f_name}" was skipped for '
                        f'mne-qt-browser < 0.2.0')
    except Exception:
        pytest.skip('Requires mne_qt_browser')
    else:
        ver = mne_qt_browser.__version__
        if api != 'PyQt5' and _compare_version(ver, '<=', '0.2.6'):
            pytest.skip(f'mne_qt_browser {ver} requires PyQt5, API is {api}')