test_kill_ring.py
85 lines
| 2.2 KiB
| text/x-python
|
PythonLexer
epatters
|
r3767 | # Standard library imports | ||
import unittest | ||||
# System library imports | ||||
from IPython.external.qt import QtCore, QtGui | ||||
# Local imports | ||||
Fernando Perez
|
r11024 | from IPython.qt.console.kill_ring import KillRing, QtKillRing | ||
epatters
|
r3767 | |||
class TestKillRing(unittest.TestCase): | ||||
@classmethod | ||||
def setUpClass(cls): | ||||
""" Create the application for the test case. | ||||
""" | ||||
Puneeth Chaganti
|
r6574 | cls._app = QtGui.QApplication.instance() | ||
if cls._app is None: | ||||
cls._app = QtGui.QApplication([]) | ||||
epatters
|
r3767 | cls._app.setQuitOnLastWindowClosed(False) | ||
@classmethod | ||||
def tearDownClass(cls): | ||||
""" Exit the application. | ||||
""" | ||||
QtGui.QApplication.quit() | ||||
def test_generic(self): | ||||
""" Does the generic kill ring work? | ||||
""" | ||||
ring = KillRing() | ||||
Bradley M. Froehle
|
r7876 | self.assertTrue(ring.yank() is None) | ||
self.assertTrue(ring.rotate() is None) | ||||
epatters
|
r3767 | |||
ring.kill('foo') | ||||
self.assertEqual(ring.yank(), 'foo') | ||||
Bradley M. Froehle
|
r7876 | self.assertTrue(ring.rotate() is None) | ||
epatters
|
r3767 | self.assertEqual(ring.yank(), 'foo') | ||
ring.kill('bar') | ||||
self.assertEqual(ring.yank(), 'bar') | ||||
self.assertEqual(ring.rotate(), 'foo') | ||||
ring.clear() | ||||
Bradley M. Froehle
|
r7876 | self.assertTrue(ring.yank() is None) | ||
self.assertTrue(ring.rotate() is None) | ||||
epatters
|
r3767 | |||
def test_qt_basic(self): | ||||
""" Does the Qt kill ring work? | ||||
""" | ||||
text_edit = QtGui.QPlainTextEdit() | ||||
ring = QtKillRing(text_edit) | ||||
ring.kill('foo') | ||||
ring.kill('bar') | ||||
ring.yank() | ||||
ring.rotate() | ||||
ring.yank() | ||||
self.assertEqual(text_edit.toPlainText(), 'foobar') | ||||
text_edit.clear() | ||||
ring.kill('baz') | ||||
ring.yank() | ||||
ring.rotate() | ||||
ring.rotate() | ||||
ring.rotate() | ||||
self.assertEqual(text_edit.toPlainText(), 'foo') | ||||
def test_qt_cursor(self): | ||||
""" Does the Qt kill ring maintain state with cursor movement? | ||||
""" | ||||
text_edit = QtGui.QPlainTextEdit() | ||||
ring = QtKillRing(text_edit) | ||||
ring.kill('foo') | ||||
ring.kill('bar') | ||||
ring.yank() | ||||
text_edit.moveCursor(QtGui.QTextCursor.Left) | ||||
ring.rotate() | ||||
self.assertEqual(text_edit.toPlainText(), 'bar') | ||||
if __name__ == '__main__': | ||||
import nose | ||||
nose.main() | ||||