Unverified Commit 88389485 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony Committed by GitHub
Browse files

Merge pull request #28796 from mantidproject/27185_clear_variables_in_scripts_in_workbench

parents 6f242c0b 02d0e781
......@@ -49,8 +49,9 @@ Improvements
- Slow running algorithms will now display an estimated time to completion in their progress bars.
- The x-axis tick labels on colorfill plots are now horizontal.
- Improved the usability of the fit function and peak selection pop-up menus by allowing the user to immediately search for the desired function and activate autocompletion by pressing "enter" if there is just a single possible function.
- The figure options menu now has a help button which opens the documentation for the menu.
- Variables assigned in python scripts are now cleared when a script is run in its entirety.
......@@ -325,6 +325,7 @@ class PythonFileInterpreterPresenter(QObject):
line_from, _, _, _ = editor.getSelection()
# run everything in the file
code_str = editor.text()
line_from = 0
return code_str, line_from
......@@ -56,6 +56,28 @@ class PythonFileInterpreterTest(unittest.TestCase):
self.assertEqual(w.clear_key_binding(key_combo), None,
def test_variables_reset(self):
w = PythonFileInterpreter(content='x=\'this is a string\'\r\nprint(x)')
self.assertTrue('x' in w._presenter.model._globals_ns.keys())
w._presenter.is_executing = False
w._presenter.view.editor.hasSelectedText = mock.MagicMock()
w._presenter.view.editor.hasSelectedText.return_value = True
w._presenter.view.editor.selectedText = mock.MagicMock()
w._presenter.view.editor.selectedText.return_value = 'print(x)'
w._presenter.view.editor.getSelection = mock.MagicMock()
w._presenter.view.editor.getSelection.return_value = [0, 0, 0, 0]
self.assertTrue('x' in w._presenter.model._globals_ns.keys())
w._presenter.view.editor.text = mock.MagicMock()
w._presenter.view.editor.text.return_value = 'print(x)'
w._presenter.is_executing = False
w._presenter.view.editor.hasSelectedText.return_value = False
self.assertFalse('x' in w._presenter.model._globals_ns.keys())
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment