def test_debug(self): """ Make sure the cursor works while debugging It might not because the console is "_executing" """ # Kernel client to test the responses of is_complete class TestIPyKernelClient(object): def is_complete(self, source): tm = TransformerManager() check_complete = tm.check_complete(source) responses.append(check_complete) # Initialize widget responses = [] w = ConsoleWidget() w._append_plain_text('Header\n') w._prompt = 'prompt>' w._show_prompt() w.kernel_client = TestIPyKernelClient() control = w._control # Execute incomplete statement inside a block code = "%debug range(1)\n" w._set_input_buffer(code) w.execute(interactive=True) # We should be able to move the cursor while debugging w._set_input_buffer("abd") QTest.keyClick(control, QtCore.Qt.Key_Left) QTest.keyClick(control, 'c') self.assertEqual(w._get_input_buffer(),"abcd")
def test_complete_python(self): """Test that is_complete is working correctly for Python.""" # Kernel client to test the responses of is_complete class TestIPyKernelClient(object): def is_complete(self, source): tm = TransformerManager() check_complete = tm.check_complete(source) responses.append(check_complete) # Initialize widget responses = [] w = ConsoleWidget() w._append_plain_text('Header\n') w._prompt = 'prompt>' w._show_prompt() w.kernel_client = TestIPyKernelClient() # Execute incomplete statement inside a block code = '\n'.join(["if True:", " a = 1"]) w._set_input_buffer(code) w.execute(interactive=True) assert responses == [('incomplete', 4)] # Execute complete statement inside a block responses = [] code = '\n'.join(["if True:", " a = 1\n\n"]) w._set_input_buffer(code) w.execute(interactive=True) assert responses == [('complete', None)]
def test_debug(self): """ Make sure the cursor works while debugging It might not because the console is "_executing" """ # Kernel client to test the responses of is_complete class TestIPyKernelClient(object): def is_complete(self, source): tm = TransformerManager() check_complete = tm.check_complete(source) responses.append(check_complete) # Initialize widget responses = [] w = ConsoleWidget() w._append_plain_text('Header\n') w._prompt = 'prompt>' w._show_prompt() w.kernel_client = TestIPyKernelClient() control = w._control # Execute incomplete statement inside a block code = "%debug range(1)\n" w._set_input_buffer(code) w.execute(interactive=True) # We should be able to move the cursor while debugging w._set_input_buffer("abd") QTest.keyClick(control, QtCore.Qt.Key_Left) QTest.keyClick(control, 'c') self.assertEqual(w._get_input_buffer(), "abcd")
def test_complete(self): class TestKernelClient(object): def is_complete(self, source): calls.append(source) return msg_id w = ConsoleWidget() cursor = w._get_prompt_cursor() w._execute = lambda *args: calls.append(args) w.kernel_client = TestKernelClient() msg_id = object() calls = [] # test incomplete statement (no _execute called, but indent added) w.execute("thing", interactive=True) self.assertEqual(calls, ["thing"]) calls = [] w._handle_is_complete_reply( dict(parent_header=dict(msg_id=msg_id), content=dict(status="incomplete", indent="!!!"))) self.assert_text_equal(cursor, u"thing\u2029> !!!") self.assertEqual(calls, []) # test complete statement (_execute called) msg_id = object() w.execute("else", interactive=True) self.assertEqual(calls, ["else"]) calls = [] w._handle_is_complete_reply( dict(parent_header=dict(msg_id=msg_id), content=dict(status="complete", indent="###"))) self.assertEqual(calls, [("else", False)]) calls = [] self.assert_text_equal(cursor, u"thing\u2029> !!!else\u2029") # test missing answer from is_complete msg_id = object() w.execute("done", interactive=True) self.assertEqual(calls, ["done"]) calls = [] self.assert_text_equal(cursor, u"thing\u2029> !!!else\u2029") event = QtCore.QEvent(QtCore.QEvent.User) w.eventFilter(w, event) self.assert_text_equal(cursor, u"thing\u2029> !!!else\u2029\u2029> ") # assert that late answer isn't destroying anything w._handle_is_complete_reply( dict(parent_header=dict(msg_id=msg_id), content=dict(status="complete", indent="###"))) self.assertEqual(calls, [])