Merge pull request #188 from ericdill/clean-up-after-oneself
Clean up temp file from test suite
This commit is contained in:
commit
f0c9cfa96f
0
pyqtgraph/exporters/tests/__init__.py
Normal file
0
pyqtgraph/exporters/tests/__init__.py
Normal file
@ -1,16 +1,23 @@
|
|||||||
"""
|
"""
|
||||||
SVG export test
|
SVG export test
|
||||||
"""
|
"""
|
||||||
|
from __future__ import division, print_function, absolute_import
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import pyqtgraph.exporters
|
|
||||||
import csv
|
import csv
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
|
||||||
app = pg.mkQApp()
|
app = pg.mkQApp()
|
||||||
|
|
||||||
|
|
||||||
def approxeq(a, b):
|
def approxeq(a, b):
|
||||||
return (a-b) <= ((a + b) * 1e-6)
|
return (a-b) <= ((a + b) * 1e-6)
|
||||||
|
|
||||||
|
|
||||||
def test_CSVExporter():
|
def test_CSVExporter():
|
||||||
|
tempfilename = tempfile.NamedTemporaryFile(suffix='.csv').name
|
||||||
|
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')
|
||||||
@ -24,9 +31,9 @@ def test_CSVExporter():
|
|||||||
plt.plot(x=x3, y=y3, stepMode=True)
|
plt.plot(x=x3, y=y3, stepMode=True)
|
||||||
|
|
||||||
ex = pg.exporters.CSVExporter(plt.plotItem)
|
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]
|
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']
|
||||||
@ -43,7 +50,8 @@ def test_CSVExporter():
|
|||||||
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
|
i += 1
|
||||||
|
|
||||||
|
os.unlink(tempfilename)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_CSVExporter()
|
test_CSVExporter()
|
||||||
|
|
@ -1,11 +1,18 @@
|
|||||||
"""
|
"""
|
||||||
SVG export test
|
SVG export test
|
||||||
"""
|
"""
|
||||||
|
from __future__ import division, print_function, absolute_import
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import pyqtgraph.exporters
|
import tempfile
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
app = pg.mkQApp()
|
app = pg.mkQApp()
|
||||||
|
|
||||||
|
|
||||||
def test_plotscene():
|
def test_plotscene():
|
||||||
|
tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name
|
||||||
|
print("using %s as a temporary file" % tempfilename)
|
||||||
pg.setConfigOption('foreground', (0,0,0))
|
pg.setConfigOption('foreground', (0,0,0))
|
||||||
w = pg.GraphicsWindow()
|
w = pg.GraphicsWindow()
|
||||||
w.show()
|
w.show()
|
||||||
@ -18,10 +25,13 @@ def test_plotscene():
|
|||||||
app.processEvents()
|
app.processEvents()
|
||||||
|
|
||||||
ex = pg.exporters.SVGExporter(w.scene())
|
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():
|
def test_simple():
|
||||||
|
tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name
|
||||||
|
print("using %s as a temporary file" % tempfilename)
|
||||||
scene = pg.QtGui.QGraphicsScene()
|
scene = pg.QtGui.QGraphicsScene()
|
||||||
#rect = pg.QtGui.QGraphicsRectItem(0, 0, 100, 100)
|
#rect = pg.QtGui.QGraphicsRectItem(0, 0, 100, 100)
|
||||||
#scene.addItem(rect)
|
#scene.addItem(rect)
|
||||||
@ -51,17 +61,17 @@ def test_simple():
|
|||||||
#el = pg.QtGui.QGraphicsEllipseItem(0, 0, 100, 50)
|
#el = pg.QtGui.QGraphicsEllipseItem(0, 0, 100, 50)
|
||||||
#el.translate(10,-5)
|
#el.translate(10,-5)
|
||||||
#el.scale(0.5,2)
|
#el.scale(0.5,2)
|
||||||
|
|
||||||
#el.setParentItem(rect2)
|
#el.setParentItem(rect2)
|
||||||
|
|
||||||
grp2 = pg.ItemGroup()
|
grp2 = pg.ItemGroup()
|
||||||
scene.addItem(grp2)
|
scene.addItem(grp2)
|
||||||
grp2.scale(100,100)
|
grp2.scale(100,100)
|
||||||
|
|
||||||
rect3 = pg.QtGui.QGraphicsRectItem(0,0,2,2)
|
rect3 = pg.QtGui.QGraphicsRectItem(0,0,2,2)
|
||||||
rect3.setPen(pg.mkPen(width=1, cosmetic=False))
|
rect3.setPen(pg.mkPen(width=1, cosmetic=False))
|
||||||
grp2.addItem(rect3)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user