|
1 | 1 | import copy |
| 2 | +from datetime import date, datetime |
2 | 3 | import signal |
3 | 4 | from unittest import mock |
4 | 5 |
|
|
10 | 11 |
|
11 | 12 |
|
12 | 13 | try: |
13 | | - from matplotlib.backends.qt_compat import QtGui |
| 14 | + from matplotlib.backends.qt_compat import QtGui, QtWidgets |
| 15 | + from matplotlib.backends.qt_editor import _formlayout |
14 | 16 | except ImportError: |
15 | 17 | pytestmark = pytest.mark.skip('No usable Qt5 bindings') |
16 | 18 |
|
@@ -245,6 +247,20 @@ def test_figureoptions(): |
245 | 247 | fig.canvas.manager.toolbar.edit_parameters() |
246 | 248 |
|
247 | 249 |
|
| 250 | +@pytest.mark.backend('Qt5Agg', skip_on_importerror=True) |
| 251 | +def test_figureoptions_with_datetime_axes(): |
| 252 | + fig, ax = plt.subplots() |
| 253 | + xydata = [ |
| 254 | + datetime(year=2021, month=1, day=1), |
| 255 | + datetime(year=2021, month=2, day=1) |
| 256 | + ] |
| 257 | + ax.plot(xydata, xydata) |
| 258 | + with mock.patch( |
| 259 | + "matplotlib.backends.qt_editor._formlayout.FormDialog.exec_", |
| 260 | + lambda self: None): |
| 261 | + fig.canvas.manager.toolbar.edit_parameters() |
| 262 | + |
| 263 | + |
248 | 264 | @pytest.mark.backend('Qt5Agg', skip_on_importerror=True) |
249 | 265 | def test_double_resize(): |
250 | 266 | # Check that resizing a figure twice keeps the same window size |
@@ -282,3 +298,20 @@ def crashing_callback(fig, stale): |
282 | 298 | canvas = FigureCanvasQTAgg(fig) |
283 | 299 | fig.stale = True |
284 | 300 | assert called |
| 301 | + |
| 302 | + |
| 303 | +@pytest.mark.backend('Qt5Agg', skip_on_importerror=True) |
| 304 | +def test_form_widget_get_with_datetime_and_date_fields(): |
| 305 | + if not QtWidgets.QApplication.instance(): |
| 306 | + QtWidgets.QApplication() |
| 307 | + form = [ |
| 308 | + ("Datetime field", datetime(year=2021, month=3, day=11)), |
| 309 | + ("Date field", date(year=2021, month=3, day=11)) |
| 310 | + ] |
| 311 | + widget = _formlayout.FormWidget(form) |
| 312 | + widget.setup() |
| 313 | + values = widget.get() |
| 314 | + assert values == [ |
| 315 | + datetime(year=2021, month=3, day=11), |
| 316 | + date(year=2021, month=3, day=11) |
| 317 | + ] |
0 commit comments