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>
This commit is contained in:
2xB 2020-05-05 18:16:07 +02:00 committed by GitHub
parent 96be1bd23f
commit 720fa5f3c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 4 deletions

View File

@ -6,7 +6,7 @@ from datetime import datetime, timedelta
from .AxisItem import AxisItem from .AxisItem import AxisItem
from ..pgcollections import OrderedDict from ..pgcollections import OrderedDict
__all__ = ['DateAxisItem', 'ZoomLevel'] __all__ = ['DateAxisItem']
MS_SPACING = 1/1000.0 MS_SPACING = 1/1000.0
SECOND_SPACING = 1 SECOND_SPACING = 1
@ -260,9 +260,8 @@ class DateAxisItem(AxisItem):
overriding this function or setting a different set of zoom levels overriding this function or setting a different set of zoom levels
than the default one. The `zoomLevels` variable is a dictionary with the 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 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 before the axis switches to the next coarser level. To customize the zoom level
zoom levels, override this function and provide custom `zoomLevelWidths` and selection, override this function.
`zoomLevels`.
""" """
padding = 10 padding = 10

View File

@ -30,3 +30,60 @@ def test_AxisItem_stopAxisAtTick(monkeypatch):
plot.show() plot.show()
app.processEvents() app.processEvents()
plot.close() 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']