test: test_make_plot and test_to_dict

This commit is contained in:
stalbe_j
2023-01-27 16:29:05 +01:00
parent d3a9fd736c
commit 43937a0db3

View File

@ -1,5 +1,14 @@
from grum.plotdesc import PlotDescription
import pytest
import pyqtgraph as pg
from grum.theme import pg_plot_style
from grum.mdi.mdisubplot import MDISubPlot
from grum.mainwin import MainWindow
import sys
from PyQt5.QtWidgets import QApplication
from grum import theme
@pytest.mark.parametrize(
"plot_name, plot_title, plot_xlabel, plot_ylabel, xs,ys", [('plot_name',
@ -42,3 +51,27 @@ def test_append():
assert pd.xs == [1,2,3]
assert pd.ys == [3,4,5]
def test_make_plot():
pd = PlotDescription('plot_name', 'plot_title', 'plot_xlabel', 'plot_ylabel', [1,2], [3,4])
app = QApplication(sys.argv)
theme.apply(app)
mw = MainWindow(add_examples=True)
mdi_sub = MDISubPlot('mdi', pd)
pw = pg.PlotWidget()
style = pg_plot_style()
ret = pd.make_plot(pw, style)
assert isinstance(ret, pg.PlotDataItem)
assert pw.getAxis("left").labelText == 'plot_ylabel'
assert pw.getAxis("bottom").labelText == 'plot_xlabel'
assert pw.getPlotItem().titleLabel.text == 'plot_title'
def test_to_dict():
pd = PlotDescription('plot_name', 'plot_title', 'plot_xlabel', 'plot_ylabel', [1,2], [3,4])
assert pd.to_dict() == {'title': 'plot_title', 'xlabel': 'plot_xlabel', 'xs': [1, 2], 'ylabel': 'plot_ylabel', 'ys': [3,4]}