|
1 | 1 | # pylint: disable=missing-docstring |
| 2 | +from unittest.mock import patch |
| 3 | + |
| 4 | +import collections |
2 | 5 | import numpy as np |
3 | 6 |
|
4 | 7 | import unittest |
5 | 8 |
|
| 9 | +from AnyQt.QtWidgets import QMenu |
| 10 | +from AnyQt.QtCore import QPoint |
| 11 | + |
6 | 12 | from Orange.data import Table, Domain |
7 | 13 | from Orange.classification import MajorityLearner |
8 | 14 | from Orange.regression import MeanLearner |
@@ -70,6 +76,59 @@ def test_CrossValidationByFeature(self): |
70 | 76 | self.assertEqual(self.widget.resampling, OWTestLearners.KFold) |
71 | 77 | self.assertFalse(self.widget.features_combo.isEnabled()) |
72 | 78 |
|
| 79 | + def test_update_shown_columns(self): |
| 80 | + w = self.widget #: OWTestLearners |
| 81 | + all, shown = "MABDEFG", "ABDF" |
| 82 | + header = w.view.horizontalHeader() |
| 83 | + w.shown_scores = set(shown) |
| 84 | + w.result_model.setHorizontalHeaderLabels(list(all)) |
| 85 | + w._update_shown_columns() |
| 86 | + for i, name in enumerate(all): |
| 87 | + self.assertEqual(name == "M" or name in shown, |
| 88 | + not header.isSectionHidden(i), |
| 89 | + msg="error in section {}({})".format(i, name)) |
| 90 | + |
| 91 | + w.shown_scores = set() |
| 92 | + w._update_shown_columns() |
| 93 | + for i, name in enumerate(all): |
| 94 | + self.assertEqual(i == 0, |
| 95 | + not header.isSectionHidden(i), |
| 96 | + msg="error in section {}({})".format(i, name)) |
| 97 | + |
| 98 | + def test_show_column_chooser(self): |
| 99 | + w = self.widget #: OWTestLearners |
| 100 | + all, shown = "MABDEFG", "ABDF" |
| 101 | + header = w.view.horizontalHeader() |
| 102 | + w.shown_scores = set(shown) |
| 103 | + w.result_model.setHorizontalHeaderLabels(list(all)) |
| 104 | + w._update_shown_columns() |
| 105 | + |
| 106 | + actions = collections.OrderedDict() |
| 107 | + menu_add_action = QMenu.addAction |
| 108 | + |
| 109 | + def addAction(menu, a): |
| 110 | + action = menu_add_action(menu, a) |
| 111 | + actions[a] = action |
| 112 | + return action |
| 113 | + |
| 114 | + def execmenu(*_): |
| 115 | + self.assertEqual(list(actions), list(all)[1:]) |
| 116 | + print(actions) |
| 117 | + for name, action in actions.items(): |
| 118 | + self.assertEqual(action.isChecked(), name in shown) |
| 119 | + actions["E"].triggered.emit(True) |
| 120 | + self.assertEqual(w.shown_scores, set("ABDEF")) |
| 121 | + actions["B"].triggered.emit(False) |
| 122 | + self.assertEqual(w.shown_scores, set("ADEF")) |
| 123 | + for i, name in enumerate(all): |
| 124 | + self.assertEqual(name == "M" or name in "ADEF", |
| 125 | + not header.isSectionHidden(i), |
| 126 | + msg="error in section {}({})".format(i, name)) |
| 127 | + |
| 128 | + with patch("AnyQt.QtWidgets.QMenu.addAction", addAction),\ |
| 129 | + patch("AnyQt.QtWidgets.QMenu.exec", execmenu): |
| 130 | + w.show_column_chooser(QPoint(0, 0)) |
| 131 | + |
73 | 132 |
|
74 | 133 | class TestHelpers(unittest.TestCase): |
75 | 134 | def test_results_one_vs_rest(self): |
|
0 commit comments