From b3e8f332fb94b5aba861bd019484fff3cd9eb330 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Thu, 10 Jun 2021 03:16:22 +0800 Subject: [PATCH] add test for export to qimage --- tests/exporters/test_image.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/exporters/test_image.py b/tests/exporters/test_image.py index 6f52eceb..a3015e67 100644 --- a/tests/exporters/test_image.py +++ b/tests/exporters/test_image.py @@ -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."