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