def setupClass(cls):
        """
        Start the shell and wait until it is finished initializing.
        """
        init_complete = threading.Event()
        
        def initTest(shell, workflow):
            cls.shell = shell
            cls.workflow = workflow
            init_complete.set()

        appCreationEvent = threading.Event()
        def createApp():
            # Create the application in the current thread.
            # The current thread is now the application main thread.
            ShellGuiTestCaseBase.app = QApplication([])
            app = ShellGuiTestCaseBase.app
            
            # Don't auto-quit the app when the window closes.  We want to re-use it for the next test.
            app.setQuitOnLastWindowClosed(False)
            
            # Create a threadRouter object that allows us to send work to the app from other threads.
            ShellGuiTestCaseBase.threadRouter = ThreadRouter(app)
            
            # Set the appCreationEvent so the tests can proceed after the app's event loop has started 
            QTimer.singleShot(0, appCreationEvent.set )

            # Start the event loop
            app.exec_()
        
        # If nose was run from the main thread, start the gui in a separate thread.
        # If nose is running in a non-main thread, we assume the main thread is available to launch the gui.
        # This is a workaround for Mac OS, in which the gui MUST be started from the main thread 
        #  (which means we've got to run nose from a separate thread.)
        if threading.current_thread() == threading.enumerate()[0]:
            if "Darwin" in platform.platform():
                # On Mac, we can't run the gui in a non-main thread.
                raise nose.SkipTest
            else:
                    
                if ShellGuiTestCaseBase.guiThread is None:
                    # QT gives a lot of errors if you try to make more than one app, 
                    #  even if the apps are created sequentially in the same thread.
                    # We'll just create a single app and re-use it for subsequent tests.
                    ShellGuiTestCaseBase.guiThread = threading.Thread( target=createApp )
                    ShellGuiTestCaseBase.guiThread.daemon = True
                    ShellGuiTestCaseBase.guiThread.start()
                    appCreationEvent.wait()
                    assert not ShellGuiTestCaseBase.app.thread().isFinished()
        else:
                # We're currently running in a non-main thread.
                # Start the gui IN THE MAIN THREAD.  Workflow is provided by our subclass.
                from tests.helpers.mainThreadHelpers import run_in_main_thread
                run_in_main_thread( createApp() )
                ShellGuiTestCaseBase.guiThread = None
                appCreationEvent.wait()

        # Use the thread router to launch the shell in the app thread
        ShellGuiTestCaseBase.threadRouter.routeToParent.emit( partial(launchShell, cls.workflowClass(), initTest ) )
        init_complete.wait()
Пример #2
0
    def setupClass(cls):
        """
        Start the shell and wait until it is finished initializing.
        """
        init_complete = threading.Event()

        def initTest(shell):
            cls.shell = shell
            init_complete.set()

        appCreationEvent = threading.Event()

        def createApp():
            # Create the application in the current thread.
            # The current thread is now the application main thread.
            assert threading.current_thread() == threading.enumerate(
            )[0], "Error: app must be created in the main thread."
            ShellGuiTestCaseBase.app = QApplication([])
            app = ShellGuiTestCaseBase.app

            # Don't auto-quit the app when the window closes.  We want to re-use it for the next test.
            app.setQuitOnLastWindowClosed(False)

            # Create a threadRouter object that allows us to send work to the app from other threads.
            ShellGuiTestCaseBase.threadRouter = ThreadRouter(app)

            # Set the appCreationEvent so the tests can proceed after the app's event loop has started
            QTimer.singleShot(0, appCreationEvent.set)

            # Start the event loop
            app.exec_()

        # If nose was run from the main thread, exit now.
        # If nose is running in a non-main thread, we assume the main thread is available to launch the gui.
        if threading.current_thread() == threading.enumerate()[0]:
            # Don't run GUI tests in the main thread.
            sys.stderr.write(
                "NOSE WAS RUN FROM THE MAIN THREAD.  SKIPPING GUI TEST\n")
            raise nose.SkipTest
        else:
            # We're currently running in a non-main thread.
            # Start the gui IN THE MAIN THREAD.  Workflow is provided by our subclass.
            run_in_main_thread(createApp)
            appCreationEvent.wait()

        platform_str = platform.platform().lower()
        if 'ubuntu' in platform_str or 'fedora' in platform_str:
            QApplication.setAttribute(Qt.AA_X11InitThreads, True)

        if ilastik.config.cfg.getboolean("ilastik", "debug"):
            QApplication.setAttribute(Qt.AA_DontUseNativeMenuBar, True)

        # Use the thread router to launch the shell in the app thread
        ShellGuiTestCaseBase.threadRouter.routeToParent.emit(
            partial(launchShell, None, initTest))
        init_complete.wait()
Пример #3
0
    def setupClass(cls):
        """
        Start the shell and wait until it is finished initializing.
        """
        init_complete = threading.Event()

        def initTest(shell):
            cls.shell = shell
            init_complete.set()

        appCreationEvent = threading.Event()

        def createApp():
            # Create the application in the current thread.
            # The current thread is now the application main thread.
            assert (
                threading.current_thread().getName() == "MainThread"
            ), "Error: app must be created in the main thread."
            ShellGuiTestCaseBase.app = QApplication([])
            app = ShellGuiTestCaseBase.app

            # Don't auto-quit the app when the window closes.  We want to re-use it for the next test.
            app.setQuitOnLastWindowClosed(False)

            # Create a threadRouter object that allows us to send work to the app from other threads.
            ShellGuiTestCaseBase.threadRouter = ThreadRouter(app)

            # Set the appCreationEvent so the tests can proceed after the app's event loop has started
            QTimer.singleShot(0, appCreationEvent.set)

            # Start the event loop
            app.exec_()

        # If nose was run from the main thread, exit now.
        # If nose is running in a non-main thread, we assume the main thread is available to launch the gui.
        if threading.current_thread().getName() == "MainThread":
            # Don't run GUI tests in the main thread.
            sys.stderr.write("NOSE WAS RUN FROM THE MAIN THREAD.  SKIPPING GUI TEST\n")
            raise nose.SkipTest
        else:
            # We're currently running in a non-main thread.
            # Start the gui IN THE MAIN THREAD.  Workflow is provided by our subclass.
            run_in_main_thread(createApp)
            appCreationEvent.wait()

        platform_str = platform.platform().lower()
        if "ubuntu" in platform_str or "fedora" in platform_str:
            QApplication.setAttribute(Qt.AA_X11InitThreads, True)

        if ilastik.config.cfg.getboolean("ilastik", "debug"):
            QApplication.setAttribute(Qt.AA_DontUseNativeMenuBar, True)

        # Use the thread router to launch the shell in the app thread
        ShellGuiTestCaseBase.threadRouter.routeToParent.emit(partial(launchShell, None, initTest))
        init_complete.wait()
Пример #4
0
    def setupClass(cls):
        """
        Start the shell and wait until it is finished initializing.
        """
        init_complete = threading.Event()
        
        def initTest(shell, workflow):
            cls.shell = shell
            cls.workflow = workflow
            init_complete.set()

        appCreationEvent = threading.Event()
        def createApp():
            # Create the application in the current thread.
            # The current thread is now the application main thread.
            assert threading.current_thread() == threading.enumerate()[0], "Error: app must be created in the main thread."
            ShellGuiTestCaseBase.app = QApplication([])
            app = ShellGuiTestCaseBase.app
            
            # Don't auto-quit the app when the window closes.  We want to re-use it for the next test.
            app.setQuitOnLastWindowClosed(False)
            
            # Create a threadRouter object that allows us to send work to the app from other threads.
            ShellGuiTestCaseBase.threadRouter = ThreadRouter(app)
            
            # Set the appCreationEvent so the tests can proceed after the app's event loop has started 
            QTimer.singleShot(0, appCreationEvent.set )

            # Start the event loop
            app.exec_()
        
        # If nose was run from the main thread, exit now.
        # If nose is running in a non-main thread, we assume the main thread is available to launch the gui.
        if threading.current_thread() == threading.enumerate()[0]:
            # Don't run GUI tests in the main thread.
            sys.stderr.write( "NOSE WAS RUN FROM THE MAIN THREAD.  SKIPPING GUI TEST\n" )
            raise nose.SkipTest
        else:
            # We're currently running in a non-main thread.
            # Start the gui IN THE MAIN THREAD.  Workflow is provided by our subclass.
            run_in_main_thread( createApp )
            appCreationEvent.wait()

        # Use the thread router to launch the shell in the app thread
        ShellGuiTestCaseBase.threadRouter.routeToParent.emit( partial(launchShell, cls.workflowClass(), initTest ) )
        init_complete.wait()
    def setupClass(cls):
        """
        Start the shell and wait until it is finished initializing.
        """
        init_complete = threading.Event()

        def initTest(shell, workflow):
            cls.shell = shell
            cls.workflow = workflow
            init_complete.set()

        appCreationEvent = threading.Event()

        def createApp():
            # Create the application in the current thread.
            # The current thread is now the application main thread.
            ShellGuiTestCaseBase.app = QApplication([])
            app = ShellGuiTestCaseBase.app

            # Don't auto-quit the app when the window closes.  We want to re-use it for the next test.
            app.setQuitOnLastWindowClosed(False)

            # Create a threadRouter object that allows us to send work to the app from other threads.
            ShellGuiTestCaseBase.threadRouter = ThreadRouter(app)

            # Set the appCreationEvent so the tests can proceed after the app's event loop has started
            QTimer.singleShot(0, appCreationEvent.set)

            # Start the event loop
            app.exec_()

        # If nose was run from the main thread, start the gui in a separate thread.
        # If nose is running in a non-main thread, we assume the main thread is available to launch the gui.
        # This is a workaround for Mac OS, in which the gui MUST be started from the main thread
        #  (which means we've got to run nose from a separate thread.)
        if threading.current_thread() == threading.enumerate()[0]:
            if "Darwin" in platform.platform():
                # On Mac, we can't run the gui in a non-main thread.
                raise nose.SkipTest
            else:

                if ShellGuiTestCaseBase.guiThread is None:
                    # QT gives a lot of errors if you try to make more than one app,
                    #  even if the apps are created sequentially in the same thread.
                    # We'll just create a single app and re-use it for subsequent tests.
                    ShellGuiTestCaseBase.guiThread = threading.Thread(
                        target=createApp)
                    ShellGuiTestCaseBase.guiThread.daemon = True
                    ShellGuiTestCaseBase.guiThread.start()
                    appCreationEvent.wait()
                    assert not ShellGuiTestCaseBase.app.thread().isFinished()
        else:
            # We're currently running in a non-main thread.
            # Start the gui IN THE MAIN THREAD.  Workflow is provided by our subclass.
            from tests.helpers.mainThreadHelpers import run_in_main_thread
            run_in_main_thread(createApp())
            ShellGuiTestCaseBase.guiThread = None
            appCreationEvent.wait()

        # Use the thread router to launch the shell in the app thread
        ShellGuiTestCaseBase.threadRouter.routeToParent.emit(
            partial(launchShell, cls.workflowClass(), initTest))
        init_complete.wait()