add test for export to qimage

This commit is contained in:
KIU Shueng Chuan 2021-06-10 03:16:22 +08:00
parent 765f9648cd
commit b3e8f332fb

View File

@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui
from pyqtgraph.exporters import ImageExporter
import pyqtgraph.functions as fn
app = pg.mkQApp()
@ -11,3 +14,15 @@ def test_ImageExporter_filename_dialog():
p = pg.plot()
exp = ImageExporter(p.getPlotItem())
exp.export()
def test_ImageExporter_toBytes():
p = pg.plot()
p.hideAxis('bottom')
p.hideAxis('left')
exp = ImageExporter(p.getPlotItem())
qimg = exp.export(toBytes=True)
qimg = qimg.convertToFormat(QtGui.QImage.Format.Format_RGBA8888)
data = fn.qimage_to_ndarray(qimg)
black = (0, 0, 0, 255)
assert np.all(data == black), "Exported image should be entirely black."