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