From 5f68a17f5e7293e0a46a572932fb1f249611de40 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Primo=C5=BE=20Godec?=
Date: Thu, 11 Jul 2019 14:34:15 +0200
Subject: [PATCH] Tests for SliderGraph
---
.../widgets/utils/tests/test_slidergraph.py | 100 ++++++++++++++++++
1 file changed, 100 insertions(+)
create mode 100644 Orange/widgets/utils/tests/test_slidergraph.py
diff --git a/Orange/widgets/utils/tests/test_slidergraph.py b/Orange/widgets/utils/tests/test_slidergraph.py
new file mode 100644
index 00000000000..66bb61dce05
--- /dev/null
+++ b/Orange/widgets/utils/tests/test_slidergraph.py
@@ -0,0 +1,100 @@
+import numpy as np
+from AnyQt.QtCore import Qt
+
+from Orange.widgets import widget
+from Orange.widgets.tests.base import WidgetTest
+from Orange.widgets.utils.slidergraph import SliderGraph
+
+
+class SimpleWidget(widget.OWWidget):
+ name = "Simple widget"
+
+ def __init__(self):
+ self.plot = SliderGraph(x_axis_label="label1",
+ y_axis_label="label2",
+ callback=self.callback_fun)
+
+ self.mainArea.layout().addWidget(self.plot)
+
+ def callback_fun(self, value):
+ pass
+
+
+class TestSliderGraph(WidgetTest):
+ def setUp(self):
+ self.data = [np.array([1, 2, 3, 4, 5, 6, 7])]
+ self.widget = self.create_widget(SimpleWidget)
+
+ def test_init(self):
+ p = self.widget.plot
+
+ # labels set correctly?
+ self.assertEqual("label1", p.getAxis("bottom").labelText)
+ self.assertEqual("label2", p.getAxis("left").labelText)
+
+ self.assertIsNone(p._line)
+ self.assertIsNone(p.sequences)
+ self.assertIsNone(p.x)
+ self.assertIsNone(p.selection_limit)
+ self.assertIsNone(p.data_increasing)
+
+ self.assertListEqual([], p.plot_horlabel)
+ self.assertListEqual([], p.plot_horline)
+
+ def test_plot(self):
+ p = self.widget.plot
+ x = np.arange(len(self.data[0]))
+ p.update(x, self.data, [Qt.red],
+ cutpoint_x=1)
+
+ # labels set correctly?
+ self.assertEqual("label1", p.getAxis("bottom").labelText)
+ self.assertEqual("label2", p.getAxis("left").labelText)
+
+ self.assertIsNotNone(p._line)
+ np.testing.assert_array_equal(self.data, p.sequences)
+ np.testing.assert_array_equal(x, p.x)
+ self.assertTrue(p.data_increasing)
+
+ self.assertEqual(len(p.plot_horlabel), 1)
+ self.assertEqual(len(p.plot_horline), 1)
+ self.assertIsNotNone(p._line)
+
+ def test_plot_selection_limit(self):
+ p = self.widget.plot
+ x = np.arange(len(self.data[0]))
+ p.update(x, self.data, [Qt.red],
+ cutpoint_x=1, selection_limit=(0, 2))
+
+ # labels set correctly?
+ self.assertEqual("label1", p.getAxis("bottom").labelText)
+ self.assertEqual("label2", p.getAxis("left").labelText)
+
+ self.assertIsNotNone(p._line)
+ np.testing.assert_array_equal(self.data, p.sequences)
+ np.testing.assert_array_equal(x, p.x)
+ self.assertTrue(p.data_increasing)
+ self.assertTupleEqual((0, 2), p.selection_limit)
+ self.assertEqual((0, 2), p._line.maxRange)
+
+ self.assertEqual(len(p.plot_horlabel), 1)
+ self.assertEqual(len(p.plot_horline), 1)
+ self.assertIsNotNone(p._line)
+
+ def test_plot_no_cutpoint(self):
+ """
+ When no cutpoint provided there must be no cutpoint plotted.
+ """
+ p = self.widget.plot
+ x = np.arange(len(self.data[0]))
+ p.update(x, self.data, [Qt.red])
+
+ self.assertIsNone(p._line)
+
+ # then it is set
+ p.update(x, self.data, [Qt.red], cutpoint_x=1)
+ self.assertIsNotNone(p._line)
+
+ # and re-ploted without cutpoint again
+ p.update(x, self.data, [Qt.red])
+ self.assertIsNone(p._line)