Merge pull request #188 from ericdill/clean-up-after-oneself

Clean up temp file from test suite
This commit is contained in:
Luke Campagnola 2015-07-18 10:22:49 +02:00
commit f0c9cfa96f
3 changed files with 32 additions and 14 deletions

View File

View File

@ -1,16 +1,23 @@
"""
SVG export test
"""
from __future__ import division, print_function, absolute_import
import pyqtgraph as pg
import pyqtgraph.exporters
import csv
import os
import tempfile
app = pg.mkQApp()
def approxeq(a, b):
return (a-b) <= ((a + b) * 1e-6)
def test_CSVExporter():
tempfilename = tempfile.NamedTemporaryFile(suffix='.csv').name
print("using %s as a temporary file" % tempfilename)
plt = pg.plot()
y1 = [1,3,2,3,1,6,9,8,4,2]
plt.plot(y=y1, name='myPlot')
@ -24,9 +31,9 @@ def test_CSVExporter():
plt.plot(x=x3, y=y3, stepMode=True)
ex = pg.exporters.CSVExporter(plt.plotItem)
ex.export(fileName='test.csv')
ex.export(fileName=tempfilename)
r = csv.reader(open('test.csv', 'r'))
r = csv.reader(open(tempfilename, 'r'))
lines = [line for line in r]
header = lines.pop(0)
assert header == ['myPlot_x', 'myPlot_y', 'x0001', 'y0001', 'x0002', 'y0002']
@ -43,7 +50,8 @@ def test_CSVExporter():
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])
i += 1
os.unlink(tempfilename)
if __name__ == '__main__':
test_CSVExporter()

View File

@ -1,11 +1,18 @@
"""
SVG export test
"""
from __future__ import division, print_function, absolute_import
import pyqtgraph as pg
import pyqtgraph.exporters
import tempfile
import os
app = pg.mkQApp()
def test_plotscene():
tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name
print("using %s as a temporary file" % tempfilename)
pg.setConfigOption('foreground', (0,0,0))
w = pg.GraphicsWindow()
w.show()
@ -18,10 +25,13 @@ def test_plotscene():
app.processEvents()
ex = pg.exporters.SVGExporter(w.scene())
ex.export(fileName='test.svg')
ex.export(fileName=tempfilename)
# clean up after the test is done
os.unlink(tempfilename)
def test_simple():
tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name
print("using %s as a temporary file" % tempfilename)
scene = pg.QtGui.QGraphicsScene()
#rect = pg.QtGui.QGraphicsRectItem(0, 0, 100, 100)
#scene.addItem(rect)
@ -51,17 +61,17 @@ def test_simple():
#el = pg.QtGui.QGraphicsEllipseItem(0, 0, 100, 50)
#el.translate(10,-5)
#el.scale(0.5,2)
#el.setParentItem(rect2)
grp2 = pg.ItemGroup()
scene.addItem(grp2)
grp2.scale(100,100)
rect3 = pg.QtGui.QGraphicsRectItem(0,0,2,2)
rect3.setPen(pg.mkPen(width=1, cosmetic=False))
grp2.addItem(rect3)
ex = pg.exporters.SVGExporter(scene)
ex.export(fileName='test.svg')
ex = pg.exporters.SVGExporter(scene)
ex.export(fileName=tempfilename)
os.unlink(tempfilename)