|
1 | 1 | import unittest |
2 | | -from unittest.mock import patch, Mock |
3 | 2 | import sys |
| 3 | +from typing import Type |
| 4 | +from unittest.mock import patch, Mock |
4 | 5 |
|
5 | 6 | from Orange.classification import GBClassifier |
6 | 7 |
|
|
27 | 28 | CatGBRegressor = None |
28 | 29 | from Orange.widgets.model.owgradientboosting import OWGradientBoosting, \ |
29 | 30 | LearnerItemModel, GBLearnerEditor, XGBLearnerEditor, XGBRFLearnerEditor, \ |
30 | | - CatGBLearnerEditor |
| 31 | + CatGBLearnerEditor, BaseEditor |
31 | 32 | from Orange.widgets.settings import SettingProvider |
32 | 33 | from Orange.widgets.tests.base import WidgetTest, ParameterMapping, \ |
33 | 34 | WidgetLearnerTestMixin, datasets, simulate, GuiTest |
@@ -66,11 +67,22 @@ def test_missing_lib(self): |
66 | 67 | self.assertFalse(model.item(1).isEnabled()) |
67 | 68 |
|
68 | 69 |
|
69 | | -class TestGBLearnerEditor(GuiTest): |
| 70 | +class BaseEditorTest(GuiTest): |
| 71 | + EditorClass: Type[BaseEditor] = None |
| 72 | + |
70 | 73 | def setUp(self): |
71 | | - editor_class = GBLearnerEditor |
| 74 | + super().setUp() |
| 75 | + editor_class = self.EditorClass |
72 | 76 | self.widget = create_parent(editor_class) |
73 | | - self.editor = editor_class(self.widget) |
| 77 | + self.editor = editor_class(self.widget) # pylint: disable=not-callable |
| 78 | + |
| 79 | + def tearDown(self) -> None: |
| 80 | + self.widget.deleteLater() |
| 81 | + super().tearDown() |
| 82 | + |
| 83 | + |
| 84 | +class TestGBLearnerEditor(BaseEditorTest): |
| 85 | + EditorClass = GBLearnerEditor |
74 | 86 |
|
75 | 87 | def test_arguments(self): |
76 | 88 | args = {"n_estimators": 100, "learning_rate": 0.1, "max_depth": 3, |
@@ -116,11 +128,8 @@ def test_default_parameters_reg(self): |
116 | 128 | self.assertIsNone(params["random_state"]) |
117 | 129 |
|
118 | 130 |
|
119 | | -class TestXGBLearnerEditor(GuiTest): |
120 | | - def setUp(self): |
121 | | - editor_class = XGBLearnerEditor |
122 | | - self.widget = create_parent(editor_class) |
123 | | - self.editor = editor_class(self.widget) |
| 131 | +class TestXGBLearnerEditor(BaseEditorTest): |
| 132 | + EditorClass = XGBLearnerEditor |
124 | 133 |
|
125 | 134 | def test_arguments(self): |
126 | 135 | args = {"n_estimators": 100, "learning_rate": 0.3, "max_depth": 6, |
@@ -181,11 +190,8 @@ def test_default_parameters_reg(self): |
181 | 190 | self.editor.colsample_bynode) |
182 | 191 |
|
183 | 192 |
|
184 | | -class TestXGBRFLearnerEditor(GuiTest): |
185 | | - def setUp(self): |
186 | | - editor_class = XGBRFLearnerEditor |
187 | | - self.widget = create_parent(editor_class) |
188 | | - self.editor = editor_class(self.widget) |
| 193 | +class TestXGBRFLearnerEditor(BaseEditorTest): |
| 194 | + EditorClass = XGBRFLearnerEditor |
189 | 195 |
|
190 | 196 | def test_arguments(self): |
191 | 197 | args = {"n_estimators": 100, "learning_rate": 0.3, "max_depth": 6, |
@@ -247,11 +253,8 @@ def test_default_parameters_reg(self): |
247 | 253 | self.editor.colsample_bynode) |
248 | 254 |
|
249 | 255 |
|
250 | | -class TestCatGBLearnerEditor(GuiTest): |
251 | | - def setUp(self): |
252 | | - editor_class = CatGBLearnerEditor |
253 | | - self.widget = create_parent(editor_class) |
254 | | - self.editor = editor_class(self.widget) |
| 256 | +class TestCatGBLearnerEditor(BaseEditorTest): |
| 257 | + EditorClass = CatGBLearnerEditor |
255 | 258 |
|
256 | 259 | def test_arguments(self): |
257 | 260 | args = {"n_estimators": 100, "learning_rate": 0.3, "max_depth": 6, |
|
0 commit comments