tests: added test to test_append_data

This commit is contained in:
stalbe_j
2023-01-17 13:07:00 +01:00
parent db5186781d
commit aa6a85650f

View File

@ -25,7 +25,7 @@ from math import isclose
class TestViewUnit(unittest.TestCase):
def setUp(self) -> None:
print('setup')
print("setup")
self.app = QApplication(sys.argv)
theme.apply(self.app)
# ctrl_c.setup(self.app)
@ -36,7 +36,7 @@ class TestViewUnit(unittest.TestCase):
print("teardown")
self.mw.rst.wait_for_stop()
self.app.quit()
print('app quit called')
print("app quit called")
del self.mw
del self.app
@ -67,12 +67,12 @@ class TestViewUnit(unittest.TestCase):
title = "plot_title"
xlabel = "xlabel"
ylabel = "ylabel"
cfg = {'title':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)
mw.new_plot(name, cfg=cfg)
assert name in mw.lst.lst.items.keys()
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
@ -83,7 +83,6 @@ class TestViewUnit(unittest.TestCase):
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)
@ -93,45 +92,54 @@ class TestViewUnit(unittest.TestCase):
assert len(spy_sig_make_new_plot) == 0 # assert not called
def test_append_data(self):
mw=self.mw
item = mw.lst.lst.get("sine")
item.set_alarm = mock.MagicMock()
item.value.append = mock.MagicMock()
mw = self.mw
sine_item = mw.lst.lst.get("sine")
sine_item.set_alarm = mock.MagicMock()
sine_item.value.append = mock.MagicMock()
point = (1,2)
point = (1, 2)
mw.append_data("sine", point)
item.value.append.assert_called_once_with(point)
item.set_alarm.assert_called_once_with(True)
mw.append_data("sine", point)
sine_item.value.append.assert_called_once_with(point)
sine_item.set_alarm.assert_called_once_with(True)
sub = MDISubPlot("sine", sine_item.value)
mw.mdi.add(sub)
sub.plot.setData = mock.MagicMock()
mw.append_data("sine", point)
sub.plot.setData.assert_called_once_with(*sine_item.value.data)
print(sine_item.set_alarm.call_args)
assert sine_item.set_alarm.call_args[0][0] == False
def test_on_make_new_plot(self):
mw = self.mw
mw.make_subwin = mock.MagicMock()
args = (1,2,'name')
kwargs = {'title':'plot_title'}
args = (1, 2, "name")
kwargs = {"title": "plot_title"}
mw.on_make_new_plot(args, kwargs)
mw.make_subwin.assert_called_once_with(MDISubPlot,args, kwargs)
mw.make_subwin.assert_called_once_with(MDISubPlot, args, kwargs)
def test_on_dclick_list_item(self):
mw = self.mw
mw = self.mw
mw.plot_single_item = mock.MagicMock()
item = mw.lst.lst.get("sine")
mw.on_dclick_list_item(item)
mw.plot_single_item.assert_called_once_with(item)
mw.plot_single_item.assert_called_once_with(item)
def test_on_plot_selected(self):
mw = self.mw
sine_item = mw.lst.lst.get("sine")
cosine_item = mw.lst.lst.get("cosine")
mw.lst.setCurrentItem(sine_item)
assert mw.lst.selectedItems()
assert mw.lst.selectedItems()
mw.plot_single_item = mock.MagicMock()
mw.on_plot_selected()
@ -154,17 +162,18 @@ class TestViewUnit(unittest.TestCase):
sine_item.set_alarm = mock.MagicMock()
mw.activate_or_make_subwin = mock.MagicMock()
mw.plot_single_item(sine_item)
sine_item.set_alarm.assert_called_once_with(False)
mw.activate_or_make_subwin.assert_called_once_with(MDISubPlot, sine_item.key, sine_item.value)
mw.activate_or_make_subwin.assert_called_once_with(
MDISubPlot, sine_item.key, sine_item.value
)
def test_plot_multiple_items(self):
mw = self.mw
sine_item = mw.lst.lst.get("sine")
cosine_item = mw.lst.lst.get("cosine")
names = ["sine", 'cosine']
names = ["sine", "cosine"]
name = " | ".join(names)
items = [sine_item, cosine_item]
descs = (sine_item.value, cosine_item.value)
@ -178,13 +187,13 @@ class TestViewUnit(unittest.TestCase):
def test_activate_or_make_subwin(self):
mw = self.mw
sine_item = mw.lst.lst.get("sine")
sub = MDISubPlot('sine', sine_item.value )
sub = MDISubPlot("sine", sine_item.value)
mw.mdi.add(sub)
cosine_item = mw.lst.get('cosine')
cosine_item = mw.lst.get("cosine")
mw.mdi.setActiveSubWindow = mock.MagicMock()
assert mw.mdi.findSubWindow('sine')
assert mw.mdi.findSubWindow("sine")
mw.activate_or_make_subwin(MDISubPlot, sine_item.key, sine_item.value)
@ -192,17 +201,19 @@ class TestViewUnit(unittest.TestCase):
mw.make_subwin = mock.MagicMock()
mw.activate_or_make_subwin(MDISubPlot, cosine_item.key, cosine_item.value)
mw.make_subwin.assert_called_once_with(MDISubPlot, cosine_item.key, cosine_item.value)
mw.make_subwin.assert_called_once_with(
MDISubPlot, cosine_item.key, cosine_item.value
)
def test_make_subwin(self):
mw= self.mw
cosine_item = mw.lst.get('cosine')
mw = self.mw
cosine_item = mw.lst.get("cosine")
mw.mdi.add = mock.MagicMock()
# sub = MDISubPlot(cosine_item.key, cosine_item.value)
mw.make_subwin(MDISubPlot, cosine_item.key, cosine_item.value)
mw.make_subwin(MDISubPlot, cosine_item.key, cosine_item.value)
assert isinstance(mw.mdi.add.call_args[0][0], MDISubPlot)
# mw.mdi.add.assert_called_once_with(sub)
# mw.mdi.add.assert_called_once_with(sub)