def test_canConnectLogWindowToController(self):
     _ = QtGui.QApplication([])
     logWindow = LogWindow(None)
     scripts = [TEST_SCRIPT]
     settingsFiles = [self.settingsFileName]
     controller = ShotRunnerController(scripts, settingsFiles, logWindow=logWindow)
     controller.run()
     self.assertEqual(DATA, str(logWindow.toPlainText()).strip())
 def test_copiesSubprocessErrorsToLogWindow(self):
     with open(self.tempFile, 'w') as f:
         f.write("raise Exception('Foobar')")
     runner = ScriptRunner(self.tempFile)
     logWindow = LogWindow(None)
     controller = LogWindowController(runner, logWindow)
     controller.run()
     controller.join()
     self.assertTrue('Foobar' in str(logWindow.toPlainText()).strip())
 def test_copiesSubprocessOutputToLogWindow(self):
     with open(self.tempFile, 'w') as f:
         f.write("print 'Foobar'")
     runner = ScriptRunner(self.tempFile)
     logWindow = LogWindow(None)
     controller = LogWindowController(runner, logWindow)
     controller.run()
     controller.join()
     self.assertEqual('Foobar', str(logWindow.toPlainText()).strip())
 def test_canRunAsynchronously(self):
     app = QtGui.QApplication([])
     logWindow = LogWindow(None)
     scripts = [TEST_SCRIPT]
     settingsFiles = [self.settingsFileName]
     controller = ShotRunnerController(scripts, settingsFiles, logWindow=logWindow)
     controller.finished.connect(app.quit)
     controller.start()
     app.exec_()
     self.assertEqual(DATA, str(logWindow.toPlainText()).strip())
    def test_canRunMultipleScriptsAsynchronously(self):
        app = QtGui.QApplication([])
        logWindow = LogWindow(None)
        numberOfScripts = 2
        scripts = [TEST_SCRIPT] * numberOfScripts
        settingsFiles = [self.settingsFileName] * numberOfScripts
        controller = ShotRunnerController(scripts, settingsFiles, logWindow=logWindow)
        controller.finished.connect(app.quit)

        controller.start()
        app.exec_()

        messages = str(logWindow.toPlainText()).strip().splitlines()
        self.assertListEqual([DATA] * numberOfScripts, messages)
    def test_canEmitMessageFromSeparateThread(self):
        signal = StringSignal()
        window = LogWindow(None)
        signal.get().connect(window.appendMessage)

        class EmitterThread(QtCore.QThread):
            def __init__(self, signal, args):
                QtCore.QThread.__init__(self)
                self.signal = signal
                self.args = args

            def run(self):
                self.signal.emit(*self.args)

        thread = EmitterThread(signal.get(), ['Foobar'])
        thread.run()
        thread.wait()

        self.assertEqual('Foobar', window.toPlainText())
 def test_canConnectSignalToAppendMessageSlot(self):
     signal = StringSignal()
     window = LogWindow(None)
     signal.get().connect(window.appendMessage)
     signal.get().emit('Foobar')
     self.assertEqual('Foobar', window.toPlainText())