Skip to content

Commit

Permalink
test_owpythonscript: Test in a single instance, also test in_proc
Browse files Browse the repository at this point in the history
  • Loading branch information
irgolic committed Jul 22, 2021
1 parent d9002af commit d3a56c2
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions Orange/widgets/data/tests/test_owpythonscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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()

0 comments on commit d3a56c2

Please sign in to comment.