From f1cb2819ebec58b27a6d1c02fbe7afd63f023b9f Mon Sep 17 00:00:00 2001 From: "Olivier J.N. Bertrand" <olivier.bertrand@uni-bielefeld.de> Date: Wed, 6 Jun 2018 17:12:00 +0200 Subject: [PATCH] Update test function the database access was done in a more complicated way than needed --- navipy/processing/test.py | 71 ++++++--------------------------------- 1 file changed, 10 insertions(+), 61 deletions(-) diff --git a/navipy/processing/test.py b/navipy/processing/test.py index 5b8218a..7aafffc 100644 --- a/navipy/processing/test.py +++ b/navipy/processing/test.py @@ -1,15 +1,15 @@ import unittest -import sqlite3 import numpy as np -import pandas as pd import navipy.database as database import navipy.processing.pcode as pcode from navipy.scene import is_numeric_array +from navipy import unittestlogger import pkg_resources class TestCase(unittest.TestCase): def setUp(self): + unittestlogger() self.mydb_filename = pkg_resources.resource_filename( 'navipy', 'resources/database.db') self.mydb = database.DataBaseLoad(self.mydb_filename) @@ -28,25 +28,8 @@ class TestCase(unittest.TestCase): posorient is of wrong type (dictionary instead of pd.series) empty posorient pd.series """ - conn = sqlite3.connect(self.mydb_filename) - c = conn.cursor() - 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] + posorients = self.mydb.posorients + posorient = posorients.loc[13, :] image = self.mydb.scene(posorient=posorient) self.assertIsNotNone(image) self.assertFalse(sum(image.shape) == 0) @@ -55,64 +38,30 @@ class TestCase(unittest.TestCase): self.assertTrue(image.shape[3] == 1) # incorrect case missing column - tuples2 = [('location', 'y'), - ('location', 'z'), (convention, 'alpha_0'), - (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] + posorient2 = posorients.loc[13, :] + posorient2.drop(('location', 'x'), inplace=True) with self.assertRaises(Exception): image = self.mydb.scene(posorient=posorient2) # incorrect case None - posorient2 = pd.Series(index=index) + posorient2 = posorients.loc[13, :] 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): image = self.mydb.scene(posorient=posorient2) # incorrect case nan - posorient2 = pd.Series(index=index) + posorient2 = posorients.loc[13, :] 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): image = self.mydb.scene(posorient=posorient2) # incorrect case no pandas series but dict 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): image = self.mydb.scene(posorient=posorient2) # not working case empty - 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']) - posorient2 = pd.Series(index=index) + posorient2 = posorients.loc[13, :]*np.nan with self.assertRaises(Exception): image = self.mydb.scene(posorient=posorient2) @@ -180,7 +129,7 @@ class TestCase(unittest.TestCase): self.mydb.scene(rowid=rowid) with self.assertRaises(TypeError): self.mydb.scene(rowid='T') - with self.assertRaises(TypeError): + with self.assertRaises(Exception): self.mydb.scene(rowid=None) with self.assertRaises(TypeError): self.mydb.scene(rowid=np.nan) -- GitLab