Exemplo n.º 1
0
    def helper_first(self, add_dash_to_name=False):
        file_path = 'test.h5'
        data_utils.delete_existing_file(file_path)
        with h5py.File(file_path, mode='w') as h5_f:
            h5_dset = h5_f.create_dataset('Main', data=[1, 2, 3])
            if add_dash_to_name:
                h5_group = prov_utils.create_results_group(
                    h5_dset, 'Some-Tool')
                tool_name = 'Some_Tool'
            else:
                tool_name = 'Tool'
                h5_group = prov_utils.create_results_group(h5_dset, tool_name)
            self.assertIsInstance(h5_group, h5py.Group)
            self.assertEqual(h5_group.name, '/Main-' + tool_name + '_000')
            self.assertEqual(h5_group.parent, h5_f)
            data_utils.verify_book_keeping_attrs(self, h5_group)

            h5_dset = h5_group.create_dataset('Main_Dataset', data=[1, 2, 3])
            h5_sub_group = prov_utils.create_results_group(h5_dset, 'SHO_Fit')
            self.assertIsInstance(h5_sub_group, h5py.Group)
            self.assertEqual(
                h5_sub_group.name,
                '/Main-' + tool_name + '_000/Main_Dataset-SHO_Fit_000')
            self.assertEqual(h5_sub_group.parent, h5_group)
            data_utils.verify_book_keeping_attrs(self, h5_sub_group)
        os.remove(file_path)
Exemplo n.º 2
0
    def test_different_file(self):
        file_path = 'test.h5'
        new_path = 'new.h5'
        data_utils.delete_existing_file(file_path)
        data_utils.delete_existing_file(new_path)

        with h5py.File(file_path, mode='w') as h5_f:
            h5_dset = h5_f.create_dataset('Main', data=[1, 2, 3])
            # Ensuring that index is calculated at destination, not source:
            _ = h5_f.create_group('Main-Tool_000')

            with h5py.File(new_path, mode='w') as h5_f_new:
                _ = h5_f_new.create_group('Main-Tool_000')

                h5_group = prov_utils.create_results_group(
                    h5_dset, 'Tool', h5_parent_group=h5_f_new)

                self.assertIsInstance(h5_group, h5py.Group)
                self.assertEqual(h5_group.name, '/Main-Tool_001')
                self.assertEqual(h5_group.parent, h5_f_new)
                self.assertNotEqual(h5_dset.file, h5_group.file)
                data_utils.verify_book_keeping_attrs(self, h5_group)

        os.remove(file_path)
        os.remove(new_path)
Exemplo n.º 3
0
    def test_invalid_types(self):
        with self.assertRaises(TypeError):
            _ = prov_utils.create_results_group("not a dataset", 'Tool')

        file_path = 'test.h5'
        data_utils.delete_existing_file(file_path)
        with h5py.File(file_path, mode='w') as h5_f:
            with self.assertRaises(TypeError):
                _ = prov_utils.create_results_group(h5_f, 'Tool')

            h5_dset = h5_f.create_dataset('Main', data=[1, 2, 3])
            with self.assertRaises(TypeError):
                _ = prov_utils.create_results_group(
                    h5_dset, 'Tool', h5_parent_group='not_group')

        os.remove(file_path)
Exemplo n.º 4
0
 def test_empty_tool_name(self):
     file_path = 'test.h5'
     data_utils.delete_existing_file(file_path)
     with h5py.File(file_path, mode='w') as h5_f:
         h5_dset = h5_f.create_dataset('Main', data=[1, 2, 3])
         with self.assertRaises(ValueError):
             _ = prov_utils.create_results_group(h5_dset, '   ')
     os.remove(file_path)
Exemplo n.º 5
0
    def test_second(self):
        file_path = 'test.h5'
        data_utils.delete_existing_file(file_path)
        with h5py.File(file_path, mode='w') as h5_f:
            h5_dset = h5_f.create_dataset('Main', data=[1, 2, 3])
            h5_group = prov_utils.create_results_group(h5_dset, 'Tool')
            self.assertIsInstance(h5_group, h5py.Group)
            self.assertEqual(h5_group.name, '/Main-Tool_000')
            self.assertEqual(h5_group.parent, h5_f)
            data_utils.verify_book_keeping_attrs(self, h5_group)

            h5_sub_group = prov_utils.create_results_group(h5_dset, 'Tool')
            self.assertIsInstance(h5_sub_group, h5py.Group)
            self.assertEqual(h5_sub_group.name, '/Main-Tool_001')
            self.assertEqual(h5_sub_group.parent, h5_f)
            data_utils.verify_book_keeping_attrs(self, h5_sub_group)
        os.remove(file_path)