From 984e7ea56d67f23fbc5a358b037eebd9e163d2ab Mon Sep 17 00:00:00 2001 From: astaric Date: Thu, 21 Sep 2017 12:36:17 +0200 Subject: [PATCH] OWBaseLearner: Save learner name in workflow --- Orange/widgets/utils/owlearnerwidget.py | 4 +++- .../widgets/utils/tests/test_owlearnerwidget.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Orange/widgets/utils/owlearnerwidget.py b/Orange/widgets/utils/owlearnerwidget.py index 488c6ba06e1..b887e05c381 100644 --- a/Orange/widgets/utils/owlearnerwidget.py +++ b/Orange/widgets/utils/owlearnerwidget.py @@ -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) @@ -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 diff --git a/Orange/widgets/utils/tests/test_owlearnerwidget.py b/Orange/widgets/utils/tests/test_owlearnerwidget.py index 1f97fad66b5..aff18934e7f 100644 --- a/Orange/widgets/utils/tests/test_owlearnerwidget.py +++ b/Orange/widgets/utils/tests/test_owlearnerwidget.py @@ -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)