8000 Add more unit tests for Qt backend · matplotlib/matplotlib@79f3385 · GitHub
[go: up one dir, main page]

Skip to content

Commit 79f3385

Browse files
committed
Add more unit tests for Qt backend
Re #19075
1 parent 6d90ab4 commit 79f3385

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import copy
2+
from datetime import date, datetime
23
import signal
34
from unittest import mock
45

56
import matplotlib
67
from matplotlib import pyplot as plt
78
from matplotlib._pylab_helpers import Gcf
9+
from matplotlib.backends.qt_editor import _formlayout
810

911
import pytest
1012

@@ -13,6 +15,7 @@
1315
from matplotlib.backends.qt_compat import QtGui
1416
except ImportError:
1517
pytestmark = pytest.mark.skip('No usable Qt5 bindings')
18+
from matplotlib.backends.qt_compat import QtWidgets
1619

1720

1821
@pytest.fixture
@@ -258,6 +261,20 @@ def test_figureoptions():
258261
fig.canvas.manager.toolbar.edit_parameters()
259262

260263

264+
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
265+
def test_figureoptions_with_datetime_axes():
266+
fig, ax = plt.subplots()
267+
xydata = [
268+
datetime(year=2021, month=1, day=1),
269+
datetime(year=2021, month=2, day=1)
270+
]
271+
ax.plot(xydata, xydata)
272+
with mock.patch(
273+
"matplotlib.backends.qt_editor._formlayout.FormDialog.exec_",
274+
lambda self: None):
275+
fig.canvas.manager.toolbar.edit_parameters()
276+
277+
261278
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
262279
def test_double_resize():
263280
# Check that resizing a figure twice keeps the same window size
@@ -295,3 +312,25 @@ def crashing_callback(fig, stale):
295312
canvas = FigureCanvasQTAgg(fig)
296313
fig.stale = True
297314
assert called
315+
316+
317+
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
318+
def test_form_widget_get_with_datetime_field():
319+
if not QtWidgets.QApplication.instance():
320+
QtWidgets.QApplication()
321+
form = [("Field name", datetime(year=2021, month=3, day=11))]
322+
widget = _formlayout.FormWidget(form)
323+
widget.setup()
324+
values = widget.get()
325+
assert(values == [datetime(year=2021, month=3, day=11)])
326+
327+
328+
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
329+
def test_form_widget_get_with_date_field():
330+
if not QtWidgets.QApplication.instance():
331+
QtWidgets.QApplication()
332+
form = [("Field name", date(year=2021, month=3, day=11))]
333+
widget = _formlayout.FormWidget(form)
334+
widget.setup()
335+
values = widget.get()
336+
assert(values == [date(year=2021, month=3, day=11)])

0 commit comments

Comments
 (0)
0