##// END OF EJS Templates
Update ConsoleWidget anchor handling test code....
Diane Trout -
Show More
@@ -1,62 +1,73
1 1 # Standard library imports
2 2 import unittest
3 3
4 4 # System library imports
5 5 from IPython.external.qt import QtCore, QtGui
6 6
7 7 # Local imports
8 8 from IPython.frontend.qt.console.console_widget import ConsoleWidget
9 9
10 10
11 11 class TestConsoleWidget(unittest.TestCase):
12 12
13 13 @classmethod
14 14 def setUpClass(cls):
15 15 """ Create the application for the test case.
16 16 """
17 17 cls._app = QtGui.QApplication.instance()
18 18 if cls._app is None:
19 19 cls._app = QtGui.QApplication([])
20 20 cls._app.setQuitOnLastWindowClosed(False)
21 21
22 22 @classmethod
23 23 def tearDownClass(cls):
24 24 """ Exit the application.
25 25 """
26 26 QtGui.QApplication.quit()
27 27
28 28 def test_special_characters(self):
29 29 """ Are special characters displayed correctly?
30 30 """
31 31 w = ConsoleWidget()
32 32 cursor = w._get_prompt_cursor()
33 33
34 34 test_inputs = ['xyz\b\b=\n', 'foo\b\nbar\n', 'foo\b\nbar\r\n', 'abc\rxyz\b\b=']
35 35 expected_outputs = [u'x=z\u2029', u'foo\u2029bar\u2029', u'foo\u2029bar\u2029', 'x=z']
36 36 for i, text in enumerate(test_inputs):
37 37 w._insert_plain_text(cursor, text)
38 38 cursor.select(cursor.Document)
39 39 selection = cursor.selectedText()
40 40 self.assertEqual(expected_outputs[i], selection)
41 41 # clear all the text
42 42 cursor.insertText('')
43 43
44 44 def test_link_handling(self):
45 class event(object):
46 def __init__(self, pos):
47 self._pos = pos
48 def pos(self):
49 return self._pos
50
45 noKeys = QtCore.Qt
46 noButton = QtCore.Qt.MouseButton(0)
47 noButtons = QtCore.Qt.MouseButtons(0)
48 noModifiers = QtCore.Qt.KeyboardModifiers(0)
49 MouseMove = QtCore.QEvent.MouseMove
50 QMouseEvent = QtGui.QMouseEvent
51
51 52 w = ConsoleWidget()
52 53 cursor = w._get_prompt_cursor()
53 54 w._insert_html(cursor, '<a href="http://python.org">written in</a>')
55 obj = w._control
54 56 self.assertEqual(w._anchor, None)
57
55 58 # should be over text
56 w.mouseMoveEvent(event(QtCore.QPoint(1,5)))
59 overTextEvent = QMouseEvent(MouseMove, QtCore.QPoint(1,5),
60 noButton, noButtons, noModifiers)
61 w.eventFilter(obj, overTextEvent)
57 62 self.assertEqual(w._anchor, "http://python.org")
63
58 64 # should still be over text
59 w.mouseMoveEvent(event(QtCore.QPoint(5,5)))
65 stillOverTextEvent = QMouseEvent(MouseMove, QtCore.QPoint(1,5),
66 noButton, noButtons, noModifiers)
67 w.eventFilter(obj, stillOverTextEvent)
68
60 69 # should be somewhere else
61 w.mouseMoveEvent(event(QtCore.QPoint(50,50)))
70 elsewhereEvent = QMouseEvent(MouseMove, QtCore.QPoint(50,50),
71 noButton, noButtons, noModifiers)
72 w.eventFilter(obj, elsewhereEvent)
62 73 self.assertEqual(w._anchor, None)
General Comments 0
You need to be logged in to leave comments. Login now