From d3a56c2787dd554841c87f4c225a3156f936eeda Mon Sep 17 00:00:00 2001 From: Rafael Irgolic Date: Thu, 22 Jul 2021 19:48:55 +0100 Subject: [PATCH] test_owpythonscript: Test in a single instance, also test in_proc --- .../widgets/data/tests/test_owpythonscript.py | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/Orange/widgets/data/tests/test_owpythonscript.py b/Orange/widgets/data/tests/test_owpythonscript.py index 1702ddb3bf0..18595120b1a 100644 --- a/Orange/widgets/data/tests/test_owpythonscript.py +++ b/Orange/widgets/data/tests/test_owpythonscript.py @@ -8,6 +8,7 @@ from Orange.classification import LogisticRegressionLearner from Orange.tests import named_file from Orange.widgets.data.owpythonscript import OWPythonScript, read_file_content, Script +from Orange.widgets.tests.base import WidgetTest from Orange.widgets.widget import OWWidget # import tests for python editor @@ -19,21 +20,27 @@ from Orange.widgets.data.utils.pythoneditor.tests.test_indenter.test_python import * from Orange.widgets.data.utils.pythoneditor.tests.test_rectangular_selection import * from Orange.widgets.data.utils.pythoneditor.tests.test_vim import * -from qtconsole.client import QtKernelClient class TestOWPythonScript(WidgetTest): + iris = Table("iris") + learner = LogisticRegressionLearner() + model = learner(iris) + default_settings = None + python_widget = None + def setUp(self): - super().setUp() - self.widget = self.create_widget(OWPythonScript) - self.iris = Table("iris") - self.learner = LogisticRegressionLearner() - self.model = self.learner(self.iris) - # self.widget.show() + if type(self).python_widget is None: + type(self).python_widget = self.create_widget( + OWPythonScript, stored_settings=self.default_settings) + type(self).python_widget.show() + self.widget = self.python_widget + self.wait_execute_script('clear') - def tearDown(self): - super().tearDown() - self.widget.onDeleteWidget() + @classmethod + def tearDownClass(cls): + cls.python_widget.onDeleteWidget() + cls.python_widget = None def wait_execute_script(self, script=None): """ @@ -237,6 +244,7 @@ def test_store_new_script(self): self.assertEqual("42", script) def test_restore_from_library(self): + self.widget.restoreSaved() before = self.widget.editor.text self.widget.editor.text = "42" self.widget.restoreSaved() @@ -246,12 +254,14 @@ def test_restore_from_library(self): def test_store_current_script(self): self.widget.editor.text = "42" settings = self.widget.settingsHandler.pack_data(self.widget) - self.widget = self.create_widget(OWPythonScript) - script = self.widget.editor.text + widget = self.create_widget(OWPythonScript) + script = widget.editor.text self.assertNotEqual("42", script) - self.widget = self.create_widget(OWPythonScript, stored_settings=settings) - script = self.widget.editor.text + widget2 = self.create_widget(OWPythonScript, stored_settings=settings) + script = widget2.editor.text self.assertEqual("42", script) + widget.onDeleteWidget() + widget2.onDeleteWidget() def test_read_file_content(self): with named_file("Content", suffix=".42") as fn: @@ -358,5 +368,10 @@ def test_unreferencible(self): self.assertEqual(self.get_output("Object"), ('a', 14)) +class TestInProcessOWPythonScript(TestOWPythonScript): + default_settings = {'useInProcessKernel': True} + python_widget = None + + if __name__ == '__main__': unittest.main()