Example #1
0
 def test_remove_dt_non_existent(self):
     """
     Try to call remove on a dataType with no H5 file.
     Should work.
     """
     folder_path = self.files_helper.get_project_folder(self.test_project, "42")
     datatype = MappedType()
     datatype.storage_path = folder_path
     assert not os.path.exists(datatype.get_storage_file_path())
     self.files_helper.remove_datatype(datatype)
Example #2
0
 def test_remove_dt_non_existent(self):
     """
     Try to call remove on a dataType with no H5 file.
     Should throw an exception.
     """
     folder_path = self.files_helper.get_project_folder(self.test_project, "42")
     datatype = MappedType()
     datatype.storage_path = folder_path
     self.assertFalse(os.path.exists(datatype.get_storage_file_path()))
     self.assertRaises(FileStructureException, self.files_helper.remove_datatype, datatype)
 def test_remove_dt_non_existent(self):
     """
     Try to call remove on a dataType with no H5 file.
     Should work.
     """
     folder_path = self.files_helper.get_project_folder(self.test_project, "42")
     datatype = MappedType()
     datatype.storage_path = folder_path
     self.assertFalse(os.path.exists(datatype.get_storage_file_path()))
     self.files_helper.remove_datatype(datatype)
 def test_remove_dt_happy_flow(self):
     """
     Happy flow for removing a file related to a DataType.
     """
     folder_path = self.files_helper.get_project_folder(self.test_project, "42")
     datatype = MappedType()
     datatype.storage_path = folder_path
     open(datatype.get_storage_file_path(), 'w') 
     self.assertTrue(os.path.exists(datatype.get_storage_file_path()), "Test file was not created!")
     self.files_helper.remove_datatype(datatype) 
     self.assertFalse(os.path.exists(datatype.get_storage_file_path()), "Test file was not deleted!")      
class ProjectionMatrixData(MappedType):
    """
    Base DataType for representing a ProjectionMatrix.
    The projection is between a source of type Connectivity regions or Surface and a set of Sensors.
    """
    
    sources = MappedType(label = "surface or region",
                                default = None, required = True)
    
    
    ## We can not use base class sensors here due to polymorphic selection
    sensors = MappedType(label = "Sensors", default = None, required = False,
                                doc = """ A set of sensors to compute projection matrix for them. """)
    
    projection_data = arrays.FloatArray(label = "Projection Matrix Data",
                                        default = None, required = True)
Example #6
0
    def setUp(self):
        """
        Prepare data for tests
        """
        storage_folder = os.path.join(config.TVB_STORAGE, "test_hdf5")

        if os.path.exists(storage_folder):
            shutil.rmtree(storage_folder)
        os.makedirs(storage_folder)

        # Create data type for which to store data
        self.data_type = MappedType()
        self.data_type.storage_path = storage_folder

        self.test_2D_array = numpy.random.random((10, 10))
        self.data_name = "vertex"
Example #7
0
 def accepted_filters():
     filters = MappedType.accepted_filters()
     filters.update({
         'datatype_class._number_of_regions': {
             'type': 'int',
             'display': 'No of Regions',
             'operations': ['==', '<', '>']
         }
     })
     return filters
Example #8
0
 def test_move_datatype(self):
     """
     Make sure associated H5 file is moved to a correct new location.
     """
     folder_path = self.files_helper.get_project_folder(self.test_project, "42")
     datatype = MappedType()
     datatype.storage_path = folder_path
     open(datatype.get_storage_file_path(), 'w') 
     self.assertTrue(os.path.exists(datatype.get_storage_file_path()), "Test file was not created!")
     self.files_helper.move_datatype(datatype, self.PROJECT_NAME + '11', "43") 
     
     self.assertFalse(os.path.exists(datatype.get_storage_file_path()), "Test file was not moved!")
     datatype.storage_path = self.files_helper.get_project_folder(self.PROJECT_NAME + '11', "43")
     self.assertTrue(os.path.exists(datatype.get_storage_file_path()), "Test file was not created!")
    def setUp(self):
        """
        Prepare data for tests
        """
        storage_folder = os.path.join(TvbProfile.current.TVB_STORAGE, "test_hdf5")

        if os.path.exists(storage_folder):
            shutil.rmtree(storage_folder)
        os.makedirs(storage_folder)
        
        # Create data type for which to store data
        self.data_type = MappedType()
        self.data_type.storage_path = storage_folder
        
        self.test_2D_array = numpy.random.random((10, 10))
        self.data_name = "vertex"
 def test_move_datatype(self):
     """
     Make sure associated H5 file is moved to a correct new location.
     """
     folder_path = self.files_helper.get_project_folder(self.test_project, "42")
     datatype = MappedType()
     datatype.storage_path = folder_path
     open(datatype.get_storage_file_path(), 'w') 
     self.assertTrue(os.path.exists(datatype.get_storage_file_path()), "Test file was not created!")
     self.files_helper.move_datatype(datatype, self.PROJECT_NAME + '11', "43") 
     
     self.assertFalse(os.path.exists(datatype.get_storage_file_path()), "Test file was not moved!")
     datatype.storage_path = self.files_helper.get_project_folder(self.PROJECT_NAME + '11', "43")
     self.assertTrue(os.path.exists(datatype.get_storage_file_path()), "Test file was not created!")
Example #11
0
 def test_remove_dt_happy_flow(self):
     """
     Happy flow for removing a file related to a DataType.
     """
     folder_path = self.files_helper.get_project_folder(self.test_project, "42")
     datatype = MappedType()
     datatype.storage_path = folder_path
     open(datatype.get_storage_file_path(), 'w') 
     self.assertTrue(os.path.exists(datatype.get_storage_file_path()), "Test file was not created!")
     self.files_helper.remove_datatype(datatype) 
     self.assertFalse(os.path.exists(datatype.get_storage_file_path()), "Test file was not deleted!")      
Example #12
0
 def accepted_filters():
     filters = MappedType.accepted_filters()
     filters.update({
         'datatype_class._nr_dimensions': {
             'type': 'int',
             'display': 'Dimensionality',
             'operations': ['==', '<', '>']
         },
         'datatype_class._length_1d': {
             'type': 'int',
             'display': 'Shape 1',
             'operations': ['==', '<', '>']
         },
         'datatype_class._length_2d': {
             'type': 'int',
             'display': 'Shape 2',
             'operations': ['==', '<', '>']
         }
     })
     return filters
class MappedTypeStorageTests(unittest.TestCase):
    """
    Test class for testing mapped type data storage into file.
    Most of the storage functionality is tested in the test suite 
    of HDF5StorageManager 
    """
    def setUp(self):
        """
        Prepare data for tests
        """
        storage_folder = os.path.join(TvbProfile.current.TVB_STORAGE, "test_hdf5")

        if os.path.exists(storage_folder):
            shutil.rmtree(storage_folder)
        os.makedirs(storage_folder)
        
        # Create data type for which to store data
        self.data_type = MappedType()
        self.data_type.storage_path = storage_folder
        
        self.test_2D_array = numpy.random.random((10, 10))
        self.data_name = "vertex"

    def tearDown(self):
        """
        Clean up tests data
        """
        if os.path.exists(self.data_type.storage_path):
            shutil.rmtree(self.data_type.storage_path)
    
    def test_store_data(self):
        """
        Test data storage into file
        """
        self.data_type.store_data(self.data_name, self.test_2D_array)
        read_data = self.data_type.get_data(self.data_name)
        numpy.testing.assert_array_equal(self.test_2D_array, read_data, "Did not get the expected data")
    
    def test_store_chunked_data(self):
        """
        Test data storage into file, but splitted in chunks
        """
        self.data_type.store_data_chunk(self.data_name, self.test_2D_array)
        read_data = self.data_type.get_data(self.data_name)
        numpy.testing.assert_array_equal(self.test_2D_array, read_data, "Did not get the expected data")
    
    
    def test_set_metadata(self):
        """
        This test checks assignment of metadata to dataset or storage file  
        """
        # First create some data and check if it is stored
        self.data_type.store_data(self.data_name, self.test_2D_array)
        
        key = "meta_key"
        value = "meva_val"
        self.data_type.set_metadata({key: value}, self.data_name)
        read_meta_data = self.data_type.get_metadata(self.data_name)
        self.assertEqual(value, read_meta_data[key], "Meta value is not correct")
        
        # Now we'll store metadata on file /root node
        self.data_type.set_metadata({key: value})
        read_meta_data = self.data_type.get_metadata()
        self.assertEqual(value, read_meta_data[key], "Meta value is not correct")
        
    def test_remove_metadata(self):
        """
        This test checks removal of metadata from dataset 
        """
        # First create some data and check if it is stored
        self.data_type.store_data(self.data_name, self.test_2D_array)
        
        key = "meta_key"
        value = "meva_val"
        self.data_type.set_metadata({key: value}, self.data_name)
        read_meta_data = self.data_type.get_metadata(self.data_name)
        self.assertEqual(value, read_meta_data[key], "Meta value is not correct")
        
        # Now delete metadata
        self.data_type.remove_metadata(key, self.data_name)
        read_meta_data = self.data_type.get_metadata(self.data_name)
        self.assertEqual(0, len(read_meta_data), "There should be no metadata on node")
class MappedTypeStorageTests(unittest.TestCase):
    """
    Test class for testing mapped type data storage into file.
    Most of the storage functionality is tested in the test suite 
    of HDF5StorageManager 
    """
    def setUp(self):
        """
        Prepare data for tests
        """
        storage_folder = os.path.join(TvbProfile.current.TVB_STORAGE,
                                      "test_hdf5")

        if os.path.exists(storage_folder):
            shutil.rmtree(storage_folder)
        os.makedirs(storage_folder)

        # Create data type for which to store data
        self.data_type = MappedType()
        self.data_type.storage_path = storage_folder

        self.test_2D_array = numpy.random.random((10, 10))
        self.data_name = "vertex"

    def tearDown(self):
        """
        Clean up tests data
        """
        if os.path.exists(self.data_type.storage_path):
            shutil.rmtree(self.data_type.storage_path)

    def test_store_data(self):
        """
        Test data storage into file
        """
        self.data_type.store_data(self.data_name, self.test_2D_array)
        read_data = self.data_type.get_data(self.data_name)
        numpy.testing.assert_array_equal(self.test_2D_array, read_data,
                                         "Did not get the expected data")

    def test_store_chunked_data(self):
        """
        Test data storage into file, but splitted in chunks
        """
        self.data_type.store_data_chunk(self.data_name, self.test_2D_array)
        read_data = self.data_type.get_data(self.data_name)
        numpy.testing.assert_array_equal(self.test_2D_array, read_data,
                                         "Did not get the expected data")

    def test_set_metadata(self):
        """
        This test checks assignment of metadata to dataset or storage file  
        """
        # First create some data and check if it is stored
        self.data_type.store_data(self.data_name, self.test_2D_array)

        key = "meta_key"
        value = "meva_val"
        self.data_type.set_metadata({key: value}, self.data_name)
        read_meta_data = self.data_type.get_metadata(self.data_name)
        self.assertEqual(value, read_meta_data[key],
                         "Meta value is not correct")

        # Now we'll store metadata on file /root node
        self.data_type.set_metadata({key: value})
        read_meta_data = self.data_type.get_metadata()
        self.assertEqual(value, read_meta_data[key],
                         "Meta value is not correct")

    def test_remove_metadata(self):
        """
        This test checks removal of metadata from dataset 
        """
        # First create some data and check if it is stored
        self.data_type.store_data(self.data_name, self.test_2D_array)

        key = "meta_key"
        value = "meva_val"
        self.data_type.set_metadata({key: value}, self.data_name)
        read_meta_data = self.data_type.get_metadata(self.data_name)
        self.assertEqual(value, read_meta_data[key],
                         "Meta value is not correct")

        # Now delete metadata
        self.data_type.remove_metadata(key, self.data_name)
        read_meta_data = self.data_type.get_metadata(self.data_name)
        self.assertEqual(0, len(read_meta_data),
                         "There should be no metadata on node")
 def __init__(self, row1="test", row2="test"):
     MappedType.__init__(self)
     self.row1 = row1
     self.row2 = row2
Example #16
0
 def __init__(self, row1="test", row2="test"):
     MappedType.__init__(self)
     self.row1 = row1
     self.row2 = row2