~ubuntu-branches/ubuntu/natty/pyside/natty

« back to all changes in this revision

Viewing changes to tests/QtGui/qvalidator_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2011-02-18 18:01:00 UTC
  • mfrom: (1.1.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110218180100-y8aqmcdbcbd6gpeh
Tags: upstream-1.0.0~rc1
ImportĀ upstreamĀ versionĀ 1.0.0~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from PySide.QtCore import *
 
2
from PySide.QtGui import *
 
3
 
 
4
import unittest
 
5
from helper import UsesQApplication
 
6
 
 
7
class MyValidator1(QValidator):
 
8
    def fixUp(self, input):
 
9
        return "fixed"
 
10
 
 
11
    def validate(self, input, pos):
 
12
        return (QValidator.Acceptable, "fixed", 1)
 
13
 
 
14
class MyValidator2(QValidator):
 
15
    def fixUp(self, input):
 
16
        return "fixed"
 
17
 
 
18
    def validate(self, input, pos):
 
19
        return (QValidator.Acceptable, "fixed")
 
20
 
 
21
class MyValidator3(QValidator):
 
22
    def fixUp(self, input):
 
23
        return "fixed"
 
24
 
 
25
    def validate(self, input, pos):
 
26
        return (QValidator.Acceptable,)
 
27
 
 
28
class MyValidator4(QValidator):
 
29
    def fixUp(self, input):
 
30
        return "fixed"
 
31
 
 
32
    def validate(self, input, pos):
 
33
        return QValidator.Acceptable
 
34
 
 
35
class QValidatorTest(UsesQApplication):
 
36
    def testValidator1(self):
 
37
        line = QLineEdit()
 
38
        line.setValidator(MyValidator1())
 
39
        line.show()
 
40
        line.setText("foo")
 
41
 
 
42
        QTimer.singleShot(0, line.close)
 
43
        self.app.exec_()
 
44
 
 
45
        self.assertEqual(line.text(), "fixed")
 
46
        self.assertEqual(line.cursorPosition(), 1)
 
47
 
 
48
    def testValidator2(self):
 
49
        line = QLineEdit()
 
50
        line.setValidator(MyValidator2())
 
51
        line.show()
 
52
        line.setText("foo")
 
53
 
 
54
        QTimer.singleShot(0, line.close)
 
55
        self.app.exec_()
 
56
 
 
57
        self.assertEqual(line.text(), "fixed")
 
58
        self.assertEqual(line.cursorPosition(), 3)
 
59
 
 
60
    def testValidator3(self):
 
61
        line = QLineEdit()
 
62
        line.setValidator(MyValidator3())
 
63
        line.show()
 
64
        line.setText("foo")
 
65
 
 
66
        QTimer.singleShot(0, line.close)
 
67
        self.app.exec_()
 
68
 
 
69
        self.assertEqual(line.text(), "foo")
 
70
        self.assertEqual(line.cursorPosition(), 3)
 
71
 
 
72
    def testValidator4(self):
 
73
        line = QLineEdit()
 
74
        line.setValidator(MyValidator4())
 
75
        line.show()
 
76
        line.setText("foo")
 
77
 
 
78
        QTimer.singleShot(0, line.close)
 
79
        self.app.exec_()
 
80
 
 
81
        self.assertEqual(line.text(), "foo")
 
82
        self.assertEqual(line.cursorPosition(), 3)
 
83
 
 
84
if __name__ == '__main__':
 
85
    unittest.main()