Ejemplo n.º 1
0
 def testCreateNxdataFromDataset(self):
     widget = CustomNxdataWidget()
     model = widget.model()
     signal = commonh5.Dataset("foo", data=numpy.array([[[5]]]))
     model.createFromSignal(signal)
     widget.setVisible(True)
     self.qWaitForWindowExposed(widget)
Ejemplo n.º 2
0
 def testCreateNxdataFromDataset(self):
     widget = CustomNxdataWidget()
     model = widget.model()
     signal = commonh5.Dataset("foo", data=numpy.array([[[5]]]))
     model.createFromSignal(signal)
     widget.setVisible(True)
     self.qWaitForWindowExposed(widget)
Ejemplo n.º 3
0
 def testCreateNxdata(self):
     widget = CustomNxdataWidget()
     model = widget.model()
     model.createNewNxdata()
     model.createNewNxdata("Foo")
     widget.setVisible(True)
     self.qWaitForWindowExposed(widget)
Ejemplo n.º 4
0
 def testCreateNxdata(self):
     widget = CustomNxdataWidget()
     model = widget.model()
     model.createNewNxdata()
     model.createNewNxdata("Foo")
     widget.setVisible(True)
     self.qWaitForWindowExposed(widget)
Ejemplo n.º 5
0
    def setUp(self):
        TestCaseQt.setUp(self)

        self.widget = CustomNxdataWidget()
        self.model = self.widget.model()
        data = numpy.array([[[5]]])
        dataset = commonh5.Dataset("foo", data=data)
        self.model.createFromSignal(dataset)
        self.selectionModel = self.widget.selectionModel()
Ejemplo n.º 6
0
 def testRemoveDatasetsFrom(self):
     f = h5py.File(self.data_h5, mode='r')
     try:
         widget = CustomNxdataWidget()
         model = widget.model()
         dataset = f["arrays/integers"]
         model.createFromSignal(dataset)
         widget.removeDatasetsFrom(f)
     finally:
         model.clear()
         f.close()
Ejemplo n.º 7
0
 def testCreateNxdataFromNxdata(self):
     widget = CustomNxdataWidget()
     model = widget.model()
     data = numpy.array([[[5]]])
     nxdata = commonh5.Group("foo")
     nxdata.attrs["NX_class"] = "NXdata"
     nxdata.attrs["signal"] = "signal"
     nxdata.create_dataset("signal", data=data)
     model.createFromNxdata(nxdata)
     widget.setVisible(True)
     self.qWaitForWindowExposed(widget)
Ejemplo n.º 8
0
 def testRemoveDatasetsFrom(self):
     f = h5py.File(os.path.join(_tmpDirectory, "data.h5"))
     try:
         widget = CustomNxdataWidget()
         model = widget.model()
         dataset = f["arrays/integers"]
         model.createFromSignal(dataset)
         widget.removeDatasetsFrom(f)
     finally:
         model.clear()
         f.close()
Ejemplo n.º 9
0
 def testCreateNxdataFromNxdata(self):
     widget = CustomNxdataWidget()
     model = widget.model()
     data = numpy.array([[[5]]])
     nxdata = commonh5.Group("foo")
     nxdata.attrs["NX_class"] = "NXdata"
     nxdata.attrs["signal"] = "signal"
     nxdata.create_dataset("signal", data=data)
     model.createFromNxdata(nxdata)
     widget.setVisible(True)
     self.qWaitForWindowExposed(widget)
Ejemplo n.º 10
0
 def testRemoveDatasetsFrom(self):
     f = h5py.File(os.path.join(_tmpDirectory, "data.h5"))
     try:
         widget = CustomNxdataWidget()
         model = widget.model()
         dataset = f["arrays/integers"]
         model.createFromSignal(dataset)
         widget.removeDatasetsFrom(f)
     finally:
         model.clear()
         f.close()
Ejemplo n.º 11
0
 def testCreateBadNxdata(self):
     widget = CustomNxdataWidget()
     model = widget.model()
     signal = commonh5.Dataset("foo", data=numpy.array([[[5]]]))
     model.createFromSignal(signal)
     axis = commonh5.Dataset("foo", data=numpy.array([[[5]]]))
     nxdataIndex = model.index(0, 0)
     item = model.itemFromIndex(nxdataIndex)
     item.setAxesDatasets([axis])
     nxdata = item.getVirtualGroup()
     self.assertIsNotNone(nxdata)
     self.assertFalse(item.isValid())
Ejemplo n.º 12
0
 def testCreateBadNxdata(self):
     widget = CustomNxdataWidget()
     model = widget.model()
     signal = commonh5.Dataset("foo", data=numpy.array([[[5]]]))
     model.createFromSignal(signal)
     axis = commonh5.Dataset("foo", data=numpy.array([[[5]]]))
     nxdataIndex = model.index(0, 0)
     item = model.itemFromIndex(nxdataIndex)
     item.setAxesDatasets([axis])
     nxdata = item.getVirtualGroup()
     self.assertIsNotNone(nxdata)
     self.assertFalse(item.isValid())
Ejemplo n.º 13
0
    def setUp(self):
        TestCaseQt.setUp(self)

        self.widget = CustomNxdataWidget()
        self.model = self.widget.model()
        data = numpy.array([[[5]]])
        dataset = commonh5.Dataset("foo", data=data)
        self.model.createFromSignal(dataset)
        self.selectionModel = self.widget.selectionModel()
Ejemplo n.º 14
0
class TestCustomNxdataWidgetInteraction(TestCaseQt):
    """Test CustomNxdataWidget with user interaction"""
    def setUp(self):
        TestCaseQt.setUp(self)

        self.widget = CustomNxdataWidget()
        self.model = self.widget.model()
        data = numpy.array([[[5]]])
        dataset = commonh5.Dataset("foo", data=data)
        self.model.createFromSignal(dataset)
        self.selectionModel = self.widget.selectionModel()

    def tearDown(self):
        self.selectionModel = None
        self.model.clear()
        self.model = None
        self.widget = None
        TestCaseQt.tearDown(self)

    def testSelectedNxdata(self):
        index = self.model.index(0, 0)
        self.selectionModel.setCurrentIndex(
            index, qt.QItemSelectionModel.ClearAndSelect)
        nxdata = self.widget.selectedNxdata()
        self.assertEqual(len(nxdata), 1)
        self.assertIsNot(nxdata[0], None)

    def testSelectedItems(self):
        index = self.model.index(0, 0)
        self.selectionModel.setCurrentIndex(
            index, qt.QItemSelectionModel.ClearAndSelect)
        items = self.widget.selectedItems()
        self.assertEqual(len(items), 1)
        self.assertIsNot(items[0], None)
        self.assertIsInstance(items[0], qt.QStandardItem)

    def testRowsAboutToBeRemoved(self):
        self.model.removeRow(0)
        self.qWaitForWindowExposed(self.widget)

    def testPaintItems(self):
        self.widget.expandAll()
        self.widget.setVisible(True)
        self.qWaitForWindowExposed(self.widget)

    def testCreateDefaultContextMenu(self):
        nxDataIndex = self.model.index(0, 0)
        menu = self.widget.createDefaultContextMenu(nxDataIndex)
        self.assertIsNot(menu, None)
        self.assertIsInstance(menu, qt.QMenu)

        signalIndex = self.model.index(0, 0, nxDataIndex)
        menu = self.widget.createDefaultContextMenu(signalIndex)
        self.assertIsNot(menu, None)
        self.assertIsInstance(menu, qt.QMenu)

        axesIndex = self.model.index(1, 0, nxDataIndex)
        menu = self.widget.createDefaultContextMenu(axesIndex)
        self.assertIsNot(menu, None)
        self.assertIsInstance(menu, qt.QMenu)

    def testDropNewDataset(self):
        dataset = commonh5.Dataset("foo", numpy.array([1, 2, 3, 4]))
        mimedata = Hdf5DatasetMimeData(dataset=dataset)
        self.model.dropMimeData(mimedata, qt.Qt.CopyAction, -1, -1,
                                qt.QModelIndex())
        self.assertEqual(self.model.rowCount(qt.QModelIndex()), 2)

    def testDropNewNxdata(self):
        data = numpy.array([[[5]]])
        nxdata = commonh5.Group("foo")
        nxdata.attrs["NX_class"] = "NXdata"
        nxdata.attrs["signal"] = "signal"
        nxdata.create_dataset("signal", data=data)
        mimedata = Hdf5DatasetMimeData(dataset=nxdata)
        self.model.dropMimeData(mimedata, qt.Qt.CopyAction, -1, -1,
                                qt.QModelIndex())
        self.assertEqual(self.model.rowCount(qt.QModelIndex()), 2)

    def testDropAxisDataset(self):
        dataset = commonh5.Dataset("foo", numpy.array([1, 2, 3, 4]))
        mimedata = Hdf5DatasetMimeData(dataset=dataset)
        nxDataIndex = self.model.index(0, 0)
        axesIndex = self.model.index(1, 0, nxDataIndex)
        self.model.dropMimeData(mimedata, qt.Qt.CopyAction, -1, -1, axesIndex)
        self.assertEqual(self.model.rowCount(qt.QModelIndex()), 1)
        item = self.model.itemFromIndex(axesIndex)
        self.assertIsNot(item.getDataset(), None)

    def testMimeData(self):
        nxDataIndex = self.model.index(0, 0)
        signalIndex = self.model.index(0, 0, nxDataIndex)
        mimeData = self.model.mimeData([signalIndex])
        self.assertIsNot(mimeData, None)
        self.assertIsInstance(mimeData, qt.QMimeData)

    def testRemoveNxdataItem(self):
        nxdataIndex = self.model.index(0, 0)
        item = self.model.itemFromIndex(nxdataIndex)
        self.model.removeNxdataItem(item)

    def testAppendAxisToNxdataItem(self):
        nxdataIndex = self.model.index(0, 0)
        item = self.model.itemFromIndex(nxdataIndex)
        self.model.appendAxisToNxdataItem(item)

    def testRemoveAxisItem(self):
        nxdataIndex = self.model.index(0, 0)
        axesIndex = self.model.index(1, 0, nxdataIndex)
        item = self.model.itemFromIndex(axesIndex)
        self.model.removeAxisItem(item)
Ejemplo n.º 15
0
 def testDestroy(self):
     widget = CustomNxdataWidget()
     ref = weakref.ref(widget)
     widget = None
     self.qWaitForDestroy(ref)
Ejemplo n.º 16
0
class TestCustomNxdataWidgetInteraction(TestCaseQt):
    """Test CustomNxdataWidget with user interaction"""

    def setUp(self):
        TestCaseQt.setUp(self)

        self.widget = CustomNxdataWidget()
        self.model = self.widget.model()
        data = numpy.array([[[5]]])
        dataset = commonh5.Dataset("foo", data=data)
        self.model.createFromSignal(dataset)
        self.selectionModel = self.widget.selectionModel()

    def tearDown(self):
        self.selectionModel = None
        self.model.clear()
        self.model = None
        self.widget = None
        TestCaseQt.tearDown(self)

    def testSelectedNxdata(self):
        index = self.model.index(0, 0)
        self.selectionModel.setCurrentIndex(index, qt.QItemSelectionModel.ClearAndSelect)
        nxdata = self.widget.selectedNxdata()
        self.assertEqual(len(nxdata), 1)
        self.assertIsNot(nxdata[0], None)

    def testSelectedItems(self):
        index = self.model.index(0, 0)
        self.selectionModel.setCurrentIndex(index, qt.QItemSelectionModel.ClearAndSelect)
        items = self.widget.selectedItems()
        self.assertEqual(len(items), 1)
        self.assertIsNot(items[0], None)
        self.assertIsInstance(items[0], qt.QStandardItem)

    def testRowsAboutToBeRemoved(self):
        self.model.removeRow(0)
        self.qWaitForWindowExposed(self.widget)

    def testPaintItems(self):
        self.widget.expandAll()
        self.widget.setVisible(True)
        self.qWaitForWindowExposed(self.widget)

    def testCreateDefaultContextMenu(self):
        nxDataIndex = self.model.index(0, 0)
        menu = self.widget.createDefaultContextMenu(nxDataIndex)
        self.assertIsNot(menu, None)
        self.assertIsInstance(menu, qt.QMenu)

        signalIndex = self.model.index(0, 0, nxDataIndex)
        menu = self.widget.createDefaultContextMenu(signalIndex)
        self.assertIsNot(menu, None)
        self.assertIsInstance(menu, qt.QMenu)

        axesIndex = self.model.index(1, 0, nxDataIndex)
        menu = self.widget.createDefaultContextMenu(axesIndex)
        self.assertIsNot(menu, None)
        self.assertIsInstance(menu, qt.QMenu)

    def testDropNewDataset(self):
        dataset = commonh5.Dataset("foo", numpy.array([1, 2, 3, 4]))
        mimedata = Hdf5DatasetMimeData(dataset=dataset)
        self.model.dropMimeData(mimedata, qt.Qt.CopyAction, -1, -1, qt.QModelIndex())
        self.assertEqual(self.model.rowCount(qt.QModelIndex()), 2)

    def testDropNewNxdata(self):
        data = numpy.array([[[5]]])
        nxdata = commonh5.Group("foo")
        nxdata.attrs["NX_class"] = "NXdata"
        nxdata.attrs["signal"] = "signal"
        nxdata.create_dataset("signal", data=data)
        mimedata = Hdf5DatasetMimeData(dataset=nxdata)
        self.model.dropMimeData(mimedata, qt.Qt.CopyAction, -1, -1, qt.QModelIndex())
        self.assertEqual(self.model.rowCount(qt.QModelIndex()), 2)

    def testDropAxisDataset(self):
        dataset = commonh5.Dataset("foo", numpy.array([1, 2, 3, 4]))
        mimedata = Hdf5DatasetMimeData(dataset=dataset)
        nxDataIndex = self.model.index(0, 0)
        axesIndex = self.model.index(1, 0, nxDataIndex)
        self.model.dropMimeData(mimedata, qt.Qt.CopyAction, -1, -1, axesIndex)
        self.assertEqual(self.model.rowCount(qt.QModelIndex()), 1)
        item = self.model.itemFromIndex(axesIndex)
        self.assertIsNot(item.getDataset(), None)

    def testMimeData(self):
        nxDataIndex = self.model.index(0, 0)
        signalIndex = self.model.index(0, 0, nxDataIndex)
        mimeData = self.model.mimeData([signalIndex])
        self.assertIsNot(mimeData, None)
        self.assertIsInstance(mimeData, qt.QMimeData)

    def testRemoveNxdataItem(self):
        nxdataIndex = self.model.index(0, 0)
        item = self.model.itemFromIndex(nxdataIndex)
        self.model.removeNxdataItem(item)

    def testAppendAxisToNxdataItem(self):
        nxdataIndex = self.model.index(0, 0)
        item = self.model.itemFromIndex(nxdataIndex)
        self.model.appendAxisToNxdataItem(item)

    def testRemoveAxisItem(self):
        nxdataIndex = self.model.index(0, 0)
        axesIndex = self.model.index(1, 0, nxdataIndex)
        item = self.model.itemFromIndex(axesIndex)
        self.model.removeAxisItem(item)
Ejemplo n.º 17
0
 def testConstruct(self):
     widget = CustomNxdataWidget()
     self.qWaitForWindowExposed(widget)