test_console_widget.py
80 lines
| 2.8 KiB
| text/x-python
|
PythonLexer
Puneeth Chaganti
|
r6437 | # Standard library imports | ||
import unittest | ||||
# System library imports | ||||
Diane Trout
|
r8533 | from IPython.external.qt import QtCore, QtGui | ||
Puneeth Chaganti
|
r6437 | |||
# Local imports | ||||
Fernando Perez
|
r11024 | from IPython.qt.console.console_widget import ConsoleWidget | ||
Puneeth Chaganti
|
r6437 | |||
class TestConsoleWidget(unittest.TestCase): | ||||
@classmethod | ||||
def setUpClass(cls): | ||||
""" Create the application for the test case. | ||||
""" | ||||
Puneeth Chaganti
|
r6574 | cls._app = QtGui.QApplication.instance() | ||
if cls._app is None: | ||||
cls._app = QtGui.QApplication([]) | ||||
Puneeth Chaganti
|
r6437 | cls._app.setQuitOnLastWindowClosed(False) | ||
@classmethod | ||||
def tearDownClass(cls): | ||||
""" Exit the application. | ||||
""" | ||||
QtGui.QApplication.quit() | ||||
def test_special_characters(self): | ||||
""" Are special characters displayed correctly? | ||||
""" | ||||
w = ConsoleWidget() | ||||
cursor = w._get_prompt_cursor() | ||||
test_inputs = ['xyz\b\b=\n', 'foo\b\nbar\n', 'foo\b\nbar\r\n', 'abc\rxyz\b\b='] | ||||
expected_outputs = [u'x=z\u2029', u'foo\u2029bar\u2029', u'foo\u2029bar\u2029', 'x=z'] | ||||
for i, text in enumerate(test_inputs): | ||||
w._insert_plain_text(cursor, text) | ||||
cursor.select(cursor.Document) | ||||
selection = cursor.selectedText() | ||||
Bradley M. Froehle
|
r7874 | self.assertEqual(expected_outputs[i], selection) | ||
Puneeth Chaganti
|
r6437 | # clear all the text | ||
cursor.insertText('') | ||||
Diane Trout
|
r8533 | |||
def test_link_handling(self): | ||||
Diane Trout
|
r8540 | noKeys = QtCore.Qt | ||
noButton = QtCore.Qt.MouseButton(0) | ||||
noButtons = QtCore.Qt.MouseButtons(0) | ||||
noModifiers = QtCore.Qt.KeyboardModifiers(0) | ||||
MouseMove = QtCore.QEvent.MouseMove | ||||
QMouseEvent = QtGui.QMouseEvent | ||||
Diane Trout
|
r8533 | w = ConsoleWidget() | ||
cursor = w._get_prompt_cursor() | ||||
w._insert_html(cursor, '<a href="http://python.org">written in</a>') | ||||
Diane Trout
|
r8540 | obj = w._control | ||
Diane Trout
|
r8588 | tip = QtGui.QToolTip | ||
self.assertEqual(tip.text(), u'') | ||||
Diane Trout
|
r8540 | |||
Diane Trout
|
r8588 | # should be somewhere else | ||
elsewhereEvent = QMouseEvent(MouseMove, QtCore.QPoint(50,50), | ||||
noButton, noButtons, noModifiers) | ||||
w.eventFilter(obj, elsewhereEvent) | ||||
self.assertEqual(tip.isVisible(), False) | ||||
self.assertEqual(tip.text(), u'') | ||||
#self.assertEqual(tip.text(), u'') | ||||
Diane Trout
|
r8533 | # should be over text | ||
Diane Trout
|
r8540 | overTextEvent = QMouseEvent(MouseMove, QtCore.QPoint(1,5), | ||
noButton, noButtons, noModifiers) | ||||
w.eventFilter(obj, overTextEvent) | ||||
Diane Trout
|
r8588 | self.assertEqual(tip.isVisible(), True) | ||
self.assertEqual(tip.text(), "http://python.org") | ||||
Diane Trout
|
r8540 | |||
Diane Trout
|
r8533 | # should still be over text | ||
Diane Trout
|
r8540 | stillOverTextEvent = QMouseEvent(MouseMove, QtCore.QPoint(1,5), | ||
noButton, noButtons, noModifiers) | ||||
w.eventFilter(obj, stillOverTextEvent) | ||||
Diane Trout
|
r8588 | self.assertEqual(tip.isVisible(), True) | ||
self.assertEqual(tip.text(), "http://python.org") | ||||
Diane Trout
|
r8540 | |||