1
from PySide.QtCore import *
2
from PySide.QtGui import *
5
from helper import UsesQApplication
7
class MyValidator1(QValidator):
8
def fixUp(self, input):
11
def validate(self, input, pos):
12
return (QValidator.Acceptable, "fixed", 1)
14
class MyValidator2(QValidator):
15
def fixUp(self, input):
18
def validate(self, input, pos):
19
return (QValidator.Acceptable, "fixed")
21
class MyValidator3(QValidator):
22
def fixUp(self, input):
25
def validate(self, input, pos):
26
return (QValidator.Acceptable,)
28
class MyValidator4(QValidator):
29
def fixUp(self, input):
32
def validate(self, input, pos):
33
return QValidator.Acceptable
35
class QValidatorTest(UsesQApplication):
36
def testValidator1(self):
38
line.setValidator(MyValidator1())
42
QTimer.singleShot(0, line.close)
45
self.assertEqual(line.text(), "fixed")
46
self.assertEqual(line.cursorPosition(), 1)
48
def testValidator2(self):
50
line.setValidator(MyValidator2())
54
QTimer.singleShot(0, line.close)
57
self.assertEqual(line.text(), "fixed")
58
self.assertEqual(line.cursorPosition(), 3)
60
def testValidator3(self):
62
line.setValidator(MyValidator3())
66
QTimer.singleShot(0, line.close)
69
self.assertEqual(line.text(), "foo")
70
self.assertEqual(line.cursorPosition(), 3)
72
def testValidator4(self):
74
line.setValidator(MyValidator4())
78
QTimer.singleShot(0, line.close)
81
self.assertEqual(line.text(), "foo")
82
self.assertEqual(line.cursorPosition(), 3)
84
if __name__ == '__main__':