Skip to content
Snippets Groups Projects
Commit f1cb2819 authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Update test function

the database access was done in a more complicated way than needed
parent d097dff1
No related branches found
No related tags found
No related merge requests found
import unittest import unittest
import sqlite3
import numpy as np import numpy as np
import pandas as pd
import navipy.database as database import navipy.database as database
import navipy.processing.pcode as pcode import navipy.processing.pcode as pcode
from navipy.scene import is_numeric_array from navipy.scene import is_numeric_array
from navipy import unittestlogger
import pkg_resources import pkg_resources
class TestCase(unittest.TestCase): class TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
unittestlogger()
self.mydb_filename = pkg_resources.resource_filename( self.mydb_filename = pkg_resources.resource_filename(
'navipy', 'resources/database.db') 'navipy', 'resources/database.db')
self.mydb = database.DataBaseLoad(self.mydb_filename) self.mydb = database.DataBaseLoad(self.mydb_filename)
...@@ -28,25 +28,8 @@ class TestCase(unittest.TestCase): ...@@ -28,25 +28,8 @@ class TestCase(unittest.TestCase):
posorient is of wrong type (dictionary instead of pd.series) posorient is of wrong type (dictionary instead of pd.series)
empty posorient pd.series empty posorient pd.series
""" """
conn = sqlite3.connect(self.mydb_filename) posorients = self.mydb.posorients
c = conn.cursor() posorient = posorients.loc[13, :]
c.execute(""" SELECT * FROM position_orientation WHERE (rowid=1) """)
rows = c.fetchall()[0]
# working case
convention = 'rxyz'
tuples = [('location', 'x'), ('location', 'y'),
('location', 'z'), (convention, 'alpha_0'),
(convention, 'alpha_1'), (convention, 'alpha_2')]
index = pd.MultiIndex.from_tuples(tuples,
names=['position',
'orientation'])
posorient = pd.Series(index=index)
posorient['location']['x'] = rows[5]
posorient['location']['y'] = rows[6]
posorient['location']['z'] = rows[1]
posorient[convention]['alpha_0'] = rows[3]
posorient[convention]['alpha_1'] = rows[2]
posorient[convention]['alpha_2'] = rows[4]
image = self.mydb.scene(posorient=posorient) image = self.mydb.scene(posorient=posorient)
self.assertIsNotNone(image) self.assertIsNotNone(image)
self.assertFalse(sum(image.shape) == 0) self.assertFalse(sum(image.shape) == 0)
...@@ -55,64 +38,30 @@ class TestCase(unittest.TestCase): ...@@ -55,64 +38,30 @@ class TestCase(unittest.TestCase):
self.assertTrue(image.shape[3] == 1) self.assertTrue(image.shape[3] == 1)
# incorrect case missing column # incorrect case missing column
tuples2 = [('location', 'y'), posorient2 = posorients.loc[13, :]
('location', 'z'), (convention, 'alpha_0'), posorient2.drop(('location', 'x'), inplace=True)
(convention, 'alpha_1'), (convention, 'alpha_2')]
index2 = pd.MultiIndex.from_tuples(tuples2,
names=['position',
'orientation'])
posorient2 = pd.Series(index=index2)
posorient2['location']['y'] = rows[6]
posorient2['location']['z'] = rows[1]
posorient2[convention]['alpha_0'] = rows[3]
posorient2[convention]['alpha_1'] = rows[2]
posorient2[convention]['alpha_2'] = rows[4]
with self.assertRaises(Exception): with self.assertRaises(Exception):
image = self.mydb.scene(posorient=posorient2) image = self.mydb.scene(posorient=posorient2)
# incorrect case None # incorrect case None
posorient2 = pd.Series(index=index) posorient2 = posorients.loc[13, :]
posorient2['location']['x'] = None posorient2['location']['x'] = None
posorient2['location']['y'] = rows[6]
posorient2['location']['z'] = rows[1]
posorient2[convention]['alpha_0'] = rows[3]
posorient2[convention]['alpha_1'] = rows[2]
posorient2[convention]['alpha_2'] = rows[4]
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
image = self.mydb.scene(posorient=posorient2) image = self.mydb.scene(posorient=posorient2)
# incorrect case nan # incorrect case nan
posorient2 = pd.Series(index=index) posorient2 = posorients.loc[13, :]
posorient2['location']['x'] = np.nan posorient2['location']['x'] = np.nan
posorient2['location']['y'] = rows[6]
posorient2['location']['z'] = rows[1]
posorient2[convention]['alpha_0'] = rows[3]
posorient2[convention]['alpha_1'] = rows[2]
posorient2[convention]['alpha_2'] = rows[4]
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
image = self.mydb.scene(posorient=posorient2) image = self.mydb.scene(posorient=posorient2)
# incorrect case no pandas series but dict # incorrect case no pandas series but dict
posorient2 = {} posorient2 = {}
posorient2['location'] = {}
posorient2[convention] = {}
posorient2['location']['x'] = rows[5]
posorient2['location']['y'] = rows[6]
posorient2['location']['z'] = rows[1]
posorient2[convention]['alpha_0'] = rows[3]
posorient2[convention]['alpha_1'] = rows[2]
posorient2[convention]['alpha_2'] = rows[4]
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
image = self.mydb.scene(posorient=posorient2) image = self.mydb.scene(posorient=posorient2)
# not working case empty # not working case empty
tuples = [('location', 'x'), ('location', 'y'), posorient2 = posorients.loc[13, :]*np.nan
('location', 'z'), (convention, 'alpha_0'),
(convention, 'alpha_1'), (convention, 'alpha_2')]
index = pd.MultiIndex.from_tuples(tuples,
names=['position',
'orientation'])
posorient2 = pd.Series(index=index)
with self.assertRaises(Exception): with self.assertRaises(Exception):
image = self.mydb.scene(posorient=posorient2) image = self.mydb.scene(posorient=posorient2)
...@@ -180,7 +129,7 @@ class TestCase(unittest.TestCase): ...@@ -180,7 +129,7 @@ class TestCase(unittest.TestCase):
self.mydb.scene(rowid=rowid) self.mydb.scene(rowid=rowid)
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
self.mydb.scene(rowid='T') self.mydb.scene(rowid='T')
with self.assertRaises(TypeError): with self.assertRaises(Exception):
self.mydb.scene(rowid=None) self.mydb.scene(rowid=None)
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
self.mydb.scene(rowid=np.nan) self.mydb.scene(rowid=np.nan)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment