1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
"""
Adapted from a code editor component created
for Enki editor as replacement for QScintilla.
Copyright (C) 2020 Andrei Kopats
Originally licensed under the terms of GNU Lesser General Public License
as published by the Free Software Foundation, version 2.1 of the license.
This is compatible with Orange3's GPL-3.0 license.
""" # pylint: disable=duplicate-code
import unittest
from AnyQt.QtCore import Qt
from AnyQt.QtGui import QKeySequence
from AnyQt.QtTest import QTest
from Orange.widgets.data.utils.pythoneditor.tests import base
from Orange.widgets.data.utils.pythoneditor.tests.base import EditorTest
class Test(EditorTest):
def test_overwrite_edit(self):
self.qpart.show()
self.qpart.text = 'abcd'
QTest.keyClicks(self.qpart, "stu")
self.assertEqual(self.qpart.text, 'stuabcd')
QTest.keyClick(self.qpart, Qt.Key_Insert)
QTest.keyClicks(self.qpart, "xy")
self.assertEqual(self.qpart.text, 'stuxycd')
QTest.keyClick(self.qpart, Qt.Key_Insert)
QTest.keyClicks(self.qpart, "z")
self.assertEqual(self.qpart.text, 'stuxyzcd')
def test_overwrite_backspace(self):
self.qpart.show()
self.qpart.text = 'abcd'
QTest.keyClick(self.qpart, Qt.Key_Insert)
for _ in range(3):
QTest.keyClick(self.qpart, Qt.Key_Right)
for _ in range(2):
QTest.keyClick(self.qpart, Qt.Key_Backspace)
self.assertEqual(self.qpart.text, 'a d')
def test_overwrite_undo(self):
self.qpart.show()
self.qpart.text = 'abcd'
QTest.keyClick(self.qpart, Qt.Key_Insert)
QTest.keyClick(self.qpart, Qt.Key_Right)
QTest.keyClick(self.qpart, Qt.Key_X)
QTest.keyClick(self.qpart, Qt.Key_X)
self.assertEqual(self.qpart.text, 'axxd')
# Ctrl+Z doesn't work. Wtf???
self.qpart.document().undo()
self.qpart.document().undo()
self.assertEqual(self.qpart.text, 'abcd')
def test_home1(self):
""" Test the operation of the home key. """
self.qpart.show()
self.qpart.text = ' xx'
# Move to the end of this string.
self.qpart.cursorPosition = (100, 100)
# Press home the first time. This should move to the beginning of the
# indent: line 0, column 4.
self.assertEqual(self.qpart.cursorPosition, (0, 4))
def column(self):
""" Return the column at which the cursor is located."""
return self.qpart.cursorPosition[1]
def test_home2(self):
""" Test the operation of the home key. """
self.qpart.show()
self.qpart.text = '\n\n ' + 'x'*10000
# Move to the end of this string.
self.qpart.cursorPosition = (100, 100)
# Press home. We should either move to the line beginning or indent. Use
# a QKeySequence because there's no home key on some Macs, so use
# whatever means home on that platform.
base.keySequenceClicks(self.qpart, QKeySequence.MoveToStartOfLine)
# There's no way I can find of determine what the line beginning should
# be. So, just press home again if we're not at the indent.
if self.column() != 4:
# Press home again to move to the beginning of the indent.
base.keySequenceClicks(self.qpart, QKeySequence.MoveToStartOfLine)
# We're at the indent.
self.assertEqual(self.column(), 4)
# Move to the beginning of the line.
base.keySequenceClicks(self.qpart, QKeySequence.MoveToStartOfLine)
self.assertEqual(self.column(), 0)
# Move back to the beginning of the indent.
base.keySequenceClicks(self.qpart, QKeySequence.MoveToStartOfLine)
self.assertEqual(self.column(), 4)
if __name__ == '__main__':
unittest.main()
|