view test/testdiagrameditor.py @ 406:b1daa462ee17

Made kernel run again
author Windel Bouwman
date Fri, 20 Feb 2015 14:25:35 +0100
parents c0d9837acde8
children
line wrap: on
line source


import unittest
import os
import sys
import time

try:
    otherpath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'python','other'))
    sys.path.insert(0, otherpath)
    import diagrameditor

    from PyQt5.QtWidgets import QApplication, QGraphicsItem
    from PyQt5.QtTest import QTest
    from PyQt5.QtCore import Qt, QTimer, QMimeData, QPointF
    from PyQt5.QtGui import QDropEvent
    skip_it = False

    # When creating an app per testcase, this fails horribly..
    app = QApplication(sys.argv)
except ImportError as e:
    skip_it = True


if 'LCFOSGUITESTS' not in os.environ:
    skip_it = True

class DiagramEditorTestCase(unittest.TestCase):
    def setUp(self):
        if skip_it:
            self.skipTest('No qt5 or X server')
            return
        #print('Instance:', QApplication.instance())
        self.main = diagrameditor.Main()
        self.main.show()
        QTest.qWaitForWindowActive(self.main)

    def tearDown(self):
        QTimer.singleShot(100, app.quit)
        app.exec_()

    def cmdNewModel(self):
        # Press ctrl+N:
        QTest.keyClick(self.main, Qt.Key_N, Qt.ControlModifier)

    def dragItemIntoScene(self):
        library = self.main.findChild(diagrameditor.LibraryWidget, 'LibraryWidget')
        editor = self.main.findChild(diagrameditor.EditorGraphicsView, 'Editor')
        #ilibrary.
        QTest.mousePress(library, Qt.LeftButton)
        print(editor, type(editor))
        QTest.mouseMove(editor)
        QTest.mouseRelease(editor, Qt.LeftButton)
        mimedata = QMimeData()
        mimedata.setData('component/name', 'Block:blk'.encode('ascii'))
        de = QDropEvent(QPointF(10, 10), Qt.CopyAction, mimedata,
                        Qt.LeftButton,
                        Qt.NoModifier)
        editor.dropEvent(de)

    def resizePlacedItem(self):
        i = self.main.findChild(QGraphicsItem, "sizer_top_right")
        print(i)

    def testScenario1(self):
        self.cmdNewModel()
        self.dragItemIntoScene()
        self.resizePlacedItem()

    def testB(self):
        print('b')


if __name__ == '__main__':
    unittest.main()