Example #1
0
    def test_ui_win_title_load_dataset(self, hdf_dataset):
        """ Test whether load dataset dialog is titled properly """
        self.filename = hdf_dataset
        dialog = HdfLoad(title='TEST')
        _ = dialog.fileOpen(self.filename)

        assert dialog.windowTitle() == 'TEST: Select a dataset...'
Example #2
0
    def test_ui_win_title_empty_load_dataset(self, hdf_dataset):
        """ Test whether load dataset dialog is titled properly with no title provided"""
        self.filename = hdf_dataset
        dialog = HdfLoad()
        _ = dialog.fileOpen(self.filename)

        assert dialog.windowTitle() == 'Select a dataset...'
Example #3
0
    def test_ui_load_file(self, hdf_dataset):
        """ Load test file and check groups """
        self.filename = hdf_dataset
        dialog = HdfLoad()
        _ = dialog.fileOpen(self.filename)

        list_dsets = [dialog.ui.listDataSet.item(num).text() for num in
                      range(dialog.ui.listDataSet.count())]

        list_grps = [dialog.ui.comboBoxGroupSelect.itemText(num) for num in
                     range(dialog.ui.comboBoxGroupSelect.count())]

        assert list_dsets == ['base']
        assert 'Group1' in list_grps
        assert 'Group2/Group3' in list_grps
        assert 'Group4/Group5/Group6' in list_grps
        assert 'Group5' not in list_grps
Example #4
0
    def test_ui_change_grp_and_filter_include(self, hdf_dataset):
        """ Load test file, change to Group1, filter for _1 """
        self.filename = hdf_dataset
        dialog = HdfLoad()
        _ = dialog.fileOpen(self.filename)

        # Change group to Group1
        dialog.ui.comboBoxGroupSelect.setCurrentIndex(1)
        list_dsets = [dialog.ui.listDataSet.item(num).text() for num in
                      range(dialog.ui.listDataSet.count())]
        assert dialog.ui.comboBoxGroupSelect.currentText() == 'Group1'
        assert list_dsets == ['ingroup1_1', 'ingroup1_2']

        dialog.ui.filterIncludeString.setText('_1')
        QTest.mouseClick(dialog.ui.pushButtonFilter, Qt.LeftButton)
        list_dsets = [dialog.ui.listDataSet.item(num).text() for num in
                      range(dialog.ui.listDataSet.count())]
        assert list_dsets == ['ingroup1_1']
Example #5
0
    def test_ui_attrs(self, hdf_dataset):
        """ Load test file, change to base group (/), check attributes """
        self.filename = hdf_dataset
        dialog = HdfLoad()
        _ = dialog.fileOpen(self.filename)

        # Change group to Group1
        dialog.ui.comboBoxGroupSelect.setCurrentIndex(0)
        list_dsets = [dialog.ui.listDataSet.item(num).text() for num in
                      range(dialog.ui.listDataSet.count())]
        assert dialog.ui.comboBoxGroupSelect.currentText() == '/'
        assert list_dsets == ['base']

        # Select dataset base
        dialog.ui.listDataSet.item(0).setSelected(True)
        QTest.mouseClick(dialog.ui.listDataSet.viewport(), Qt.LeftButton)

        assert (dialog.ui.tableAttributes.findItems('Attribute_str', Qt.MatchExactly)[0].text() ==
                'Attribute_str')
        assert not dialog.ui.tableAttributes.findItems('fake', Qt.MatchExactly)  # Empty
Example #6
0
 def test_ui_wrongfile(self, hdf_dataset):
     """ Load test file, change to base group (/), check attributes """
     self.filename = hdf_dataset
     dialog = HdfLoad()
     with pytest.raises(FileNotFoundError):
         _ = dialog.fileOpen('does_not_exist.h5')
Example #7
0
    def addDataset(self):
        if (self.last_path is None) | (self.last_fname is
                                       None) | (self.last_dsetname is None):
            first_dset = True
            to_open = HdfLoad.getFileDataSets(parent=self)
        else:
            first_dset = False
            to_open = HdfLoad.getFileDataSets(pth=_os.path.join(
                self.last_path, self.last_fname),
                                              parent=self)

        if to_open is not None:
            temp_last_path, temp_last_fname, _ = to_open

            # Since to_open's dsets will be lists, this is an unraveled version
            to_import = [[temp_last_path, temp_last_fname, q]
                         for q in to_open[-1]]
            to_import2 = []  # Duplicates removed if NOT allowing duplicates

            for q in to_import:
                if not self.config['allow_duplicates']:
                    if self.is_duplicate_import([q[0], q[1], q[2]]):
                        msg = _QMessageBox(self)
                        msg.setIcon(_QMessageBox.Critical)
                        str1 = 'Cannot import duplicate image:\n\n'
                        str2 = '{} : {} : {}\n\n'.format(*q)
                        str3 = '\n\nNot importing this dataset'
                        msg.setText(str1 + str2 + str3)
                        msg.setWindowTitle('Duplicate Image Found.')
                        msg.setStandardButtons(_QMessageBox.Ok)
                        msg.setDefaultButton(_QMessageBox.Ok)
                        out = msg.exec()
                    else:
                        to_import2.append(q)

                else:
                    to_import2.append(q)

            for q in to_import2:
                fof = FidOrFile(fullpath(pth=q[0], filename=q[1]))
                if fof.fid[q[-1]].ndim != 3:
                    msg = _QMessageBox(self)
                    msg.setIcon(_QMessageBox.Critical)
                    str1 = 'Dataset is not 3D:\n\n'
                    str2 = '{} : {} : {}'.format(*q)
                    str3 = '\n\nNot importing this dataset'
                    msg.setText(str1 + str2 + str3)
                    msg.setWindowTitle('Cannot Load Non-3D Datasets.')
                    msg.setStandardButtons(_QMessageBox.Ok)
                    msg.setDefaultButton(_QMessageBox.Ok)
                    out = msg.exec()
                    fof.fid.close()
                else:
                    self.h5dlist.append(fof.fid[q[-1]])
                    self.data.append(fof.fid[q[-1]])
                    self.last_path = q[0]
                    self.last_fname = q[1]
                    self.last_dsetname = q[2]
                    self.data_list.append(q)

                    if first_dset:
                        flen = self.data.unitshape_orig[-1]
                        self.ui.sliderFreq.setMinimum(0)
                        self.ui.sliderFreq.setMaximum(flen - 1)
                        self.ui.sliderFreq.setValue(0)

                        self.pix = _np.arange(flen)
                        calib_vec = self.check_for_spectral_calib(
                            fof.fid[q[-1]])
                        self.check_for_spatial_calib(fof.fid[q[-1]])

                        self.updateFrequency(calib_vec)
                        first_dset = False

            self.updateDatasets()