Mercurial > lcfOS
comparison test/testdiagrameditor.py @ 390:b77f3290ac79
Added diagram editor tests
author | Windel Bouwman |
---|---|
date | Fri, 16 May 2014 10:12:16 +0200 |
parents | |
children | bb4289c84907 |
comparison
equal
deleted
inserted
replaced
388:e07c2a9abac1 | 390:b77f3290ac79 |
---|---|
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 | |
12 from PyQt5.QtWidgets import QApplication | |
13 from PyQt5.QtTest import QTest | |
14 from PyQt5.QtCore import Qt, QTimer | |
15 skip_it = False | |
16 | |
17 # When creating an app per testcase, this fails horribly.. | |
18 app = QApplication(sys.argv) | |
19 except ImportError as e: | |
20 skip_it = True | |
21 | |
22 | |
23 | |
24 class DiagramEditorTestCase(unittest.TestCase): | |
25 def setUp(self): | |
26 if skip_it: | |
27 self.skipTest('No qt5 or X server') | |
28 return | |
29 #print('Instance:', QApplication.instance()) | |
30 self.main = diagrameditor.Main() | |
31 self.main.show() | |
32 QTest.qWaitForWindowActive(self.main) | |
33 | |
34 def tearDown(self): | |
35 QTimer.singleShot(100, app.quit) | |
36 app.exec_() | |
37 | |
38 def cmdNewModel(self): | |
39 # Press ctrl+N: | |
40 QTest.keyClick(self.main, Qt.Key_N, Qt.ControlModifier) | |
41 | |
42 def dragItemIntoScene(self): | |
43 library = self.main.findChild(diagrameditor.LibraryWidget, 'LibraryWidget') | |
44 editor = self.main.findChild(diagrameditor.EditorGraphicsView, 'Editor') | |
45 #ilibrary. | |
46 QTest.mousePress(library, Qt.LeftButton) | |
47 print(editor, type(editor)) | |
48 QTest.mouseMove(editor) | |
49 QTest.mouseRelease(editor, Qt.LeftButton) | |
50 | |
51 def testScenario1(self): | |
52 self.cmdNewModel() | |
53 self.dragItemIntoScene() | |
54 | |
55 def testB(self): | |
56 print('b') | |
57 | |
58 | |
59 if __name__ == '__main__': | |
60 unittest.main() | |
61 |