Skip to content

Commit

Permalink
Merge pull request #3 from astrofrog/pyside-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog authored Aug 18, 2023
2 parents b86a4e5 + 7aa9a2c commit 74e5178
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 38 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/check_failures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
import sys
from xml.etree import ElementTree

if len(sys.argv) != 2:
print("Usage: python check_failures.py filename.xml")
sys.exit(1)

filename = sys.argv[1]

if not os.path.exists(filename):
print("Output file does not exist, pytest command did not complete")
sys.exit(1)

et = ElementTree.parse(filename)
results = et.find("testsuite").attrib

if int(results["errors"]) > 0 or int(results["failures"]) > 0:
print("There were failures/errors as part of the test suite")
sys.exit(1)
14 changes: 7 additions & 7 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ jobs:
envs: |
# Non-deterministic QThread exceptions
- linux: py38-test-pyside514
- linux: py39-test-pyside515
- linux: py310-test-pyside63
- linux: py38-test-pyside514-skipexitcode
- linux: py39-test-pyside515-skipexitcode
- linux: py310-test-pyside63-skipexitcode
# PySide6 6.4 failures due to https://github.com/spyder-ide/qtpy/issues/373
# and https://github.com/matplotlib/matplotlib/issues/24155
# Python 3.11.0 failing on Windows in test_image.py on
# > assert df.find_factory(fname) is df.img_data
- linux: py310-test-pyside64
- linux: py311-test-pyside64
- macos: py310-test-pyside63
- macos: py311-test-pyside64
- linux: py310-test-pyside64-skipexitcode
- linux: py311-test-pyside64-skipexitcode
- macos: py310-test-pyside63-skipexitcode
- macos: py311-test-pyside64-skipexitcode
- windows: py310-test-pyside64
- windows: py311-test-pyqt515
Expand Down
2 changes: 1 addition & 1 deletion glue_qt/app/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ def screenshot(self, filename):
"""
image = QtGui.QImage(self.size(), QtGui.QImage.Format_RGB32)
painter = QtGui.QPainter(image)
flags = self.IgnoreMask | self.DrawWindowBackground | self.DrawChildren
flags = QtWidgets.QWidget.IgnoreMask | QtWidgets.QWidget.DrawWindowBackground | QtWidgets.QWidget.DrawChildren
self.render(painter, QtCore.QPoint(), QtGui.QRegion(), flags)
image.save(filename)
painter.end()
Expand Down
2 changes: 1 addition & 1 deletion glue_qt/app/mdi_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def paintEvent(self, event):
painter.setPen(QtGui.QColor(210, 210, 210))
font = painter.font()
font.setPointSize(font.pointSize() * 4)
font.setWeight(font.Black)
font.setWeight(QtGui.QFont.Black)
painter.setFont(font)
rect = self.contentsRect()
painter.drawText(rect, Qt.AlignHCenter | Qt.AlignVCenter,
Expand Down
5 changes: 2 additions & 3 deletions glue_qt/app/tests/test_preferences.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os

import pytest
import numpy as np
from unittest.mock import patch, MagicMock
from matplotlib.colors import ColorConverter

from glue import custom_viewer
from glue.tests.helpers import PYSIDE2_INSTALLED # noqa
from glue_qt.tests.helpers import requires_pyqt
from glue.core import HubListener, Application, Data, DataCollection
from glue.core.message import SettingsChangeMessage
from qtpy import QtWidgets
Expand Down Expand Up @@ -322,7 +321,7 @@ def setup(axes):
raise Exception("Failed to find custom viewer in qt_client")


@pytest.mark.skipif('PYSIDE2_INSTALLED')
@requires_pyqt
def test_foreground_background_settings():

d_1d = Data(x=np.random.random(100), y=np.random.random(100), label='Data 1d')
Expand Down
4 changes: 2 additions & 2 deletions glue_qt/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

try:
from qtpy import PYSIDE2
from qtpy import PYSIDE2, PYSIDE6
except Exception:
PYSIDE2 = False

Expand Down Expand Up @@ -113,7 +113,7 @@ def pytest_unconfigure(config):
# Until this can be properly debugged and fixed, we xfail any test that fails
# with one of these exceptions.

if PYSIDE2:
if PYSIDE2 or PYSIDE6:
QTSTANDARD_EXC = "QtGui.QStandardItem' object has no attribute "
QTSTANDARD_ATTRS = ["'connect'", "'item'", "'triggered'"]

Expand Down
4 changes: 2 additions & 2 deletions glue_qt/core/data_collection_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def __init__(self, parent=None):

# only edit label on model.new_item
self.setItemDelegate(LabeledDelegate())
self.setEditTriggers(self.NoEditTriggers)
self.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)

self.setIconSize(QtCore.QSize(16, 16))

Expand All @@ -469,7 +469,7 @@ def select_indices(self, *indices):
sm = self.selectionModel()
sm.clearSelection()
for idx in indices:
sm.select(idx, sm.Select)
sm.select(idx, QtCore.QItemSelectionModel.Select)

def set_data_collection(self, data_collection):
self._model = DataCollectionModel(data_collection)
Expand Down
2 changes: 1 addition & 1 deletion glue_qt/core/layer_artist_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __init__(self, parent=None, hub=None):
self.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.setEditTriggers(self.NoEditTriggers)
self.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)

self.setMinimumSize(200, 100)
self._actions = {}
Expand Down
4 changes: 2 additions & 2 deletions glue_qt/core/style_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def edit_style(cls, layer):
self = cls(layer)
result = self.exec_()

if result == self.Accepted:
if result == QtWidgets.QDialog.Accepted:
self.update_style()

@classmethod
Expand All @@ -117,7 +117,7 @@ def dropdown_editor(cls, item, pos, **kwargs):

pos = self.mapFromGlobal(pos)
self.move(pos)
if self.exec_() == self.Accepted:
if self.exec_() == QtWidgets.QDialog.Accepted:
self.update_style()


Expand Down
7 changes: 2 additions & 5 deletions glue_qt/plugins/dendro_viewer/tests/test_data_viewer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# pylint: disable=I0011,W0613,W0201,W0212,E1101,E1103

import os
from contextlib import nullcontext

import pytest
import numpy as np
Expand Down Expand Up @@ -140,6 +139,7 @@ def test_attribute_change_triggers_relayout(self):

class TestSessions(object):

@pytest.mark.filterwarnings('ignore:glue.external.echo')
@pytest.mark.parametrize('protocol', [0, 1])
def test_session_back_compat(self, protocol):

Expand All @@ -150,10 +150,7 @@ def test_session_back_compat(self, protocol):

state = GlueUnSerializer.loads(session)

# This is raised (only) on initial import, so depends on prior state unfortunately
with (pytest.warns(UserWarning, match='glue.external.echo is deprecated, import from echo')
if protocol == 1 else nullcontext()):
ga = state.object('__main__')
ga = state.object('__main__')

dc = ga.session.data_collection

Expand Down
Empty file added glue_qt/tests/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions glue_qt/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest

from glue.tests.helpers import PYQT5_INSTALLED, PYQT6_INSTALLED, PYSIDE2_INSTALLED, PYSIDE6_INSTALLED

requires_pyqt = pytest.mark.skipif(str(not PYQT5_INSTALLED and not PYQT6_INSTALLED),
reason='An installation of PyQt is required')

requires_pyside = pytest.mark.skipif(str(not PYSIDE2_INSTALLED and not PYSIDE6_INSTALLED),
reason='An installation of PySide is required')
6 changes: 3 additions & 3 deletions glue_qt/tests/test_session_back_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import pytest
import numpy as np

from glue.tests.helpers import requires_astropy, requires_h5py, requires_qt, PYSIDE2_INSTALLED # noqa
from glue.tests.helpers import requires_astropy, requires_h5py, requires_qt
from glue_qt.tests.helpers import requires_pyqt
from glue.core.component import CoordinateComponent, Component
from glue.core.state import GlueUnSerializer
from glue.core.component_id import PixelComponentID
Expand Down Expand Up @@ -103,9 +104,8 @@ def test_load_link_helpers_04():
ga.close()


@requires_qt
@requires_pyqt
@requires_astropy
@pytest.mark.skipif('PYSIDE2_INSTALLED')
def test_load_viewers_04():

# FIXME - for some reason this test with PySide2 causes a leftover reference
Expand Down
2 changes: 1 addition & 1 deletion glue_qt/viewers/common/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _make_action(self, tool, menu=None):
button.setText(tool.action_text)
if icon:
button.setIcon(icon)
button.setPopupMode(button.InstantPopup)
button.setPopupMode(QtWidgets.QToolButton.InstantPopup)
button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
action = self.addWidget(button)
if menu:
Expand Down
2 changes: 2 additions & 0 deletions glue_qt/viewers/image/tests/test_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from glue_qt.app import GlueApplication
from glue.core.fixed_resolution_buffer import ARRAY_CACHE, PIXEL_CACHE
from glue.core.data_derived import IndexedData
from glue_qt.tests.helpers import requires_pyqt

from ..data_viewer import ImageViewer

Expand Down Expand Up @@ -558,6 +559,7 @@ def test_scatter_overlay(self):
self.viewer.add_data(self.image1)
self.viewer.add_data(self.catalog)

@requires_pyqt
def test_removed_subset(self):

# Regression test for a bug in v0.11.0 that meant that if a subset
Expand Down
4 changes: 2 additions & 2 deletions glue_qt/viewers/image/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from glue.core import Data
from glue_qt.viewers.image import ImageViewer
from glue.core.tests.util import simple_session
from glue.tests.helpers import PYSIDE2_INSTALLED # noqa
from glue_qt.tests.helpers import requires_pyqt


@pytest.mark.skipif('PYSIDE2_INSTALLED')
@requires_pyqt
@pytest.mark.mpl_image_compare(tolerance=1, savefig_kwargs={'dpi': 50})
def test_resample_on_zoom():

Expand Down
2 changes: 2 additions & 0 deletions glue_qt/viewers/matplotlib/tests/test_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from glue.core.roi import XRangeROI
from glue_qt.utils import process_events
from glue.tests.helpers import requires_matplotlib_ge_22
from glue_qt.tests.helpers import requires_pyqt


class MatplotlibDrawCounter(object):
Expand Down Expand Up @@ -550,6 +551,7 @@ def test_numerical_data_changed(self):
self.data.update_values_from_data(data)
assert self.draw_count == 2

@requires_pyqt
@requires_matplotlib_ge_22
def test_aspect_resize(self):

Expand Down
4 changes: 2 additions & 2 deletions glue_qt/viewers/profile/profile_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def enable(self):
self.ui.button_collapse.clicked.connect(self._on_collapse)

font = QtGui.QFont("Courier")
font.setStyleHint(font.Monospace)
font.setStyleHint(QtGui.QFont.Monospace)
self.ui.text_log.document().setDefaultFont(font)
self.ui.text_log.setLineWrapMode(self.ui.text_log.NoWrap)
self.ui.text_log.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)

self.axes = self.viewer.axes
self.canvas = self.axes.figure.canvas
Expand Down
5 changes: 2 additions & 3 deletions glue_qt/viewers/profile/tests/test_profile_tools.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pytest
import numpy as np

from numpy.testing import assert_allclose

from glue.core import Data
from glue.tests.helpers import PYSIDE2_INSTALLED # noqa
from glue_qt.tests.helpers import requires_pyqt
from glue_qt.app import GlueApplication
from glue_qt.utils import process_events
from glue.viewers.image.state import AggregateSlice
Expand Down Expand Up @@ -68,7 +67,7 @@ def test_navigate_sync_image(self):
self.viewer.axes.figure.canvas.button_release_event(x, y, 1)
assert image_viewer.state.slices == (5, 0, 0)

@pytest.mark.skipif('PYSIDE2_INSTALLED')
@requires_pyqt
def test_fit_polynomial(self):

# TODO: need to deterministically set to polynomial fitter
Expand Down
4 changes: 2 additions & 2 deletions glue_qt/viewers/table/data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ def __init__(self, session, state=None, parent=None, widget=None):

hdr = self.ui.table.horizontalHeader()
hdr.setStretchLastSection(True)
hdr.setSectionResizeMode(hdr.Interactive)
hdr.setSectionResizeMode(QtWidgets.QHeaderView.Interactive)

hdr = self.ui.table.verticalHeader()
hdr.setSectionResizeMode(hdr.Interactive)
hdr.setSectionResizeMode(QtWidgets.QHeaderView.Interactive)

self.data = None
self.model = None
Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ extras =
test
all: all
docs: docs
allowlist_externals =
sh
commands =
test: pip freeze
test: pytest --pyargs glue_qt --cov glue_qt --cov-config={toxinidir}/setup.cfg {posargs}
test-!skipexitcode: pytest --pyargs glue_qt --cov glue_qt --cov-config={toxinidir}/setup.cfg {posargs}
# The skipexitcode mode consists of ignoring the exit code of the pytest
# command and just checking whether any errors or failures were present.
test-skipexitcode: sh -c 'pytest --pyargs glue_qt --cov glue_qt --cov-config={toxinidir}/setup.cfg --junit-xml={toxinidir}/{envname}.xml {posargs} || true'
test-skipexitcode: python {toxinidir}/.github/workflows/check_failures.py {toxinidir}/{envname}.xml
docs: sphinx-build -W -n -b html -d _build/doctrees . _build/html

[testenv:codestyle]
Expand Down

0 comments on commit 74e5178

Please sign in to comment.