Package unittests :: Package victor_database :: Module victor_database_read_tests
[hide private]
[frames] | no frames]

Source Code for Module unittests.victor_database.victor_database_read_tests

  1  """ 
  2  This module implements the unit tests for 
  3  read of the atomic data types by VictorDatabase. 
  4  """ 
  5   
  6  import random 
  7  import unittest 
  8  import StringIO 
  9  import HTMLTestRunner 
 10  import traceback 
 11  import sys 
 12   
 13  from unittest_helper import * 
 14  from tuple_processor import * 
 15  from psql_util import * 
 16  import cStringIO 
 17   
 18   
19 -class VictorDBReadRegressionTests(unittest.TestCase):
20
21 - def generic_test_read_data(self, schema, type_params, method_name):
22 """ 23 Tests whether random data types are successfully read by VictorDatabase 24 @type schema: tuple 25 @param schema: represents the data types in the tuple 26 @type type_params: tuple 27 @param type_params: contains information(is_array_type, elm_size, random_fnc, elm_type, pack_fnc, convert_sql_fnc, 28 sql_create_type) about each data type in the tuple. 29 @type method_name: string 30 @param method_name: the name of the method who calls this generic method 31 """ 32 db_conn = psycopg2.connect('dbname={0}'.format(dbname)) 33 cur = db_conn.cursor() 34 35 for i in range(test_num): 36 create_table_query = create_table_from_fields(type_params) 37 cur.execute(create_table_query) 38 39 all_tuples = [] 40 for j in range(tuple_size): 41 rand_tuple = [] 42 converted_data = [] 43 insert_query = 'INSERT INTO ' + temp_table_name + ' VALUES (' 44 for (is_array_type, elm_size, random_fnc, elm_type, pack_fnc, convert_sql_fnc, sql_create_type) in type_params: 45 # create rand data 46 data = create_rand_data(is_array_type, random_fnc) 47 48 # append to the tuple 49 rand_tuple.append(data) 50 converted_data.append(convert_sql_fnc(data)) 51 52 53 insert_query += ','.join(converted_data) 54 insert_query += ');' 55 cur.execute(insert_query) 56 all_tuples.append(rand_tuple) 57 58 db_conn.commit() 59 60 vdb = VictorDatabase(cur, schema, temp_table_name, 1) 61 ret_tuples = vdb.read_tuples() 62 63 compare_set_of_tuples(self, type_params, all_tuples, ret_tuples, method_name, exact_equal)
64 65
67 """ 68 Tests whether tuples that only contain random char are successfully read by VictorDatabase 69 """ 70 self.generic_test_read_data([charoid], [char_vdb_type_param], 'read_single_char_type')
71 72
74 """ 75 Tests whether tuples that only contain random bool are successfully read by VictorDatabase 76 """ 77 self.generic_test_read_data([booloid], [bool_vdb_type_param], 'read_single_bool_type')
78 79
81 """ 82 Tests whether tuples that only contain random int2 are successfully read by VictorDatabase 83 """ 84 self.generic_test_read_data([int2oid], [int2_vdb_type_param], 'read_single_int2_type')
85 86
88 """ 89 Tests whether tuples that only contain random int4 are successfully read by VictorDatabase 90 """ 91 self.generic_test_read_data([int4oid], [int4_vdb_type_param], 'read_single_int4_type')
92 93
95 """ 96 Tests whether tuples that only contain random int8 are successfully read by VictorDatabase 97 """ 98 self.generic_test_read_data([int8oid], [int8_vdb_type_param], 'read_single_int8_type')
99 100
102 """ 103 Tests whether tuples that only contain random float4 are successfully read by VictorDatabase 104 """ 105 self.generic_test_read_data([float4oid], [float4_vdb_type_param], 'read_single_float4_type')
106 107
109 """ 110 Tests whether tuples that only contain random float8 are successfully read by VictorDatabase 111 """ 112 self.generic_test_read_data([float8oid], [float8_vdb_type_param], 'read_single_float8_type')
113 114
116 """ 117 Tests whether tuples that only contain random bool array are successfully read by VictorDatabase 118 """ 119 self.generic_test_read_data([boolarrayoid], [bool_array_vdb_type_param], 'read_single_bool_array_type')
120 121
123 """ 124 Tests whether tuples that only contain random int2 array are successfully reand by VictorDatabase 125 """ 126 self.generic_test_read_data([int2arrayoid], [int2_array_vdb_type_param], 'read_single_int2_array_type')
127 128
130 """ 131 Tests whether tuples that only contain random int4 array are successfully read by VictorDatabase 132 """ 133 self.generic_test_read_data([int4arrayoid], [int4_array_vdb_type_param], 'read_single_int4_array_type')
134 135
137 """ 138 Tests whether tuples that only contain random int8 array are successfully read by VictorDatabase 139 """ 140 self.generic_test_read_data([int8arrayoid], [int8_array_vdb_type_param], 'read_single_int8_array_type')
141 142
144 """ 145 Tests whether tuples that only contain random float4 array are successfully read by VictorDatabase 146 """ 147 self.generic_test_read_data([float4arrayoid], [float4_array_vdb_type_param], 'read_single_float4_array_type')
148 149
151 """ 152 Tests whether tuples that only contain random float8 array are successfully read by VictorDatabase 153 """ 154 self.generic_test_read_data([float8arrayoid], [float8_array_vdb_type_param], 'read_single_float8_array_type')
155 156
158 """ 159 Tests whether tuples that only contain random float8 2d array are successfully read by VictorDatabase 160 """ 161 self.generic_test_read_data([float82darrayoid], [float8_2d_array_vdb_type_param], 'read_single_float8_2d_array_type')
162 163
165 """ 166 This method tests read of tuples with possible non-array data type combinations. 167 Since there are 7 non-array data types, all combinations produce 127 different schema. 168 """ 169 test_tuples_with_non_array_data(self.generic_test_read_data, limit_test, with_sql)
170 171
173 """ 174 This method tests read of tuples with possible array(1d or 2d) data type combinations. 175 Since there are 7 array data types, all combinations produce 127 different schema. 176 """ 177 test_tuples_with_array_data(self.generic_test_read_data, limit_test, with_sql)
178 179
180 - def test_tuples_with_data(self):
181 """ 182 This method tests read of tuples with possible non-array and array(1d or 2d) data type combinations. 183 Since there are 14 data types, all combinations should produce 2 ** 14 - 1 different schema. 184 """ 185 test_tuples_with_data(self.generic_test_read_data, limit_test, with_sql)
186