Clean up test files
Remove if __name__ == "__main__" bits, replace some == None to is None checks Cleanup variety of static code checker issue Removed missing imports, restructured some logic to make a little cleaner, fixed a function in test_dockarea, unfortunately broke the test so now I tell pytest to expect the Exception.
This commit is contained in:
parent
0160de22fb
commit
e7a30b9324
|
@ -0,0 +1,23 @@
|
||||||
|
import initExample ## Add path to library (just for examples; you do not need this)
|
||||||
|
|
||||||
|
import pyqtgraph as pg
|
||||||
|
from pyqtgraph.Qt import QtTest
|
||||||
|
|
||||||
|
from examples.ExampleApp import ExampleLoader
|
||||||
|
"""
|
||||||
|
This file is used by test_examples.py for ensuring the Example App works.
|
||||||
|
It is not named test_ExampleApp.py as that way the Example application is
|
||||||
|
not run twice.
|
||||||
|
"""
|
||||||
|
|
||||||
|
pg.mkQApp()
|
||||||
|
|
||||||
|
def test_ExampleLoader():
|
||||||
|
loader = ExampleLoader()
|
||||||
|
QtTest.QTest.qWaitForWindowExposed(loader)
|
||||||
|
QtTest.QTest.qWait(200)
|
||||||
|
loader.close()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_ExampleLoader()
|
||||||
|
pg.exec()
|
|
@ -1,10 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#try:
|
|
||||||
# from PyQt5 import sip
|
|
||||||
#except ImportError:
|
|
||||||
# import sip
|
|
||||||
# sip.setapi('QString', 1)
|
|
||||||
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
pg.mkQApp()
|
pg.mkQApp()
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from collections import OrderedDict
|
import pyqtgraph.dockarea as da
|
||||||
|
|
||||||
pg.mkQApp()
|
pg.mkQApp()
|
||||||
|
|
||||||
import pyqtgraph.dockarea as da
|
|
||||||
|
|
||||||
def test_dockarea():
|
def test_dockarea():
|
||||||
a = da.DockArea()
|
a = da.DockArea()
|
||||||
|
@ -176,14 +174,14 @@ def test_dockarea():
|
||||||
# a superfluous vertical splitter in state2 has been removed
|
# a superfluous vertical splitter in state2 has been removed
|
||||||
state4 = a4.saveState()
|
state4 = a4.saveState()
|
||||||
state4['main'][1][0] = state4['main'][1][0][1][0]
|
state4['main'][1][0] = state4['main'][1][0][1][0]
|
||||||
assert clean_state(state4['main']) == clean_state(state2['main'])
|
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
# this test doesn't work, likely due to clean_state not working as intended
|
||||||
|
assert clean_state(state4['main']) == clean_state(state2['main'])
|
||||||
|
|
||||||
|
|
||||||
def clean_state(state):
|
def clean_state(state):
|
||||||
# return state dict with sizes removed
|
# return state dict with sizes removed
|
||||||
ch = [clean_state(x) for x in state[1]] if isinstance(state[1], list) else state[1]
|
ch = [clean_state(x) for x in state[1]] if isinstance(state[1], list) else state[1]
|
||||||
state = (state[0], ch, {})
|
state = (state[0], ch, {})
|
||||||
|
return state
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_dockarea()
|
|
||||||
|
|
|
@ -17,19 +17,19 @@ def approxeq(a, b):
|
||||||
def test_CSVExporter():
|
def test_CSVExporter():
|
||||||
tempfilename = tempfile.NamedTemporaryFile(suffix='.csv').name
|
tempfilename = tempfile.NamedTemporaryFile(suffix='.csv').name
|
||||||
print("using %s as a temporary file" % tempfilename)
|
print("using %s as a temporary file" % tempfilename)
|
||||||
|
|
||||||
plt = pg.plot()
|
plt = pg.plot()
|
||||||
y1 = [1,3,2,3,1,6,9,8,4,2]
|
y1 = [1,3,2,3,1,6,9,8,4,2]
|
||||||
plt.plot(y=y1, name='myPlot')
|
plt.plot(y=y1, name='myPlot')
|
||||||
|
|
||||||
y2 = [3,4,6,1,2,4,2,3,5,3,5,1,3]
|
y2 = [3,4,6,1,2,4,2,3,5,3,5,1,3]
|
||||||
x2 = pg.np.linspace(0, 1.0, len(y2))
|
x2 = pg.np.linspace(0, 1.0, len(y2))
|
||||||
plt.plot(x=x2, y=y2)
|
plt.plot(x=x2, y=y2)
|
||||||
|
|
||||||
y3 = [1,5,2,3,4,6,1,2,4,2,3,5,3]
|
y3 = [1,5,2,3,4,6,1,2,4,2,3,5,3]
|
||||||
x3 = pg.np.linspace(0, 1.0, len(y3)+1)
|
x3 = pg.np.linspace(0, 1.0, len(y3)+1)
|
||||||
plt.plot(x=x3, y=y3, stepMode="center")
|
plt.plot(x=x3, y=y3, stepMode="center")
|
||||||
|
|
||||||
ex = pg.exporters.CSVExporter(plt.plotItem)
|
ex = pg.exporters.CSVExporter(plt.plotItem)
|
||||||
ex.export(fileName=tempfilename)
|
ex.export(fileName=tempfilename)
|
||||||
|
|
||||||
|
@ -38,21 +38,15 @@ def test_CSVExporter():
|
||||||
lines = [line for line in r]
|
lines = [line for line in r]
|
||||||
header = lines.pop(0)
|
header = lines.pop(0)
|
||||||
assert header == ['myPlot_x', 'myPlot_y', 'x0001', 'y0001', 'x0002', 'y0002']
|
assert header == ['myPlot_x', 'myPlot_y', 'x0001', 'y0001', 'x0002', 'y0002']
|
||||||
|
|
||||||
i = 0
|
for i, vals in enumerate(lines):
|
||||||
for vals in lines:
|
|
||||||
vals = list(map(str.strip, vals))
|
vals = list(map(str.strip, vals))
|
||||||
assert (i >= len(y1) and vals[0] == '') or approxeq(float(vals[0]), i)
|
assert (i >= len(y1) and vals[0] == '') or approxeq(float(vals[0]), i)
|
||||||
assert (i >= len(y1) and vals[1] == '') or approxeq(float(vals[1]), y1[i])
|
assert (i >= len(y1) and vals[1] == '') or approxeq(float(vals[1]), y1[i])
|
||||||
|
|
||||||
assert (i >= len(x2) and vals[2] == '') or approxeq(float(vals[2]), x2[i])
|
assert (i >= len(x2) and vals[2] == '') or approxeq(float(vals[2]), x2[i])
|
||||||
assert (i >= len(y2) and vals[3] == '') or approxeq(float(vals[3]), y2[i])
|
assert (i >= len(y2) and vals[3] == '') or approxeq(float(vals[3]), y2[i])
|
||||||
|
|
||||||
assert (i >= len(x3) and vals[4] == '') or approxeq(float(vals[4]), x3[i])
|
assert (i >= len(x3) and vals[4] == '') or approxeq(float(vals[4]), x3[i])
|
||||||
assert (i >= len(y3) and vals[5] == '') or approxeq(float(vals[5]), y3[i])
|
assert (i >= len(y3) and vals[5] == '') or approxeq(float(vals[5]), y3[i])
|
||||||
i += 1
|
|
||||||
|
|
||||||
os.unlink(tempfilename)
|
os.unlink(tempfilename)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_CSVExporter()
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ from pyqtgraph.exporters import HDF5Exporter
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.testing import assert_equal
|
from numpy.testing import assert_equal
|
||||||
import h5py
|
import h5py
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
@ -15,7 +15,7 @@ def test_PlotItem_shared_axis_items(orientation):
|
||||||
|
|
||||||
layout = pg.GraphicsLayoutWidget()
|
layout = pg.GraphicsLayoutWidget()
|
||||||
|
|
||||||
pi1 = layout.addPlot(axisItems={orientation: ax1})
|
_ = layout.addPlot(axisItems={orientation: ax1})
|
||||||
|
|
||||||
pi2 = layout.addPlot()
|
pi2 = layout.addPlot()
|
||||||
# left or bottom replaces, right or top adds new
|
# left or bottom replaces, right or top adds new
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import pytest
|
|
||||||
|
|
||||||
app = pg.mkQApp()
|
app = pg.mkQApp()
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
import weakref
|
import weakref
|
||||||
try:
|
|
||||||
import faulthandler
|
|
||||||
faulthandler.enable()
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
import faulthandler
|
||||||
|
faulthandler.enable()
|
||||||
|
|
||||||
pg.mkQApp()
|
pg.mkQApp()
|
||||||
|
|
||||||
def test_getViewWidget():
|
def test_getViewWidget():
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import time
|
import time
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pyqtgraph.Qt import QtCore, QtGui, QtTest
|
from pyqtgraph.Qt import QtGui, QtTest
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from tests.image_testing import assertImageApproved, TransposedImageItem
|
from tests.image_testing import assertImageApproved, TransposedImageItem
|
||||||
|
@ -188,7 +188,6 @@ def test_ImageItem_axisorder():
|
||||||
|
|
||||||
|
|
||||||
def test_dividebyzero():
|
def test_dividebyzero():
|
||||||
import pyqtgraph as pg
|
|
||||||
im = pg.image(pg.np.random.normal(size=(100,100)))
|
im = pg.image(pg.np.random.normal(size=(100,100)))
|
||||||
im.imageItem.setAutoDownsample(True)
|
im.imageItem.setAutoDownsample(True)
|
||||||
im.view.setRange(xRange=[-5+25, 5e+25],yRange=[-5e+25, 5e+25])
|
im.view.setRange(xRange=[-5+25, 5e+25],yRange=[-5e+25, 5e+25])
|
||||||
|
|
|
@ -48,7 +48,7 @@ def test_InfiniteLine():
|
||||||
px = pg.Point(-0.5, -1.0 / 3**0.5)
|
px = pg.Point(-0.5, -1.0 / 3**0.5)
|
||||||
assert br.containsPoint(pos + 5 * px, QtCore.Qt.OddEvenFill)
|
assert br.containsPoint(pos + 5 * px, QtCore.Qt.OddEvenFill)
|
||||||
assert not br.containsPoint(pos + 7 * px, QtCore.Qt.OddEvenFill)
|
assert not br.containsPoint(pos + 7 * px, QtCore.Qt.OddEvenFill)
|
||||||
|
plt.close()
|
||||||
|
|
||||||
def test_mouseInteraction():
|
def test_mouseInteraction():
|
||||||
# disable delay of mouse move events because events is called immediately in test
|
# disable delay of mouse move events because events is called immediately in test
|
||||||
|
@ -96,7 +96,4 @@ def test_mouseInteraction():
|
||||||
assert hline2.mouseHovering == False
|
assert hline2.mouseHovering == False
|
||||||
mouseDrag(plt, pos, pos2, QtCore.Qt.LeftButton)
|
mouseDrag(plt, pos, pos2, QtCore.Qt.LeftButton)
|
||||||
assert hline2.value() == -1
|
assert hline2.value() == -1
|
||||||
|
plt.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_mouseInteraction()
|
|
||||||
|
|
|
@ -30,7 +30,3 @@ def test_PlotCurveItem():
|
||||||
assertImageApproved(p, 'plotcurveitem/connectarray', "Plot curve with connection array.")
|
assertImageApproved(p, 'plotcurveitem/connectarray', "Plot curve with connection array.")
|
||||||
|
|
||||||
p.close()
|
p.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_PlotCurveItem()
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
|
|
@ -5,7 +5,6 @@ import numpy as np
|
||||||
|
|
||||||
def test_scatterplotitem():
|
def test_scatterplotitem():
|
||||||
app = pg.mkQApp()
|
app = pg.mkQApp()
|
||||||
app.processEvents()
|
|
||||||
|
|
||||||
plot = pg.PlotWidget()
|
plot = pg.PlotWidget()
|
||||||
# set view range equal to its bounding rect.
|
# set view range equal to its bounding rect.
|
||||||
|
@ -99,7 +98,4 @@ def test_init_spots():
|
||||||
assert spots[1].pen() == pg.mkPen(None)
|
assert spots[1].pen() == pg.mkPen(None)
|
||||||
assert spots[1].brush() == pg.mkBrush(None)
|
assert spots[1].brush() == pg.mkBrush(None)
|
||||||
assert spots[1].data() == 'zzz'
|
assert spots[1].data() == 'zzz'
|
||||||
|
plot.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_scatterplotitem()
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import pytest
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
|
||||||
app = pg.mkQApp()
|
app = pg.mkQApp()
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import pytest
|
|
||||||
from pyqtgraph.parametertree import Parameter
|
from pyqtgraph.parametertree import Parameter
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +23,6 @@ def test_parameter_hasdefault():
|
||||||
assert not p.hasDefault()
|
assert not p.hasDefault()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_unpack_parameter():
|
def test_unpack_parameter():
|
||||||
# test that **unpacking correctly returns child name/value maps
|
# test that **unpacking correctly returns child name/value maps
|
||||||
params = [
|
params = [
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# ~*~ coding: utf8 ~*~
|
|
||||||
import sys
|
import sys
|
||||||
import pytest
|
|
||||||
from pyqtgraph.Qt import QtGui, QtCore
|
from pyqtgraph.Qt import QtGui, QtCore
|
||||||
import pyqtgraph.parametertree as pt
|
import pyqtgraph.parametertree as pt
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
|
|
@ -27,6 +27,7 @@ def test_Vector_init():
|
||||||
v = pg.Vector([0, 1])
|
v = pg.Vector([0, 1])
|
||||||
assert v.z() == 0
|
assert v.z() == 0
|
||||||
v = pg.Vector([0, 1, 2])
|
v = pg.Vector([0, 1, 2])
|
||||||
|
assert v.z() == 2
|
||||||
|
|
||||||
# QSizeF
|
# QSizeF
|
||||||
v = pg.Vector(QtCore.QSizeF(1, 2))
|
v = pg.Vector(QtCore.QSizeF(1, 2))
|
||||||
|
@ -45,7 +46,7 @@ def test_Vector_init():
|
||||||
assert v == qv
|
assert v == qv
|
||||||
|
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
v = pg.Vector(1, 2, 3, 4)
|
_ = pg.Vector(1, 2, 3, 4)
|
||||||
|
|
||||||
|
|
||||||
def test_Vector_interface():
|
def test_Vector_interface():
|
||||||
|
@ -59,7 +60,7 @@ def test_Vector_interface():
|
||||||
assert v[0] == -1
|
assert v[0] == -1
|
||||||
assert v[2] == 0
|
assert v[2] == 0
|
||||||
with pytest.raises(IndexError):
|
with pytest.raises(IndexError):
|
||||||
x = v[4]
|
_ = v[4]
|
||||||
|
|
||||||
assert v[1] == 2
|
assert v[1] == 2
|
||||||
v[1] = 5
|
v[1] = 5
|
||||||
|
|
|
@ -1,36 +1,30 @@
|
||||||
from pyqtgraph import configfile
|
from pyqtgraph import configfile
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import tempfile, os
|
|
||||||
|
|
||||||
def test_longArrays():
|
def test_longArrays(tmpdir):
|
||||||
"""
|
"""
|
||||||
Test config saving and loading of long arrays.
|
Test config saving and loading of long arrays.
|
||||||
"""
|
"""
|
||||||
tmp = tempfile.mktemp(".cfg")
|
|
||||||
|
|
||||||
arr = np.arange(20)
|
arr = np.arange(20)
|
||||||
configfile.writeConfigFile({'arr':arr}, tmp)
|
|
||||||
config = configfile.readConfigFile(tmp)
|
tf = tmpdir.join("config.cfg")
|
||||||
|
configfile.writeConfigFile({'arr': arr}, tf)
|
||||||
|
config = configfile.readConfigFile(tf)
|
||||||
assert all(config['arr'] == arr)
|
assert all(config['arr'] == arr)
|
||||||
|
|
||||||
os.remove(tmp)
|
def test_multipleParameters(tmpdir):
|
||||||
|
|
||||||
def test_multipleParameters():
|
|
||||||
"""
|
"""
|
||||||
Test config saving and loading of multiple parameters.
|
Test config saving and loading of multiple parameters.
|
||||||
"""
|
"""
|
||||||
tmp = tempfile.mktemp(".cfg")
|
|
||||||
|
|
||||||
par1 = [1,2,3]
|
par1 = [1,2,3]
|
||||||
par2 = "Test"
|
par2 = "Test"
|
||||||
par3 = {'a':3,'b':'c'}
|
par3 = {'a':3,'b':'c'}
|
||||||
|
|
||||||
configfile.writeConfigFile({'par1':par1, 'par2':par2, 'par3':par3}, tmp)
|
tf = tmpdir.join("config.cfg")
|
||||||
config = configfile.readConfigFile(tmp)
|
configfile.writeConfigFile({'par1':par1, 'par2':par2, 'par3':par3}, tf)
|
||||||
|
config = configfile.readConfigFile(tf)
|
||||||
|
|
||||||
assert config['par1'] == par1
|
assert config['par1'] == par1
|
||||||
assert config['par2'] == par2
|
assert config['par2'] == par2
|
||||||
assert config['par3'] == par3
|
assert config['par3'] == par3
|
||||||
|
|
||||||
os.remove(tmp)
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import gc, os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,7 @@ def mkrefs(*objs):
|
||||||
"""
|
"""
|
||||||
allObjs = {}
|
allObjs = {}
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
if isinstance(obj, pg.QtCore.QObject):
|
obj = qObjectTree(obj) if isinstance(obj, pg.QtCore.QObject) else [obj]
|
||||||
obj = qObjectTree(obj)
|
|
||||||
else:
|
|
||||||
obj = [obj]
|
|
||||||
for o in obj:
|
for o in obj:
|
||||||
allObjs[id(o)] = o
|
allObjs[id(o)] = o
|
||||||
return [weakref.ref(obj) for obj in allObjs.values()]
|
return [weakref.ref(obj) for obj in allObjs.values()]
|
||||||
|
@ -51,7 +48,7 @@ def test_PlotWidget():
|
||||||
# return weakrefs to a bunch of objects that should die when the scope exits.
|
# return weakrefs to a bunch of objects that should die when the scope exits.
|
||||||
return mkrefs(w, c, data, w.plotItem, w.plotItem.vb, w.plotItem.getMenu(), w.plotItem.getAxis('left'))
|
return mkrefs(w, c, data, w.plotItem, w.plotItem.vb, w.plotItem.getMenu(), w.plotItem.getAxis('left'))
|
||||||
|
|
||||||
for i in range(5):
|
for _ in range(5):
|
||||||
assert_alldead(mkobjs())
|
assert_alldead(mkobjs())
|
||||||
|
|
||||||
def test_GraphicsWindow():
|
def test_GraphicsWindow():
|
||||||
|
@ -63,7 +60,7 @@ def test_GraphicsWindow():
|
||||||
v1 = w.addViewBox()
|
v1 = w.addViewBox()
|
||||||
return mkrefs(w, p1, v1)
|
return mkrefs(w, p1, v1)
|
||||||
|
|
||||||
for i in range(5):
|
for _ in range(5):
|
||||||
assert_alldead(mkobjs())
|
assert_alldead(mkobjs())
|
||||||
|
|
||||||
def test_ImageView():
|
def test_ImageView():
|
||||||
|
@ -74,13 +71,5 @@ def test_ImageView():
|
||||||
|
|
||||||
return mkrefs(iv, iv.imageItem, iv.view, iv.ui.histogram, data)
|
return mkrefs(iv, iv.imageItem, iv.view, iv.ui.histogram, data)
|
||||||
|
|
||||||
for i in range(5):
|
for _ in range(5):
|
||||||
assert_alldead(mkobjs())
|
assert_alldead(mkobjs())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
ot = test_PlotItem()
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import os, sys, shutil, time
|
import os, sys, shutil, time
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import pyqtgraph.reload
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import sys
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pyqtgraph.Qt import QtCore, QtGui, QT_LIB, mkQApp
|
from pyqtgraph.Qt import QtCore, mkQApp
|
||||||
from pyqtgraph import SignalProxy
|
from pyqtgraph import SignalProxy
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ class Receiver(QtCore.QObject):
|
||||||
def qapp():
|
def qapp():
|
||||||
app = mkQApp()
|
app = mkQApp()
|
||||||
if app is None:
|
if app is None:
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = mkQApp()
|
||||||
yield app
|
yield app
|
||||||
app.processEvents(QtCore.QEventLoop.AllEvents, 100)
|
app.processEvents(QtCore.QEventLoop.AllEvents, 100)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from pyqtgraph.Qt import QtCore, QtGui
|
from pyqtgraph.Qt import QtGui
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.testing import assert_array_almost_equal, assert_almost_equal
|
from numpy.testing import assert_array_almost_equal, assert_almost_equal
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ def crashtest():
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Caught interrupt; send another to exit.")
|
print("Caught interrupt; send another to exit.")
|
||||||
try:
|
try:
|
||||||
for i in range(100):
|
for _ in range(100):
|
||||||
QtTest.QTest.qWait(100)
|
QtTest.QTest.qWait(100)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
thread.terminate()
|
thread.terminate()
|
||||||
|
@ -95,7 +95,7 @@ def createWidget():
|
||||||
p('create widget')
|
p('create widget')
|
||||||
global widgets, allWidgets
|
global widgets, allWidgets
|
||||||
if len(widgets) > 50:
|
if len(widgets) > 50:
|
||||||
return
|
return None
|
||||||
widget = randItem(widgetTypes)()
|
widget = randItem(widgetTypes)()
|
||||||
widget.setWindowTitle(widget.__class__.__name__)
|
widget.setWindowTitle(widget.__class__.__name__)
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
|
@ -153,8 +153,3 @@ def addReference():
|
||||||
obj2 = randItem(widgets)
|
obj2 = randItem(widgets)
|
||||||
p(' %s -> %s' % (obj1, obj2))
|
p(' %s -> %s' % (obj1, obj2))
|
||||||
obj1._testref = obj2
|
obj1._testref = obj2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_stability()
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ def checkLru(lru):
|
||||||
|
|
||||||
lru[2] = 2
|
lru[2] = 2
|
||||||
assert set([2, 3]) == set(lru.values())
|
assert set([2, 3]) == set(lru.values())
|
||||||
|
|
||||||
lru[1] = 1
|
lru[1] = 1
|
||||||
set([2, 1]) == set(lru.values())
|
set([2, 1]) == set(lru.values())
|
||||||
|
|
||||||
|
@ -37,19 +37,16 @@ def checkLru(lru):
|
||||||
lru[2] = 2
|
lru[2] = 2
|
||||||
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
|
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
|
||||||
|
|
||||||
_a = lru[1]
|
_ = lru[1]
|
||||||
assert [(2, 2), (1, 1)] == list(lru.items(accessTime=True))
|
assert [(2, 2), (1, 1)] == list(lru.items(accessTime=True))
|
||||||
|
|
||||||
_a = lru[2]
|
_ = lru[2]
|
||||||
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
|
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
|
||||||
|
|
||||||
assert lru.get(2) == 2
|
assert lru.get(2) == 2
|
||||||
assert lru.get(3) == None
|
assert lru.get(3) is None
|
||||||
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
|
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
|
||||||
|
|
||||||
lru.clear()
|
lru.clear()
|
||||||
assert [] == list(lru.items())
|
assert [] == list(lru.items())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
testLRU()
|
|
||||||
|
|
|
@ -8,10 +8,10 @@ def test_combobox():
|
||||||
cb.setValue(2)
|
cb.setValue(2)
|
||||||
assert str(cb.currentText()) == 'b'
|
assert str(cb.currentText()) == 'b'
|
||||||
assert cb.value() == 2
|
assert cb.value() == 2
|
||||||
|
|
||||||
# Clear item list; value should be None
|
# Clear item list; value should be None
|
||||||
cb.clear()
|
cb.clear()
|
||||||
assert cb.value() == None
|
assert cb.value() is None
|
||||||
|
|
||||||
# Reset item list; value should be set automatically
|
# Reset item list; value should be set automatically
|
||||||
cb.setItems(items)
|
cb.setItems(items)
|
||||||
|
@ -33,12 +33,3 @@ def test_combobox():
|
||||||
|
|
||||||
cb.setItemValue('c', 7)
|
cb.setItemValue('c', 7)
|
||||||
assert cb.value() == 7
|
assert cb.value() == 7
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
cb = pg.ComboBox()
|
|
||||||
cb.show()
|
|
||||||
cb.setItems({'': None, 'a': 1, 'b': 2, 'c': 3})
|
|
||||||
def fn(ind):
|
|
||||||
print("New value: %s" % cb.value())
|
|
||||||
cb.currentIndexChanged.connect(fn)
|
|
|
@ -1,10 +1,9 @@
|
||||||
from pyqtgraph.Qt import QtCore
|
from pyqtgraph.Qt import QtCore, QtGui
|
||||||
from pyqtgraph.Qt import QtGui
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
|
||||||
|
app = pg.mkQApp()
|
||||||
|
|
||||||
def test_basics_graphics_view():
|
def test_basics_graphics_view():
|
||||||
app = pg.mkQApp()
|
|
||||||
view = pg.GraphicsView()
|
view = pg.GraphicsView()
|
||||||
background_role = view.backgroundRole()
|
background_role = view.backgroundRole()
|
||||||
assert background_role == QtGui.QPalette.Window
|
assert background_role == QtGui.QPalette.Window
|
||||||
|
@ -39,11 +38,11 @@ def test_basics_graphics_view():
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
aliasing = QtGui.QPainter.Antialiasing
|
aliasing = QtGui.QPainter.Antialiasing
|
||||||
# Default is set to `False`
|
# Default is set to `False`
|
||||||
assert not view.renderHints() & aliasing == aliasing
|
assert view.renderHints() & aliasing != aliasing
|
||||||
view.setAntialiasing(True)
|
view.setAntialiasing(True)
|
||||||
assert view.renderHints() & aliasing == aliasing
|
assert view.renderHints() & aliasing == aliasing
|
||||||
view.setAntialiasing(False)
|
view.setAntialiasing(False)
|
||||||
assert not view.renderHints() & aliasing == aliasing
|
assert view.renderHints() & aliasing != aliasing
|
||||||
|
|
||||||
# Enable mouse
|
# Enable mouse
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|
|
@ -41,4 +41,4 @@ def testHistogramLUTWidget():
|
||||||
w.setImageItem(img)
|
w.setImageItem(img)
|
||||||
|
|
||||||
QtGui.QApplication.processEvents()
|
QtGui.QApplication.processEvents()
|
||||||
|
win.close()
|
||||||
|
|
|
@ -117,12 +117,3 @@ def test_TableWidget():
|
||||||
assert isinstance(item.value, float)
|
assert isinstance(item.value, float)
|
||||||
assert isinstance(item.index, int)
|
assert isinstance(item.index, int)
|
||||||
assert item.text() == ("%d %f" % (item.index, item.value))
|
assert item.text() == ("%d %f" % (item.index, item.value))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
w = pg.TableWidget(editable=True)
|
|
||||||
w.setData(listOfTuples)
|
|
||||||
w.resize(600, 600)
|
|
||||||
w.show()
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue