390
|
1
|
|
2 import unittest
|
|
3 import os
|
|
4 import sys
|
|
5 import time
|
|
6
|
|
7 try:
|
|
8 otherpath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'python','other'))
|
|
9 sys.path.insert(0, otherpath)
|
|
10 import diagrameditor
|
|
11
|
392
|
12 from PyQt5.QtWidgets import QApplication, QGraphicsItem
|
390
|
13 from PyQt5.QtTest import QTest
|
392
|
14 from PyQt5.QtCore import Qt, QTimer, QMimeData, QPointF
|
|
15 from PyQt5.QtGui import QDropEvent
|
390
|
16 skip_it = False
|
|
17
|
|
18 # When creating an app per testcase, this fails horribly..
|
|
19 app = QApplication(sys.argv)
|
|
20 except ImportError as e:
|
|
21 skip_it = True
|
|
22
|
|
23
|
398
|
24 if 'LCFOSGUITESTS' not in os.environ:
|
|
25 skip_it = True
|
390
|
26
|
|
27 class DiagramEditorTestCase(unittest.TestCase):
|
|
28 def setUp(self):
|
|
29 if skip_it:
|
|
30 self.skipTest('No qt5 or X server')
|
|
31 return
|
|
32 #print('Instance:', QApplication.instance())
|
|
33 self.main = diagrameditor.Main()
|
|
34 self.main.show()
|
|
35 QTest.qWaitForWindowActive(self.main)
|
|
36
|
|
37 def tearDown(self):
|
|
38 QTimer.singleShot(100, app.quit)
|
|
39 app.exec_()
|
|
40
|
|
41 def cmdNewModel(self):
|
|
42 # Press ctrl+N:
|
|
43 QTest.keyClick(self.main, Qt.Key_N, Qt.ControlModifier)
|
|
44
|
|
45 def dragItemIntoScene(self):
|
|
46 library = self.main.findChild(diagrameditor.LibraryWidget, 'LibraryWidget')
|
|
47 editor = self.main.findChild(diagrameditor.EditorGraphicsView, 'Editor')
|
|
48 #ilibrary.
|
|
49 QTest.mousePress(library, Qt.LeftButton)
|
|
50 print(editor, type(editor))
|
|
51 QTest.mouseMove(editor)
|
|
52 QTest.mouseRelease(editor, Qt.LeftButton)
|
392
|
53 mimedata = QMimeData()
|
|
54 mimedata.setData('component/name', 'Block:blk'.encode('ascii'))
|
|
55 de = QDropEvent(QPointF(10, 10), Qt.CopyAction, mimedata,
|
|
56 Qt.LeftButton,
|
|
57 Qt.NoModifier)
|
|
58 editor.dropEvent(de)
|
|
59
|
|
60 def resizePlacedItem(self):
|
|
61 i = self.main.findChild(QGraphicsItem, "sizer_top_right")
|
|
62 print(i)
|
390
|
63
|
|
64 def testScenario1(self):
|
|
65 self.cmdNewModel()
|
|
66 self.dragItemIntoScene()
|
392
|
67 self.resizePlacedItem()
|
390
|
68
|
|
69 def testB(self):
|
|
70 print('b')
|
|
71
|
|
72
|
|
73 if __name__ == '__main__':
|
|
74 unittest.main()
|