def comms(kernel): """Get the comms""" commA = dummyComm() commB = dummyComm() commA.other = commB commB.other = commA frontend_comm = FrontendComm(kernel) kernel_comm = KernelComm() class DummyKernelClient(): comm_channel = None kernel_comm.kernel_client = DummyKernelClient() kernel_comm._register_comm(commA) # Bypass the target system as this is not what is being tested frontend_comm._comm_open(commB, {'content': { 'data': { 'pickle_protocol': 2 } }}) return (kernel_comm, frontend_comm)
def __init__(self, ipyclient, additional_options, interpreter_versions, is_external_kernel, is_spyder_kernel, handlers, *args, **kw): # To override the Qt widget used by RichJupyterWidget self.custom_control = ControlWidget self.custom_page_control = PageControlWidget self.custom_edit = True self.spyder_kernel_comm = KernelComm() self.spyder_kernel_comm.sig_exception_occurred.connect( self.sig_exception_occurred) super(ShellWidget, self).__init__(*args, **kw) self.ipyclient = ipyclient self.additional_options = additional_options self.interpreter_versions = interpreter_versions self.is_external_kernel = is_external_kernel self.is_spyder_kernel = is_spyder_kernel self._cwd = '' # Keyboard shortcuts # Registered here to use shellwidget as the parent self.shortcuts = self.create_shortcuts() # Set the color of the matched parentheses here since the qtconsole # uses a hard-coded value that is not modified when the color scheme is # set in the qtconsole constructor. See spyder-ide/spyder#4806. self.set_bracket_matcher_color_scheme(self.syntax_style) self.shutting_down = False self.kernel_manager = None self.kernel_client = None handlers.update({ 'pdb_state': self.set_pdb_state, 'pdb_execute': self.pdb_execute, 'show_pdb_output': self.show_pdb_output, 'get_pdb_settings': self.get_pdb_settings, 'set_debug_state': self.set_debug_state, 'update_syspath': self.update_syspath, 'do_where': self.do_where, 'pdb_input': self.pdb_input, 'request_interrupt_eventloop': self.request_interrupt_eventloop, }) for request_id in handlers: self.spyder_kernel_comm.register_call_handler( request_id, handlers[request_id]) self._execute_queue = [] self.executed.connect(self.pop_execute_queue) # Show a message in our installers to explain users how to use # modules that don't come with them. self.show_modules_message = is_pynsist() or running_in_mac_app() self.shutdown_lock = Lock()
def comms(kernel): """Get the comms""" commA = dummyComm() commB = dummyComm() commA.other = commB commB.other = commA frontend_comm = FrontendComm(kernel) kernel_comm = KernelComm() def dummy_set_comm_port(port): """There is no port to set.""" pass kernel_comm.register_call_handler('_set_comm_port', dummy_set_comm_port) class DummyKernelClient(): comm_channel = 0 shell_channel = 0 kernel_comm.kernel_client = DummyKernelClient() kernel_comm._register_comm(commA) # Bypass the target system as this is not what is being tested frontend_comm._comm_open(commB, {'content': {'data': {'pickle_protocol': 2}}}) return (kernel_comm, frontend_comm)
def __init__(self, ipyclient, additional_options, interpreter_versions, external_kernel, *args, **kw): # To override the Qt widget used by RichJupyterWidget self.custom_control = ControlWidget self.custom_page_control = PageControlWidget self.custom_edit = True self.spyder_kernel_comm = KernelComm() self.spyder_kernel_comm.sig_exception_occurred.connect( self.sig_exception_occurred) super(ShellWidget, self).__init__(*args, **kw) self.ipyclient = ipyclient self.additional_options = additional_options self.interpreter_versions = interpreter_versions self.external_kernel = external_kernel self._cwd = '' # Keyboard shortcuts self.shortcuts = self.create_shortcuts() # Set the color of the matched parentheses here since the qtconsole # uses a hard-coded value that is not modified when the color scheme is # set in the qtconsole constructor. See spyder-ide/spyder#4806. self.set_bracket_matcher_color_scheme(self.syntax_style) self.shutdown_called = False self.kernel_manager = None self.kernel_client = None self.shutdown_thread = None handlers = { 'pdb_state': self.set_pdb_state, 'pdb_execute': self.pdb_execute, 'get_pdb_settings': self.get_pdb_settings, 'run_cell': self.handle_run_cell, 'cell_count': self.handle_cell_count, 'current_filename': self.handle_current_filename, 'get_file_code': self.handle_get_file_code, 'set_debug_state': self.set_debug_state, 'update_syspath': self.update_syspath, 'do_where': self.do_where, 'pdb_input': self.pdb_input, 'request_interrupt_eventloop': self.request_interrupt_eventloop, } for request_id in handlers: self.spyder_kernel_comm.register_call_handler( request_id, handlers[request_id]) self._execute_queue = [] self.executed.connect(self.pop_execute_queue) # Internal kernel are always spyder kernels self._is_spyder_kernel = not external_kernel
def __init__(self, ipyclient, additional_options, interpreter_versions, external_kernel, *args, **kw): # To override the Qt widget used by RichJupyterWidget self.custom_control = ControlWidget self.custom_page_control = PageControlWidget self.custom_edit = True super(ShellWidget, self).__init__(*args, **kw) self.ipyclient = ipyclient self.additional_options = additional_options self.interpreter_versions = interpreter_versions self.external_kernel = external_kernel self._cwd = '' # Keyboard shortcuts self.shortcuts = self.create_shortcuts() # Set the color of the matched parentheses here since the qtconsole # uses a hard-coded value that is not modified when the color scheme is # set in the qtconsole constructor. See spyder-ide/spyder#4806. self.set_bracket_matcher_color_scheme(self.syntax_style) self.spyder_kernel_comm = KernelComm() self.spyder_kernel_comm.sig_exception_occurred.connect( self.sig_exception_occurred) self.kernel_manager = None self.kernel_client = None handlers = { 'pdb_state': self.set_pdb_state, 'pdb_continue': self.pdb_continue, 'get_breakpoints': self.get_spyder_breakpoints, 'save_files': self.handle_save_files, 'run_cell': self.handle_run_cell, 'cell_count': self.handle_cell_count, 'current_filename': self.handle_current_filename, } for request_id in handlers: self.spyder_kernel_comm.register_call_handler( request_id, handlers[request_id]) self.spyder_kernel_comm.sig_debugging.connect(self._debugging_hook)
def test_runcell(tmpdir, debug): """Test the runcell command.""" # Command to start the kernel cmd = "from spyder_kernels.console import start; start.main()" with setup_kernel(cmd) as client: # Write code with a cell to a file code = u"result = 10; fname = __file__" p = tmpdir.join("cell-test.py") p.write(code) class Signal(): def connect(self, function): self.function = function # Fake Qt signal iopub_recieved = Signal() client.iopub_channel.message_received = iopub_recieved # Open comm comm_manager = CommManager(client) kernel_comm = KernelComm() kernel_comm._register_comm( comm_manager.new_comm('spyder_api', data={'pickle_protocol': 2})) def process_msg(call_name): msg = {'msg_type': None} while (msg['msg_type'] != 'comm_msg' or msg['content']['data']['content']['call_name'] != call_name): msg = client.get_iopub_msg(block=True, timeout=TIMEOUT) iopub_recieved.function(msg) def runcell(cellname, filename): return code def set_debug_state(state): set_debug_state.state = state set_debug_state.state = None kernel_comm.register_call_handler('run_cell', runcell) kernel_comm.register_call_handler('get_breakpoints', lambda: {}) kernel_comm.register_call_handler('pdb_state', lambda state: None) kernel_comm.register_call_handler('set_debug_state', set_debug_state) if debug: function = 'debugcell' else: function = 'runcell' # Execute runcell client.execute(function + u"('', r'{}')".format(to_text_string(p))) # Get the runcell call process_msg('run_cell') if debug: # Continue process_msg('set_debug_state') process_msg('get_breakpoints') assert set_debug_state.state time.sleep(.5) client.input('c') process_msg('set_debug_state') assert not set_debug_state.state msg = client.get_shell_msg(block=True, timeout=TIMEOUT) assert msg['msg_type'] == 'execute_reply' # Verify that the `result` variable is defined client.inspect('result') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] assert content['found'] # Verify that the `fname` variable is `cell-test.py` client.inspect('fname') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] assert "cell-test.py" in content['data']['text/plain'] # Verify that the `__file__` variable is undefined client.inspect('__file__') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] assert not content['found']