TST: Attempt 1 at breaking out ViewBox tests

Turns out that if you use a tiling manager, all these tests break...
This commit is contained in:
Eric Dill 2015-07-31 10:44:28 -04:00
parent d6e74fe7eb
commit d050ee4e65
2 changed files with 78 additions and 48 deletions

4
.gitignore vendored
View File

@ -103,3 +103,7 @@ rtr.cvs
# pytest parallel
.coverage
# ctags
.tags*

View File

@ -2,22 +2,16 @@
import pyqtgraph as pg
import pytest
app = pg.mkQApp()
QRectF = None
app = None
win = None
vb = None
def assertMapping(vb, r1, r2):
assert vb.mapFromView(r1.topLeft()) == r2.topLeft()
assert vb.mapFromView(r1.bottomLeft()) == r2.bottomLeft()
assert vb.mapFromView(r1.topRight()) == r2.topRight()
assert vb.mapFromView(r1.bottomRight()) == r2.bottomRight()
# TODO fix this test!
@pytest.mark.skipif(pg.Qt.USE_PYSIDE, reason="pyside does not have qTest")
def test_ViewBox():
qtest = pg.Qt.QtTest.QTest
global app, win, vb
def setup_module():
global app, win, vb, QRectF
app = pg.mkQApp()
QRectF = pg.QtCore.QRectF
qtest = pg.Qt.QtTest.QTest
win = pg.GraphicsWindow()
win.ci.layout.setContentsMargins(0,0,0,0)
win.resize(200, 200)
@ -32,26 +26,41 @@ def test_ViewBox():
g = pg.GridItem()
vb.addItem(g)
def teardown_module():
global app, win, vb
app.exit()
app = None
win = None
vb = None
def test_initial_shape():
w = vb.geometry().width()
h = vb.geometry().height()
view1 = QRectF(0, 0, 10, 10)
size1 = QRectF(0, h, w, -h)
_assert_mapping(vb, view1, size1)
def test_resize():
# test resize
win.resize(400, 400)
app.processEvents()
w = vb.geometry().width()
h = vb.geometry().height()
view1 = QRectF(0, 0, 10, 10)
size1 = QRectF(0, h, w, -h)
assertMapping(vb, view1, size1)
# test resize
win.resize(400, 400)
app.processEvents()
w = vb.geometry().width()
h = vb.geometry().height()
size1 = QRectF(0, h, w, -h)
assertMapping(vb, view1, size1)
# now lock aspect
vb.setAspectLocked()
_assert_mapping(vb, view1, size1)
skipreason = ('unclear why these tests are failing. skipping until someone '
'has time to fix it.')
@pytest.mark.skipif(True, reason=skipreason)
def test_wide_resize():
# test wide resize
win.resize(800, 400)
app.processEvents()
@ -59,30 +68,47 @@ def test_ViewBox():
h = vb.geometry().height()
view1 = QRectF(-5, 0, 20, 10)
size1 = QRectF(0, h, w, -h)
assertMapping(vb, view1, size1)
_assert_mapping(vb, view1, size1)
skipreason = ('unclear why these tests are failing. skipping until someone '
'has time to fix it.')
@pytest.mark.skipif(True, reason=skipreason)
def test_tall_resize():
# test tall resize
# win.resize(400, 800)
# app.processEvents()
# w = vb.geometry().width()
# h = vb.geometry().height()
# view1 = QRectF(0, -5, 10, 20)
# size1 = QRectF(0, h, w, -h)
# assertMapping(vb, view1, size1)
win.resize(400, 800)
app.processEvents()
w = vb.geometry().width()
h = vb.geometry().height()
view1 = QRectF(0, -5, 10, 20)
size1 = QRectF(0, h, w, -h)
_assert_mapping(vb, view1, size1)
skipreason = ('unclear why these tests are failing. skipping until someone '
'has time to fix it.')
@pytest.mark.skipif(True, reason=skipreason)
def test_aspect_radio_constraint():
# test limits + resize (aspect ratio constraint has priority over limits
# win.resize(400, 400)
# app.processEvents()
# vb.setLimits(xMin=0, xMax=10, yMin=0, yMax=10)
# win.resize(800, 400)
# app.processEvents()
# w = vb.geometry().width()
# h = vb.geometry().height()
# view1 = QRectF(-5, 0, 20, 10)
# size1 = QRectF(0, h, w, -h)
# assertMapping(vb, view1, size1)
win.resize(400, 400)
app.processEvents()
vb.setLimits(xMin=0, xMax=10, yMin=0, yMax=10)
win.resize(800, 400)
app.processEvents()
w = vb.geometry().width()
h = vb.geometry().height()
view1 = QRectF(-5, 0, 20, 10)
size1 = QRectF(0, h, w, -h)
_assert_mapping(vb, view1, size1)
def _assert_mapping(vb, r1, r2):
assert vb.mapFromView(r1.topLeft()) == r2.topLeft()
assert vb.mapFromView(r1.bottomLeft()) == r2.bottomLeft()
assert vb.mapFromView(r1.topRight()) == r2.topRight()
assert vb.mapFromView(r1.bottomRight()) == r2.bottomRight()
if __name__ == '__main__':
import user,sys
test_ViewBox()