pyqtgraph/tests/exporters/test_image.py

29 lines
814 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2021-06-09 19:16:22 +00:00
import numpy as np
import pyqtgraph as pg
2021-06-09 19:16:22 +00:00
from pyqtgraph.Qt import QtGui
from pyqtgraph.exporters import ImageExporter
2021-06-09 19:16:22 +00:00
import pyqtgraph.functions as fn
app = pg.mkQApp()
def test_ImageExporter_filename_dialog():
"""Tests ImageExporter code path that opens a file dialog. Regression test
for pull request 1133."""
p = pg.plot()
exp = ImageExporter(p.getPlotItem())
exp.export()
2021-06-09 19:16:22 +00:00
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."