From 720fa5f3c2e77dd1b5d18af26f65de41188b282e Mon Sep 17 00:00:00 2001 From: 2xB <31772910+2xB@users.noreply.github.com> Date: Tue, 5 May 2020 18:16:07 +0200 Subject: [PATCH] DateAxisItem: AxisItem unlinking tests and doc fixed (#1179) * Added test_AxisItem by @mliberty1 As found in https://github.com/pyqtgraph/pyqtgraph/pull/917 * test_AxisItem: Fit to current implementation * DateAxisItem: Fix documentation to zoomLevels zoomLevels is not intended to be set by the user (see discussion in converstation from https://github.com/pyqtgraph/pyqtgraph/pull/1154/files#diff-aefdb23660d0963df0dff3a116baded8 ). Also, `zoomLevelWidths` does currently not exist. This commit adapts the documentation to reflect that. * DateAxisItem: Do not publish ZoomLevel * DateAxisItem testing: Removed unnecessary monkeypatch fixture Co-authored-by: 2xB <2xB@users.noreply.github.com> --- pyqtgraph/graphicsItems/DateAxisItem.py | 7 +-- .../graphicsItems/tests/test_AxisItem.py | 57 +++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/pyqtgraph/graphicsItems/DateAxisItem.py b/pyqtgraph/graphicsItems/DateAxisItem.py index 7cf9be2c..a5132fd9 100644 --- a/pyqtgraph/graphicsItems/DateAxisItem.py +++ b/pyqtgraph/graphicsItems/DateAxisItem.py @@ -6,7 +6,7 @@ from datetime import datetime, timedelta from .AxisItem import AxisItem from ..pgcollections import OrderedDict -__all__ = ['DateAxisItem', 'ZoomLevel'] +__all__ = ['DateAxisItem'] MS_SPACING = 1/1000.0 SECOND_SPACING = 1 @@ -260,9 +260,8 @@ class DateAxisItem(AxisItem): overriding this function or setting a different set of zoom levels than the default one. The `zoomLevels` variable is a dictionary with the maximal distance of ticks in seconds which are allowed for each zoom level - before the axis switches to the next coarser level. To create custom - zoom levels, override this function and provide custom `zoomLevelWidths` and - `zoomLevels`. + before the axis switches to the next coarser level. To customize the zoom level + selection, override this function. """ padding = 10 diff --git a/pyqtgraph/graphicsItems/tests/test_AxisItem.py b/pyqtgraph/graphicsItems/tests/test_AxisItem.py index 22dccdb4..8d89259a 100644 --- a/pyqtgraph/graphicsItems/tests/test_AxisItem.py +++ b/pyqtgraph/graphicsItems/tests/test_AxisItem.py @@ -30,3 +30,60 @@ def test_AxisItem_stopAxisAtTick(monkeypatch): plot.show() app.processEvents() plot.close() + + +def test_AxisItem_viewUnlink(): + plot = pg.PlotWidget() + view = plot.plotItem.getViewBox() + axis = plot.getAxis("bottom") + assert axis.linkedView() == view + axis.unlinkFromView() + assert axis.linkedView() is None + + +class FakeSignal: + + def __init__(self): + self.calls = [] + + def connect(self, *args, **kwargs): + self.calls.append('connect') + + def disconnect(self, *args, **kwargs): + self.calls.append('disconnect') + + +class FakeView: + + def __init__(self): + self.sigYRangeChanged = FakeSignal() + self.sigXRangeChanged = FakeSignal() + self.sigResized = FakeSignal() + + +def test_AxisItem_bottomRelink(): + axis = pg.AxisItem('bottom') + fake_view = FakeView() + axis.linkToView(fake_view) + assert axis.linkedView() == fake_view + assert fake_view.sigYRangeChanged.calls == [] + assert fake_view.sigXRangeChanged.calls == ['connect'] + assert fake_view.sigResized.calls == ['connect'] + axis.unlinkFromView() + assert fake_view.sigYRangeChanged.calls == [] + assert fake_view.sigXRangeChanged.calls == ['connect', 'disconnect'] + assert fake_view.sigResized.calls == ['connect', 'disconnect'] + + +def test_AxisItem_leftRelink(): + axis = pg.AxisItem('left') + fake_view = FakeView() + axis.linkToView(fake_view) + assert axis.linkedView() == fake_view + assert fake_view.sigYRangeChanged.calls == ['connect'] + assert fake_view.sigXRangeChanged.calls == [] + assert fake_view.sigResized.calls == ['connect'] + axis.unlinkFromView() + assert fake_view.sigYRangeChanged.calls == ['connect', 'disconnect'] + assert fake_view.sigXRangeChanged.calls == [] + assert fake_view.sigResized.calls == ['connect', 'disconnect']