annotate test/testdiagrameditor.py @ 390:b77f3290ac79

Added diagram editor tests
author Windel Bouwman
date Fri, 16 May 2014 10:12:16 +0200
parents
children bb4289c84907
rev   line source
390
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
1
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
2 import unittest
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
3 import os
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
4 import sys
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
5 import time
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
6
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
7 try:
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
8 otherpath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'python','other'))
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
9 sys.path.insert(0, otherpath)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
10 import diagrameditor
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
11
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
12 from PyQt5.QtWidgets import QApplication
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
13 from PyQt5.QtTest import QTest
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
14 from PyQt5.QtCore import Qt, QTimer
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
15 skip_it = False
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
16
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
17 # When creating an app per testcase, this fails horribly..
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
18 app = QApplication(sys.argv)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
19 except ImportError as e:
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
20 skip_it = True
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
21
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
22
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
23
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
24 class DiagramEditorTestCase(unittest.TestCase):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
25 def setUp(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
26 if skip_it:
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
27 self.skipTest('No qt5 or X server')
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
28 return
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
29 #print('Instance:', QApplication.instance())
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
30 self.main = diagrameditor.Main()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
31 self.main.show()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
32 QTest.qWaitForWindowActive(self.main)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
33
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
34 def tearDown(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
35 QTimer.singleShot(100, app.quit)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
36 app.exec_()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
37
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
38 def cmdNewModel(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
39 # Press ctrl+N:
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
40 QTest.keyClick(self.main, Qt.Key_N, Qt.ControlModifier)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
41
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
42 def dragItemIntoScene(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
43 library = self.main.findChild(diagrameditor.LibraryWidget, 'LibraryWidget')
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
44 editor = self.main.findChild(diagrameditor.EditorGraphicsView, 'Editor')
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
45 #ilibrary.
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
46 QTest.mousePress(library, Qt.LeftButton)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
47 print(editor, type(editor))
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
48 QTest.mouseMove(editor)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
49 QTest.mouseRelease(editor, Qt.LeftButton)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
50
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
51 def testScenario1(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
52 self.cmdNewModel()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
53 self.dragItemIntoScene()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
54
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
55 def testB(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
56 print('b')
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
57
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
58
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
59 if __name__ == '__main__':
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
60 unittest.main()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
61