Show More
@@ -1,40 +1,42 b'' | |||
|
1 | 1 | # Standard library imports |
|
2 | 2 | import unittest |
|
3 | 3 | |
|
4 | 4 | # System library imports |
|
5 | 5 | from IPython.external.qt import 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 |
cls._app = QtGui.QApplication( |
|
|
17 | cls._app = QtGui.QApplication.instance() | |
|
18 | if cls._app is None: | |
|
19 | cls._app = QtGui.QApplication([]) | |
|
18 | 20 | cls._app.setQuitOnLastWindowClosed(False) |
|
19 | 21 | |
|
20 | 22 | @classmethod |
|
21 | 23 | def tearDownClass(cls): |
|
22 | 24 | """ Exit the application. |
|
23 | 25 | """ |
|
24 | 26 | QtGui.QApplication.quit() |
|
25 | 27 | |
|
26 | 28 | def test_special_characters(self): |
|
27 | 29 | """ Are special characters displayed correctly? |
|
28 | 30 | """ |
|
29 | 31 | w = ConsoleWidget() |
|
30 | 32 | cursor = w._get_prompt_cursor() |
|
31 | 33 | |
|
32 | 34 | test_inputs = ['xyz\b\b=\n', 'foo\b\nbar\n', 'foo\b\nbar\r\n', 'abc\rxyz\b\b='] |
|
33 | 35 | expected_outputs = [u'x=z\u2029', u'foo\u2029bar\u2029', u'foo\u2029bar\u2029', 'x=z'] |
|
34 | 36 | for i, text in enumerate(test_inputs): |
|
35 | 37 | w._insert_plain_text(cursor, text) |
|
36 | 38 | cursor.select(cursor.Document) |
|
37 | 39 | selection = cursor.selectedText() |
|
38 | 40 | self.assertEquals(expected_outputs[i], selection) |
|
39 | 41 | # clear all the text |
|
40 | 42 | cursor.insertText('') |
@@ -1,83 +1,85 b'' | |||
|
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.kill_ring import KillRing, QtKillRing |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | class TestKillRing(unittest.TestCase): |
|
12 | 12 | |
|
13 | 13 | @classmethod |
|
14 | 14 | def setUpClass(cls): |
|
15 | 15 | """ Create the application for the test case. |
|
16 | 16 | """ |
|
17 |
cls._app = QtGui.QApplication( |
|
|
17 | cls._app = QtGui.QApplication.instance() | |
|
18 | if cls._app is None: | |
|
19 | cls._app = QtGui.QApplication([]) | |
|
18 | 20 | cls._app.setQuitOnLastWindowClosed(False) |
|
19 | 21 | |
|
20 | 22 | @classmethod |
|
21 | 23 | def tearDownClass(cls): |
|
22 | 24 | """ Exit the application. |
|
23 | 25 | """ |
|
24 | 26 | QtGui.QApplication.quit() |
|
25 | 27 | |
|
26 | 28 | def test_generic(self): |
|
27 | 29 | """ Does the generic kill ring work? |
|
28 | 30 | """ |
|
29 | 31 | ring = KillRing() |
|
30 | 32 | self.assert_(ring.yank() is None) |
|
31 | 33 | self.assert_(ring.rotate() is None) |
|
32 | 34 | |
|
33 | 35 | ring.kill('foo') |
|
34 | 36 | self.assertEqual(ring.yank(), 'foo') |
|
35 | 37 | self.assert_(ring.rotate() is None) |
|
36 | 38 | self.assertEqual(ring.yank(), 'foo') |
|
37 | 39 | |
|
38 | 40 | ring.kill('bar') |
|
39 | 41 | self.assertEqual(ring.yank(), 'bar') |
|
40 | 42 | self.assertEqual(ring.rotate(), 'foo') |
|
41 | 43 | |
|
42 | 44 | ring.clear() |
|
43 | 45 | self.assert_(ring.yank() is None) |
|
44 | 46 | self.assert_(ring.rotate() is None) |
|
45 | 47 | |
|
46 | 48 | def test_qt_basic(self): |
|
47 | 49 | """ Does the Qt kill ring work? |
|
48 | 50 | """ |
|
49 | 51 | text_edit = QtGui.QPlainTextEdit() |
|
50 | 52 | ring = QtKillRing(text_edit) |
|
51 | 53 | |
|
52 | 54 | ring.kill('foo') |
|
53 | 55 | ring.kill('bar') |
|
54 | 56 | ring.yank() |
|
55 | 57 | ring.rotate() |
|
56 | 58 | ring.yank() |
|
57 | 59 | self.assertEqual(text_edit.toPlainText(), 'foobar') |
|
58 | 60 | |
|
59 | 61 | text_edit.clear() |
|
60 | 62 | ring.kill('baz') |
|
61 | 63 | ring.yank() |
|
62 | 64 | ring.rotate() |
|
63 | 65 | ring.rotate() |
|
64 | 66 | ring.rotate() |
|
65 | 67 | self.assertEqual(text_edit.toPlainText(), 'foo') |
|
66 | 68 | |
|
67 | 69 | def test_qt_cursor(self): |
|
68 | 70 | """ Does the Qt kill ring maintain state with cursor movement? |
|
69 | 71 | """ |
|
70 | 72 | text_edit = QtGui.QPlainTextEdit() |
|
71 | 73 | ring = QtKillRing(text_edit) |
|
72 | 74 | |
|
73 | 75 | ring.kill('foo') |
|
74 | 76 | ring.kill('bar') |
|
75 | 77 | ring.yank() |
|
76 | 78 | text_edit.moveCursor(QtGui.QTextCursor.Left) |
|
77 | 79 | ring.rotate() |
|
78 | 80 | self.assertEqual(text_edit.toPlainText(), 'bar') |
|
79 | 81 | |
|
80 | 82 | |
|
81 | 83 | if __name__ == '__main__': |
|
82 | 84 | import nose |
|
83 | 85 | nose.main() |
General Comments 0
You need to be logged in to leave comments.
Login now