def test_runconfig_workdir(main_window, qtbot, tmpdir): """Test runconfig workdir options.""" CONF.set('run', 'configurations', []) # ---- Load test file ---- test_file = osp.join(LOCATION, 'script.py') main_window.editor.load(test_file) code_editor = main_window.editor.get_focus_widget() # --- Use cwd for this file --- rc = RunConfiguration().get() rc['file_dir'] = False rc['cw_dir'] = True config_entry = (test_file, rc) CONF.set('run', 'configurations', [config_entry]) # --- Run test file --- shell = main_window.ipyconsole.get_current_shellwidget() qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) qtbot.keyClick(code_editor, Qt.Key_F5) qtbot.wait(500) # --- Assert we're in cwd after execution --- with qtbot.waitSignal(shell.executed): shell.execute('import os; current_dir = os.getcwd()') assert shell.get_value('current_dir') == get_home_dir() # --- Use fixed execution dir for test file --- temp_dir = str(tmpdir.mkdir("test_dir")) rc['file_dir'] = False rc['cw_dir'] = False rc['fixed_dir'] = True rc['dir'] = temp_dir config_entry = (test_file, rc) CONF.set('run', 'configurations', [config_entry]) # --- Run test file --- shell = main_window.ipyconsole.get_current_shellwidget() qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) qtbot.keyClick(code_editor, Qt.Key_F5) qtbot.wait(500) # --- Assert we're in fixed dir after execution --- with qtbot.waitSignal(shell.executed): shell.execute('import os; current_dir = os.getcwd()') assert shell.get_value('current_dir') == temp_dir # ---- Closing test file and resetting config ---- main_window.editor.close_file() CONF.set('run', 'configurations', [])
def test_dedicated_consoles(main_window, qtbot): """Test running code in dedicated consoles.""" # ---- Load test file ---- test_file = osp.join(LOCATION, 'script.py') main_window.editor.load(test_file) code_editor = main_window.editor.get_focus_widget() # --- Set run options for this file --- rc = RunConfiguration().get() # A dedicated console is used when these two options are False rc['current'] = rc['systerm'] = False config_entry = (test_file, rc) CONF.set('run', 'configurations', [config_entry]) # --- Run test file and assert that we get a dedicated console --- qtbot.keyClick(code_editor, Qt.Key_F5) qtbot.wait(500) shell = main_window.ipyconsole.get_current_shellwidget() control = shell._control qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) nsb = main_window.variableexplorer.get_focus_widget() assert len(main_window.ipyconsole.get_clients()) == 2 assert main_window.ipyconsole.filenames == ['', test_file] assert main_window.ipyconsole.tabwidget.tabText(1) == 'script.py/A' qtbot.wait(500) assert nsb.editor.model.rowCount() == 3 # --- Assert only runfile text is present and there's no banner text --- # See PR #5301 text = control.toPlainText() assert ('runfile' in text) and not ('Python' in text or 'IPython' in text) # --- Clean namespace after re-execution --- with qtbot.waitSignal(shell.executed): shell.execute('zz = -1') qtbot.keyClick(code_editor, Qt.Key_F5) qtbot.wait(500) assert not shell.is_defined('zz') # --- Assert runfile text is present after reruns --- assert 'runfile' in control.toPlainText() # ---- Closing test file and resetting config ---- main_window.editor.close_file() CONF.set('run', 'configurations', [])