Skip to content

Commit

Permalink
OWBaseLearner: Save learner name in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
astaric committed Sep 21, 2017
1 parent 351b364 commit 984e7ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Orange/widgets/utils/owlearnerwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class OWBaseLearner(OWWidget, metaclass=OWBaseLearnerMeta):
LEARNER = None
supports_sparse = True

learner_name = Setting(None, schema_only=True)
want_main_area = False
resizing_enabled = False
auto_apply = Setting(True)
Expand Down Expand Up @@ -96,7 +97,8 @@ def __init__(self):
self.data = None
self.valid_data = False
self.learner = None
self.learner_name = self.name
if self.learner_name is None:
self.learner_name = self.name
self.model = None
self.preprocessors = None
self.outdated_settings = False
Expand Down
16 changes: 16 additions & 0 deletions Orange/widgets/utils/tests/test_owlearnerwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,19 @@ class WidgetA(OWBaseLearner):
self.assertIn(WidgetA.Inputs.data.name, inputs)
self.assertIn(WidgetA.Inputs.preprocessor.name, inputs)
self.assertIn("A", inputs)

def test_persists_learner_name_in_settings(self):
class WidgetA(OWBaseLearner):
name = "A"
LEARNER = KNNLearner

inputs = [("A", None, "set_data")]
outputs = [("A", None)]

w1 = self.create_widget(WidgetA)
self.assertEqual(w1.learner_name, "A")
w1.learner_name = "MyWidget"

settings = w1.settingsHandler.pack_data(w1)
w2 = self.create_widget(WidgetA, settings)
self.assertEqual(w2.learner_name, w1.learner_name)

0 comments on commit 984e7ea

Please sign in to comment.