Ejemplo n.º 1
0
class TestHdf5TreeModelSignals(TestCaseQt):

    def setUp(self):
        TestCaseQt.setUp(self)
        self.model = hdf5.Hdf5TreeModel()
        filename = _tmpDirectory + "/data.h5"
        self.h5 = h5py.File(filename)
        self.model.insertH5pyObject(self.h5)

        self.listener = SignalListener()
        self.model.sigH5pyObjectLoaded.connect(self.listener.partial(signal="loaded"))
        self.model.sigH5pyObjectRemoved.connect(self.listener.partial(signal="removed"))
        self.model.sigH5pyObjectSynchronized.connect(self.listener.partial(signal="synchronized"))

    def tearDown(self):
        self.signals = None
        ref = weakref.ref(self.model)
        self.model = None
        self.qWaitForDestroy(ref)
        self.h5.close()
        self.h5 = None
        TestCaseQt.tearDown(self)

    def waitForPendingOperations(self, model):
        for _ in range(10):
            if not model.hasPendingOperations():
                break
            self.qWait(10)
        else:
            raise RuntimeError("Still waiting for a pending operation")

    def testInsert(self):
        filename = _tmpDirectory + "/data.h5"
        h5 = h5py.File(filename)
        self.model.insertH5pyObject(h5)
        self.assertEqual(self.listener.callCount(), 0)

    def testLoaded(self):
        filename = _tmpDirectory + "/data.h5"
        self.model.insertFile(filename)
        self.assertEqual(self.listener.callCount(), 1)
        self.assertEqual(self.listener.karguments(argumentName="signal")[0], "loaded")
        self.assertIsNot(self.listener.arguments(callIndex=0)[0], self.h5)
        self.assertEqual(self.listener.arguments(callIndex=0)[0].filename, filename)

    def testRemoved(self):
        self.model.removeH5pyObject(self.h5)
        self.assertEqual(self.listener.callCount(), 1)
        self.assertEqual(self.listener.karguments(argumentName="signal")[0], "removed")
        self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5)

    def testSynchonized(self):
        self.model.synchronizeH5pyObject(self.h5)
        self.waitForPendingOperations(self.model)
        self.assertEqual(self.listener.callCount(), 1)
        self.assertEqual(self.listener.karguments(argumentName="signal")[0], "synchronized")
        self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5)
        self.assertIsNot(self.listener.arguments(callIndex=0)[1], self.h5)
 def testSuccess(self):
     listener = SignalListener()
     button = ThreadPoolPushButton()
     button.setCallable(self._compute)
     button.beforeExecuting.connect(listener.partial(test="be"))
     button.started.connect(listener.partial(test="s"))
     button.succeeded.connect(listener.partial(test="result"))
     button.failed.connect(listener.partial(test="Unexpected exception"))
     button.finished.connect(listener.partial(test="f"))
     button.executeCallable()
     self.qapp.processEvents()
     time.sleep(0.1)
     self.qapp.processEvents()
     result = listener.karguments(argumentName="test")
     self.assertListEqual(result, ["be", "s", "result", "f"])
Ejemplo n.º 3
0
 def testSuccess(self):
     listener = SignalListener()
     button = ThreadPoolPushButton()
     button.setCallable(self._compute)
     button.beforeExecuting.connect(listener.partial(test="be"))
     button.started.connect(listener.partial(test="s"))
     button.succeeded.connect(listener.partial(test="result"))
     button.failed.connect(listener.partial(test="Unexpected exception"))
     button.finished.connect(listener.partial(test="f"))
     button.executeCallable()
     self.qapp.processEvents()
     time.sleep(0.1)
     self.qapp.processEvents()
     result = listener.karguments(argumentName="test")
     self.assertListEqual(result, ["be", "s", "result", "f"])
 def testFail(self):
     listener = SignalListener()
     button = ThreadPoolPushButton()
     button.setCallable(self._computeFail)
     button.beforeExecuting.connect(listener.partial(test="be"))
     button.started.connect(listener.partial(test="s"))
     button.succeeded.connect(listener.partial(test="Unexpected success"))
     button.failed.connect(listener.partial(test="exception"))
     button.finished.connect(listener.partial(test="f"))
     with TestLogging('silx.gui.widgets.ThreadPoolPushButton', error=1):
         button.executeCallable()
         self.qapp.processEvents()
         time.sleep(0.1)
         self.qapp.processEvents()
     result = listener.karguments(argumentName="test")
     self.assertListEqual(result, ["be", "s", "exception", "f"])
     listener.clear()
Ejemplo n.º 5
0
 def testFail(self):
     listener = SignalListener()
     button = ThreadPoolPushButton()
     button.setCallable(self._computeFail)
     button.beforeExecuting.connect(listener.partial(test="be"))
     button.started.connect(listener.partial(test="s"))
     button.succeeded.connect(listener.partial(test="Unexpected success"))
     button.failed.connect(listener.partial(test="exception"))
     button.finished.connect(listener.partial(test="f"))
     with TestLogging('silx.gui.widgets.ThreadPoolPushButton', error=1):
         button.executeCallable()
         self.qapp.processEvents()
         time.sleep(0.1)
         self.qapp.processEvents()
     result = listener.karguments(argumentName="test")
     self.assertListEqual(result, ["be", "s", "exception", "f"])
     listener.clear()
Ejemplo n.º 6
0
 def testEmitCurrentROI(self):
     """Test behavior of the CurvesROIWidget.sigROISignal"""
     roi = CurvesROIWidget.ROI(name='linear', fromdata=0, todata=5)
     self.widget.roiWidget.setRois((roi, ))
     signalListener = SignalListener()
     self.widget.roiWidget.sigROISignal.connect(signalListener.partial())
     self.widget.show()
     self.qapp.processEvents()
     self.assertTrue(signalListener.callCount() is 0)
     self.assertTrue(self.widget.roiWidget.roiTable.activeRoi is roi)
     roi.setFrom(0.0)
     self.qapp.processEvents()
     self.assertTrue(signalListener.callCount() is 0)
     roi.setFrom(0.3)
     self.qapp.processEvents()
     self.assertTrue(signalListener.callCount() is 1)
Ejemplo n.º 7
0
 def testEmitCurrentROI(self):
     """Test behavior of the CurvesROIWidget.sigROISignal"""
     roi = CurvesROIWidget.ROI(name='linear', fromdata=0, todata=5)
     self.widget.roiWidget.setRois((roi,))
     signalListener = SignalListener()
     self.widget.roiWidget.sigROISignal.connect(signalListener.partial())
     self.widget.show()
     self.qapp.processEvents()
     self.assertTrue(signalListener.callCount() is 0)
     self.assertTrue(self.widget.roiWidget.roiTable.activeRoi is roi)
     roi.setFrom(0.0)
     self.qapp.processEvents()
     self.assertTrue(signalListener.callCount() is 0)
     roi.setFrom(0.3)
     self.qapp.processEvents()
     self.assertTrue(signalListener.callCount() is 1)