diff --git a/Orange/widgets/data/tests/test_owpythonscript.py b/Orange/widgets/data/tests/test_owpythonscript.py index 1702ddb3bf0..bf23d383e92 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,21 @@ 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): - 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() + iris = Table("iris") + learner = LogisticRegressionLearner() + model = learner(iris) + default_settings = None + python_widget = None - def tearDown(self): - super().tearDown() - self.widget.onDeleteWidget() + def setUp(self): + if type(self).python_widget is None: + type(self).python_widget = self.create_widget( + OWPythonScript, stored_settings=self.default_settings) + self.widget = self.python_widget + self.wait_execute_script('clear') def wait_execute_script(self, script=None): """ @@ -237,6 +238,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 +248,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 +362,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()