|
1 | 1 | import copy
|
| 2 | +from datetime import date, datetime |
2 | 3 | import signal
|
3 | 4 | from unittest import mock
|
4 | 5 |
|
5 | 6 | import matplotlib
|
6 | 7 | from matplotlib import pyplot as plt
|
7 | 8 | from matplotlib._pylab_helpers import Gcf
|
| 9 | +from matplotlib.backends.qt_editor import _formlayout |
8 | 10 |
|
9 | 11 | import pytest
|
10 | 12 |
|
|
13 | 15 | from matplotlib.backends.qt_compat import QtGui
|
14 | 16 | except ImportError:
|
15 | 17 | pytestmark = pytest.mark.skip('No usable Qt5 bindings')
|
| 18 | +from matplotlib.backends.qt_compat import QtWidgets |
16 | 19 |
|
17 | 20 |
|
18 | 21 | @pytest.fixture
|
@@ -258,6 +261,20 @@ def test_figureoptions():
|
258 | 261 | fig.canvas.manager.toolbar.edit_parameters()
|
259 | 262 |
|
260 | 263 |
|
| 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 | + |
261 | 278 | @pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
|
262 | 279 | def test_double_resize():
|
263 | 280 | # Check that resizing a figure twice keeps the same window size
|
@@ -295,3 +312,25 @@ def crashing_callback(fig, stale):
|
295 | 312 | canvas = FigureCanvasQTAgg(fig)
|
296 | 313 | fig.stale = True
|
297 | 314 | 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