Show More
@@ -1,42 +1,62 b'' | |||||
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 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 | ||||
|
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 | ||||
|
51 | w = ConsoleWidget() | |||
|
52 | cursor = w._get_prompt_cursor() | |||
|
53 | w._insert_html(cursor, '<a href="http://python.org">written in</a>') | |||
|
54 | self.assertEqual(w._anchor, None) | |||
|
55 | # should be over text | |||
|
56 | w.mouseMoveEvent(event(QtCore.QPoint(1,5))) | |||
|
57 | self.assertEqual(w._anchor, "http://python.org") | |||
|
58 | # should still be over text | |||
|
59 | w.mouseMoveEvent(event(QtCore.QPoint(5,5))) | |||
|
60 | # should be somewhere else | |||
|
61 | w.mouseMoveEvent(event(QtCore.QPoint(50,50))) | |||
|
62 | self.assertEqual(w._anchor, None) |
General Comments 0
You need to be logged in to leave comments.
Login now