Пример #1
0
    def test_hdf5_parse(self):
        '''
        Very basic check of parsed object structure containing minimum 3 dicts
        '''
        parsed_HDF5 = utils.parse_matlab_HDF5(self.settings['FEATURES'][0],
                                              self.settings)

        subjects = set(parsed_HDF5.keys())
        self.assertEqual(subjects,
                         self.all_subjects,
                         msg="Check that parsed HDF5 contains all subjects")

        typs = set(parsed_HDF5['Dog_1'].keys())
        self.assertEqual(typs,
                         self.all_types,
                         msg="Check that all ictypes are in parsed file by "
                             "checking the ictypes under Dog_1")

        num_interictal_dog1_segs = len(\
                parsed_HDF5['Dog_1']['interictal'].keys())

        self.assertEqual(num_interictal_dog1_segs,
                         480,
                         msg="Check there is the correct number of segments in "
                             "parsed HDF5s by checking dog1 interictal")
Пример #2
0
    def test_parse_error_warning(self):
        '''
        Assert malformed HDF5 raises proper warning
        '''
        malformed_feat = 'malformed_feat'
        h5_file_name = os.path.join(
            self.settings['TRAIN_DATA_PATH'],
            "{0}{1}.h5".format(malformed_feat, self.settings['VERSION']))

        with warnings.catch_warnings(record=True) as w:

            dummy = utils.parse_matlab_HDF5(malformed_feat, self.settings)

            self.assertEqual(len(w),
                             1,
                             msg="Check one and only one error "
                             "raised")
            self.assertIs(w[-1].category,
                          UserWarning,
                          msg="Check error is "
                          "UserWarning")
            self.assertEqual(str(w[-1].message), "Unable to "
                                                 "parse {0}".format(\
                                                            h5_file_name),
                             msg="Check the warning raised is correct format")
Пример #3
0
    def test_ioerror_warning(self):
        '''
        Assert a non-existent file correctly raises warning
        '''
        non_existent_feat = 'fake_feat'
        h5_file_name = os.path.join(
            self.settings['TRAIN_DATA_PATH'],
            "{0}{1}.h5".format(non_existent_feat, self.settings['VERSION']))

        with warnings.catch_warnings(record=True) as w:
            dummy = utils.parse_matlab_HDF5(non_existent_feat, self.settings)

            self.assertEqual(len(w),
                             1,
                             msg="Check there is one and only "
                             "one warning raised")
            self.assertIs(w[-1].category,
                          UserWarning,
                          msg="Check that "
                          "warning raised "
                          "is a UserWarning ")
            self.assertEqual(str(w[-1].message),
                             "{0} does not exist (or is not "
                             "readable)".format(h5_file_name),
                             msg="Check the "
                             "warning is "
                             "the correct "
                             "format ")
Пример #4
0
    def test_hdf5_parse(self):
        '''
        Very basic check of parsed object structure containing minimum 3 dicts
        '''
        parsed_HDF5 = utils.parse_matlab_HDF5(self.settings['FEATURES'][0],
                                              self.settings)

        subjects = set(parsed_HDF5.keys())
        self.assertEqual(subjects,
                         self.all_subjects,
                         msg="Check that parsed HDF5 contains all subjects")

        typs = set(parsed_HDF5['Dog_1'].keys())
        self.assertEqual(typs,
                         self.all_types,
                         msg="Check that all ictypes are in parsed file by "
                         "checking the ictypes under Dog_1")

        num_interictal_dog1_segs = len(\
                parsed_HDF5['Dog_1']['interictal'].keys())

        self.assertEqual(
            num_interictal_dog1_segs,
            480,
            msg="Check there is the correct number of segments in "
            "parsed HDF5s by checking dog1 interictal")
Пример #5
0
    def test_parse_error_warning(self):
        '''
        Assert malformed HDF5 raises proper warning
        '''
        malformed_feat = 'malformed_feat'
        h5_file_name = os.path.join(self.settings['TRAIN_DATA_PATH'],
                                    "{0}{1}.h5".format(malformed_feat,
                                                       self.settings['VERSION']))

        with warnings.catch_warnings(record=True) as w:

                dummy = utils.parse_matlab_HDF5(malformed_feat,
                                                self.settings)

                self.assertEqual(len(w), 1, msg="Check one and only one error "
                                                "raised")
                self.assertIs(w[-1].category, UserWarning, msg="Check error is "
                                                                "UserWarning")
                self.assertEqual(str(w[-1].message), "Unable to "
                                                     "parse {0}".format(\
                                                                h5_file_name),
                                 msg="Check the warning raised is correct format")
Пример #6
0
    def test_ioerror_warning(self):
        '''
        Assert a non-existent file correctly raises warning
        '''
        non_existent_feat = 'fake_feat'
        h5_file_name = os.path.join(self.settings['TRAIN_DATA_PATH'],
                                    "{0}{1}.h5".format(non_existent_feat,
                                                       self.settings['VERSION']))

        with warnings.catch_warnings(record=True) as w:
                dummy = utils.parse_matlab_HDF5(non_existent_feat,
                                                self.settings)

                self.assertEqual(len(w), 1, msg="Check there is one and only "
                                                "one warning raised")
                self.assertIs(w[-1].category, UserWarning, msg="Check that "
                                                                "warning raised "
                                                                "is a UserWarning ")
                self.assertEqual(str(w[-1].message),
                                 "{0} does not exist (or is not "
                                 "readable)".format(h5_file_name), msg="Check the "
                                                                        "warning is "
                                                                        "the correct "
                                                                        "format ")