Skip to content

Commit

Permalink
Tests for SliderGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Jul 11, 2019
1 parent 01c2a00 commit 5f68a17
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions Orange/widgets/utils/tests/test_slidergraph.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 5f68a17

Please sign in to comment.