annotate test/testdiagrameditor.py @ 410:6aa9743ed362 tip

Reflect change in c3 public modifier
author Windel Bouwman
date Mon, 23 Feb 2015 21:06:04 +0100
parents c0d9837acde8
children
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
392
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
12 from PyQt5.QtWidgets import QApplication, QGraphicsItem
390
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
13 from PyQt5.QtTest import QTest
392
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
14 from PyQt5.QtCore import Qt, QTimer, QMimeData, QPointF
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
15 from PyQt5.QtGui import QDropEvent
390
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
16 skip_it = False
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
17
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
18 # When creating an app per testcase, this fails horribly..
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
19 app = QApplication(sys.argv)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
20 except ImportError as e:
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
21 skip_it = True
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
22
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
23
398
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 392
diff changeset
24 if 'LCFOSGUITESTS' not in os.environ:
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 392
diff changeset
25 skip_it = True
390
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
26
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
27 class DiagramEditorTestCase(unittest.TestCase):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
28 def setUp(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
29 if skip_it:
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
30 self.skipTest('No qt5 or X server')
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
31 return
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
32 #print('Instance:', QApplication.instance())
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
33 self.main = diagrameditor.Main()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
34 self.main.show()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
35 QTest.qWaitForWindowActive(self.main)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
36
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
37 def tearDown(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
38 QTimer.singleShot(100, app.quit)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
39 app.exec_()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
40
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
41 def cmdNewModel(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
42 # Press ctrl+N:
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
43 QTest.keyClick(self.main, Qt.Key_N, Qt.ControlModifier)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
44
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
45 def dragItemIntoScene(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
46 library = self.main.findChild(diagrameditor.LibraryWidget, 'LibraryWidget')
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
47 editor = self.main.findChild(diagrameditor.EditorGraphicsView, 'Editor')
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
48 #ilibrary.
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
49 QTest.mousePress(library, Qt.LeftButton)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
50 print(editor, type(editor))
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
51 QTest.mouseMove(editor)
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
52 QTest.mouseRelease(editor, Qt.LeftButton)
392
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
53 mimedata = QMimeData()
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
54 mimedata.setData('component/name', 'Block:blk'.encode('ascii'))
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
55 de = QDropEvent(QPointF(10, 10), Qt.CopyAction, mimedata,
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
56 Qt.LeftButton,
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
57 Qt.NoModifier)
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
58 editor.dropEvent(de)
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
59
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
60 def resizePlacedItem(self):
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
61 i = self.main.findChild(QGraphicsItem, "sizer_top_right")
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
62 print(i)
390
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
63
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
64 def testScenario1(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
65 self.cmdNewModel()
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
66 self.dragItemIntoScene()
392
bb4289c84907 Added some sort of drop event test
Windel Bouwman
parents: 390
diff changeset
67 self.resizePlacedItem()
390
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
68
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
69 def testB(self):
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
70 print('b')
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
71
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
72
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
73 if __name__ == '__main__':
b77f3290ac79 Added diagram editor tests
Windel Bouwman
parents:
diff changeset
74 unittest.main()