test: test_new_plot

This commit is contained in:
stalbe_j
2023-01-16 16:44:31 +01:00
parent 071dac82af
commit 145d05c111

View File

@ -1,6 +1,6 @@
import unittest
import sys
# import pytest
from PyQt5.QtWidgets import QApplication, QAction
from grum.mainwin import MainWindow
@ -13,12 +13,14 @@ from grum.plotdesc import PlotDescription
from grum.menus.rclickmenu import RClickMenu
from grum.menus import BarMenu
from grum.mdi import MDIArea
from grum.rpc import RPCServerThread
from PyQt5.QtTest import QSignalSpy
# import parametrized
# from parameterized import parameterized
class TestViewUnit(unittest.TestCase):
def setUp(self) -> None:
self.app = QApplication(sys.argv)
theme.apply(self.app)
@ -29,6 +31,7 @@ class TestViewUnit(unittest.TestCase):
def tearDown(self) -> None:
print("teardown")
self.app.quit()
self.mw.rst.shutdown()
def test_defaults(self):
@ -41,10 +44,44 @@ class TestViewUnit(unittest.TestCase):
for key in mw.lst.lst.items:
assert isinstance(mw.lst.lst.get(key), DictListItem)
assert isinstance(mw.lst.lst.get(key).value, PlotDescription)
assert isinstance(mw.lst.menu, RClickMenu)
assert isinstance(mw.menu_settings, BarMenu)
assert isinstance(mw.menu_settings.checkboxes["Open new plots"], QAction)
assert isinstance(mw.mdi, MDIArea)
# @parameterized.expand([["Dotted line", "r"], ["Line", "r"], ["Dots", None]])
def test_new_plot(self):
mw = self.mw
name = "plot_name"
title = "plot_title"
xlabel = "xlabel"
ylabel = "ylabel"
cfg = {'title':title, 'xlabel':xlabel, 'ylabel': ylabel}
spy_sig_make_new_plot = QSignalSpy(mw.sig_make_new_plot)
mw.new_plot(name, cfg = cfg)
assert name in mw.lst.lst.items.keys()
assert isinstance(mw.lst.lst.get(name).value, PlotDescription)
assert mw.lst.lst.get(name).value.title == title
assert mw.lst.lst.get(name).value.xlabel == xlabel
assert mw.lst.lst.get(name).value.ylabel == ylabel
assert mw.menu_settings.checkboxes["Open new plots"].isChecked()
assert len(spy_sig_make_new_plot) == 1 # assert called once
assert spy_sig_make_new_plot[0][0] == name # assert called with name
assert isinstance(spy_sig_make_new_plot[0][1], PlotDescription)
mw.menu_settings.checkboxes["Open new plots"].setChecked(False)
assert mw.menu_settings.checkboxes["Open new plots"].isChecked() == False
spy_sig_make_new_plot = QSignalSpy(mw.sig_make_new_plot)
mw.new_plot("new_name", cfg)
assert len(spy_sig_make_new_plot) == 0 # assert not called