Coverage for navipy/database/test.py : 57%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# from navipy.processing.tools import is_numeric_array
'navipy', 'resources/database2.db')
""" this test checks the initialization of a DataBase works correctly. it checks if correct errors are raised for: - a database file with out .db ending is used for initialization - wrong types are passed for the database name i.e. integers, floats, none, nan """ # filename must end with .db # filename must be string
# only works if testdb was created before e.g. with DataBase # with self.assertRaises(NameError): # DataBase('test')
""" this test checks the initialization of a DataBase works correctly. it checks if correct errors are raised for: - channels names, which are no strings or chars - channel name is None value or nan """ # channels must be strings or char
""" this test checks if the function table_exists works correctly it checks if correct errors are raised for: - a database name that are not of type string or char i.e. integer, float, none, nan - Attention: in this test the check for a table that existed did not work correctly (False was returned) """ # self.assertFalse(self.mydb.table_exist('testblubb')) # self.assertFalse(self.mydb.table_exist(self.mydb_filename))
""" this test checks the function data validity works correctly. It should return true if the database contains data in the row, that is checked for it checks if correct errors are raised for: - row numbers that are not integers. i.e. float non, nan (must be integer) - row is out of range; smaller or equal to 0 - checks if true is returned for an exiting entry (row=1) """
""" this test checks the function get_posid works correctly. it checks if correct errors are raised for: - posorient is missing an entry (no 'x' column) - posorient contains nan or none values - posorient is of wrong type (dict instead of pd.series) """ conn = sqlite3.connect(self.mydb_filename) c = conn.cursor() c.execute(""" SELECT * FROM position_orientation WHERE (rowid=1) """) rows = c.fetchall()[0] # convention = rows[1]
tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient = pd.Series(index=index) posorient['location']['x'] = rows[6] posorient['location']['y'] = rows[7] posorient['location']['z'] = rows[8] posorient['xyz']['alpha_0'] = rows[3] posorient['xyz']['alpha_1'] = rows[5] posorient['xyz']['alpha_2'] = rows[4]
posid = self.mydb.get_posid(posorient) assert posid == 1
# incorrect case missing column tuples = [('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index) posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4]
with self.assertRaises(Exception): posid = self.mydb.get_posid(posorient2)
# incorrect case None tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(self.tuples, names=['position', 'orientation'])
posorient3 = pd.Series(index=index) posorient3['location']['x'] = None posorient3['location']['y'] = rows[7] posorient3['location']['z'] = rows[8] posorient3['xyz']['alpha_0'] = rows[3] posorient3['xyz']['alpha_1'] = rows[5] posorient3['xyz']['alpha_2'] = rows[4] with self.assertRaises(ValueError): posid = self.mydb.get_posid(posorient2)
# incorrect case nan tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(self.tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index) posorient2['location']['x'] = np.nan posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(ValueError): posid = self.mydb.get_posid(posorient2)
# incorrect case no pandas series but dict posorient2 = {} posorient2['location']['x'] = rows[6] posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(TypeError): self.mydb.get_posid(posorient2)
# not working case empty tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(self.tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index)
with self.assertRaises(Exception): self.mydb.get_posid(posorient2)
""" this test checks the function read_posorient works correctly. it checks if correct errors are raised for: - posorient is missing an entry (no 'x' column) - posorient contains nan or none values - posorient is of wrong type (dict instead of pd.series) """ # working case ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] names=['position', 'orientation'])
# print(posid) assert posid['location']['x'] == posorient['location']['x']
# incorrect case missing column tuples = [('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index) posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(ValueError): self.mydb.read_posorient(posorient=posorient2)
# incorrect case None tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index) posorient2['location']['x'] = None posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(ValueError): self.mydb.read_posorient(posorient=posorient2)
# incorrect case nan tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index) posorient2['location']['x'] = np.nan posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(ValueError): self.mydb.read_posorient(posorient=posorient2)
# incorrect case no pandas series but dict posorient2 = {} posorient2['location'] = {} posorient2['xyz'] = {} posorient2['location']['x'] = rows[6] posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(TypeError): self.mydb.read_posorient(posorient=posorient2)
# not working case empty tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index)
with self.assertRaises(Exception): self.mydb.read_posorient(posorient=posorient2)
""" this test checks the function read_posorient works correctly. it checks if correct errors are raised for: - rowid is out of range (<=0) - rowid is of type char, none, nan, float and checks if the returned entry for rowid 1 is correct - that it all columns and correct values """ # working case ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] names=['position', 'orientation'])
# print("rowid",rowid)
assert posoriend2['location']['y'] == posorient['location']['y'] assert posoriend2['location']['z'] == posorient['location']['z'] assert (posoriend2['xyz']['alpha_0'] == posorient['xyz']['alpha_0']) assert (posoriend2['xyz']['alpha_1'] == posorient['xyz']['alpha_1']) assert (posoriend2['xyz']['alpha_2'] == posorient['xyz']['alpha_2'])
""" this test checks the function scene works correctly. it checks if correct errors are raised for: - rowid is out of range (<=0) - rowid is of type char, none, nan, float
and checks if the returned entry for different rows is correct - has correct shape - does not contain nans """ # print("rowid",rowid)
# image=np.array(image)
""" this test checks the function scene works correctly. it checks if correct errors are raised for: - posorient is missing an entry (no 'x' column) - posorient contains nan or none values - posorient is of wrong type (dict instead of pd.series) """ # working case ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] names=['position', 'orientation']) self.assertIsNotNone(image) self.assertFalse(sum(image.shape) == 0) # print("shape",image.shape) self.assertTrue(len(image.shape) == 4) self.assertTrue(image.shape[3] == 1)
# incorrect case missing column tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index) posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(Exception): image = self.mydb.scene(posorient=posorient2)
# incorrect case None tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index) posorient2['location']['x'] = None posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(ValueError): image = self.mydb.scene(posorient=posorient2)
# incorrect case nan tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), ('xyz', 'alpha_0'), ('xyz', 'alpha_1'), ('xyz', 'alpha_2')] index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index) posorient2['location']['x'] = np.nan posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(ValueError): image = self.mydb.scene(posorient=posorient2)
# incorrect case no pandas series but dict posorient2 = {} posorient2['location'] = {} posorient2['xyz'] = {} posorient2['location']['x'] = rows[6] posorient2['location']['y'] = rows[7] posorient2['location']['z'] = rows[8] posorient2['xyz']['alpha_0'] = rows[3] posorient2['xyz']['alpha_1'] = rows[5] posorient2['xyz']['alpha_2'] = rows[4] with self.assertRaises(TypeError): image = self.mydb.scene(posorient=posorient2)
# not working case empty index = pd.MultiIndex.from_tuples(tuples, names=['position', 'orientation'])
posorient2 = pd.Series(index=index)
with self.assertRaises(Exception): image = self.mydb.scene(posorient=posorient2)
""" this test checks the function denormalise_image works correctly. it checks if correct errors are raised for: - image has wrong type (list instead of np.ndarray) - image does not have enough dimensions - image contains nan values - image has to many dimensions - cminmax range is missing one channel - cminmax range is empty pd.series - cminmax range is dictionary - cminmax contains nans """ 'G_min', 'G_max', 'G_range', 'B_min', 'B_max', 'B_range', 'D_min', 'D_max', 'D_range'])
# not working
# image2 = image # image2[23,34,0] = 'addsf' # with self.assertRaises(ValueError): # denormed=self.mydb.denormalise_image(image2,cminmaxrange)
'B_min', 'B_max', 'B_range', 'D_min', 'D_max', 'D_range'])
'G_min', 'G_max', 'G_range', 'B_min', 'B_max', 'B_range', 'D_min', 'D_max', 'D_range']) # cminmaxrange3.R_min = [] # cminmaxrange3.R_max = [] # cminmaxrange3.R_range = [] # cminmaxrange3.G_min = [] # cminmaxrange3.G_max = [] # cminmaxrange3.G_range = [] # cminmaxrange3.B_min = [] # cminmaxrange3.B_max = [] # cminmaxrange3.B_range = [] # cminmaxrange3.D_min = [] # cminmaxrange3.D_max = [] # cminmaxrange3.D_range = []
""" this test checks the function normalise_image works correctly. it checks if correct errors are raised for: - image is of wrong type (list) - image has wrong dimensionality (too big, too small) - image contains nan values """
# not working
"""image2 = image.copy() image2[23,34,0] = 'addsf' with self.assertRaises(ValueError): denormed=loadDB.normalise_image(image2)"""
""" this test checks the function insert_replace works correctly. it checks if correct errors are raised for: - filename is of type integer, float, nan or none - filename does not exist in database/params are wrong """
unittest.main() |