From d519630d14ff7ef5eac09a2773e9b61232480a56 Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Fri, 28 May 2021 11:32:11 -0700 Subject: [PATCH] Fix check for equality between floats While this fix prevents an assertion error, the assertion error was being suppressed; and was only noticeable via pytest -s where the error was printed to console. Future work should be done to minimize the use of bare exceptions so these tests do not fail silently --- tests/graphicsItems/test_AxisItem.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/graphicsItems/test_AxisItem.py b/tests/graphicsItems/test_AxisItem.py index 481ce15c..b58d75f3 100644 --- a/tests/graphicsItems/test_AxisItem.py +++ b/tests/graphicsItems/test_AxisItem.py @@ -1,16 +1,19 @@ import pyqtgraph as pg +from math import isclose app = pg.mkQApp() def test_AxisItem_stopAxisAtTick(monkeypatch): def test_bottom(p, axisSpec, tickSpecs, textSpecs): - assert view.mapToView(axisSpec[1]).x() == 0.25 - assert view.mapToView(axisSpec[2]).x() == 0.75 + viewPixelSize = view.viewPixelSize() + assert isclose(view.mapToView(axisSpec[1]).x(), 0.25, abs_tol=viewPixelSize[0]) + assert isclose(view.mapToView(axisSpec[2]).x(), 0.75, abs_tol=viewPixelSize[0]) def test_left(p, axisSpec, tickSpecs, textSpecs): - assert view.mapToView(axisSpec[1]).y() == 0.875 - assert view.mapToView(axisSpec[2]).y() == 0.125 + viewPixelSize = view.viewPixelSize() + assert isclose(view.mapToView(axisSpec[1]).y(), 0.875, abs_tol=viewPixelSize[1]) + assert isclose(view.mapToView(axisSpec[2]).y(), 0.125, abs_tol=viewPixelSize[1]) plot = pg.PlotWidget() view = plot.plotItem.getViewBox()