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.assertEquals(self.listener.callCount(), 0) def testLoaded(self): filename = _tmpDirectory + "/data.h5" self.model.insertFile(filename) self.assertEquals(self.listener.callCount(), 1) self.assertEquals(self.listener.karguments(argumentName="signal")[0], "loaded") self.assertIsNot(self.listener.arguments(callIndex=0)[0], self.h5) self.assertEquals(self.listener.arguments(callIndex=0)[0].filename, filename) def testRemoved(self): self.model.removeH5pyObject(self.h5) self.assertEquals(self.listener.callCount(), 1) self.assertEquals(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.assertEquals(self.listener.callCount(), 1) self.assertEquals(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"])
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()
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.assertEquals(self.listener.callCount(), 0) def testLoaded(self): filename = _tmpDirectory + "/data.h5" self.model.insertFile(filename) self.assertEquals(self.listener.callCount(), 1) self.assertEquals( self.listener.karguments(argumentName="signal")[0], "loaded") self.assertIsNot(self.listener.arguments(callIndex=0)[0], self.h5) self.assertEquals( self.listener.arguments(callIndex=0)[0].filename, filename) def testRemoved(self): self.model.removeH5pyObject(self.h5) self.assertEquals(self.listener.callCount(), 1) self.assertEquals( 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.assertEquals(self.listener.callCount(), 1) self.assertEquals( 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)