Skip to content

Commit

Permalink
oweditdomain: Add tests for ordered categorical change
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Jan 15, 2019
1 parent 0f3d59d commit b65c214
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions Orange/widgets/data/tests/test_oweditdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
OWEditDomain,
ContinuousVariableEditor, DiscreteVariableEditor, VariableEditor,
TimeVariableEditor, Categorical, Real, Time, String,
Rename, Annotate, CategoriesMapping, report_transform,
apply_transform
Rename, Annotate, CategoriesMapping, ChangeOrdered, report_transform,
apply_transform,
)
from Orange.widgets.data.owcolor import OWColor, ColorRole
from Orange.widgets.tests.base import WidgetTest, GuiTest
Expand Down Expand Up @@ -53,6 +53,12 @@ def test_categories_mapping(self):
self.assertIn("b", r)
self.assertIn("<s>", r)

def test_change_ordered(self):
var = Categorical("C", ("a", "b"), None, ())
tr = ChangeOrdered(True)
r = report_transform(var, [tr])
self.assertIn("ordered", r)


class TestOWEditDomain(WidgetTest):
def setUp(self):
Expand Down Expand Up @@ -166,6 +172,21 @@ def test_time_variable_preservation(self):
output = self.get_output(self.widget.Outputs.data)
self.assertEqual(str(table[0, 4]), str(output[0, 4]))

def test_change_ordered(self):
"""Test categorical ordered flag change"""
table = Table(Domain(
[DiscreteVariable("A", values=["a", "b"], ordered=True)]))
self.send_signal(self.widget.Inputs.data, table)
output = self.get_output(self.widget.Outputs.data)
self.assertTrue(output.domain[0].ordered)

editor = self.widget.findChild(DiscreteVariableEditor)
assert isinstance(editor, DiscreteVariableEditor)
editor.ordered_cb.setChecked(False)
self.widget.commit()
output = self.get_output(self.widget.Outputs.data)
self.assertFalse(output.domain[0].ordered)


class TestEditors(GuiTest):
def test_variable_editor(self):
Expand Down Expand Up @@ -217,6 +238,7 @@ def test_discrete_editor(self):
w.set_data(v)

self.assertEqual(w.name_edit.text(), v.name)
self.assertFalse(w.ordered_cb.isChecked())
self.assertEqual(w.labels_model.get_dict(), dict(v.annotations))
self.assertEqual(w.get_data(), (v, []))
w.set_data(None)
Expand All @@ -233,6 +255,11 @@ def test_discrete_editor(self):
w.grab() # run delegate paint method
self.assertEqual(w.get_data(), (v, [CategoriesMapping(mapping)]))

w.set_data(v, [CategoriesMapping(mapping), ChangeOrdered(True)])
self.assertTrue(w.ordered_cb.isChecked())
self.assertEqual(
w.get_data()[1], [CategoriesMapping(mapping), ChangeOrdered(True)]
)
# test selection/deselection in the view
w.set_data(v)
view = w.values_edit
Expand Down Expand Up @@ -299,6 +326,11 @@ def test_discrete_reorder(self):
DD.compute_value, Lookup(D, np.array([2, 3, 1, 0]))
)

def test_ordered_change(self):
D = DiscreteVariable("D", values=("a", "b"), ordered=True)
Do = apply_transform(D, [ChangeOrdered(False)])
self.assertFalse(Do.ordered)

def test_discrete_add_drop(self):
D = DiscreteVariable("D", values=("2", "3", "1", "0"), base_value=1)
mapping = (
Expand Down

0 comments on commit b65c214

Please sign in to comment.