Trees | Indices | Help |
---|
|
1 """ 2 This module implements the unit tests for 3 read and write 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 171918321 """ 22 Tests whether random data types are successfully read and written by VictorDatabase 23 @type schema: tuple 24 @param schema: represents the data types in the tuple 25 @type type_params: tuple 26 @param type_params: contains information(is_array_type, elm_size, random_fnc, elm_type, pack_fnc, convert_sql_fnc, 27 sql_create_type) about each data type in the tuple. 28 @type method_name: string 29 @param method_name: the name of the method who calls this generic method 30 """ 31 db_conn = psycopg2.connect('dbname={0}'.format(dbname)) 32 cur = db_conn.cursor() 33 34 for i in range(test_num): 35 create_table_query = create_table_from_fields(type_params) 36 cur.execute(create_table_query) 37 38 all_tuples = [] 39 for j in range(tuple_size): 40 rand_tuple = [] 41 42 for (is_array_type, elm_size, random_fnc, elm_type, pack_fnc, convert_sql_fnc, sql_create_type) in type_params: 43 # create rand data 44 data = create_rand_data(is_array_type, random_fnc) 45 46 # append to the tuple 47 rand_tuple.append(data) 48 49 all_tuples.append(rand_tuple) 50 51 db_conn.commit() 52 53 vdb = VictorDatabase(cur, schema, temp_table_name, 1) 54 vdb.write_tuples(all_tuples) 55 vdb.flush() 56 vdb = VictorDatabase(cur, schema, temp_table_name, 1) 57 ret_tuples = vdb.read_tuples() 58 59 compare_set_of_tuples(self, type_params, all_tuples, ret_tuples, method_name, exact_equal)60 6163 """ 64 Tests whether tuples that only contain random char are successfully read and written by VictorDatabase 65 """ 66 self.generic_test_round_trip_data([charoid], [char_vdb_type_param], 'round_trip_single_char_type')67 6870 """ 71 Tests whether tuples that only contain random bool are successfully read and written by VictorDatabase 72 """ 73 self.generic_test_round_trip_data([booloid], [bool_vdb_type_param], 'round_trip_single_bool_type')74 7577 """ 78 Tests whether tuples that only contain random int2 are successfully read and written by VictorDatabase 79 """ 80 self.generic_test_round_trip_data([int2oid], [int2_vdb_type_param], 'round_trip_single_int2_type')81 8284 """ 85 Tests whether tuples that only contain random int4 are successfully read and written by VictorDatabase 86 """ 87 self.generic_test_round_trip_data([int4oid], [int4_vdb_type_param], 'round_trip_single_int4_type')88 8991 """ 92 Tests whether tuples that only contain random int8 are successfully read and written by VictorDatabase 93 """ 94 self.generic_test_round_trip_data([int8oid], [int8_vdb_type_param], 'round_trip_single_int8_type')95 9698 """ 99 Tests whether tuples that only contain random float4 are successfully read and written by VictorDatabase 100 """ 101 self.generic_test_round_trip_data([float4oid], [float4_vdb_type_param], 'round_trip_single_float4_type')102 103105 """ 106 Tests whether tuples that only contain random float8 are successfully read and written by VictorDatabase 107 """ 108 self.generic_test_round_trip_data([float8oid], [float8_vdb_type_param], 'round_trip_single_float8_type')109 110112 """ 113 Tests whether tuples that only contain random bool array are successfully read and written by VictorDatabase 114 """ 115 self.generic_test_round_trip_data([boolarrayoid], [bool_array_vdb_type_param], 'round_trip_single_bool_array_type')116 117119 """ 120 Tests whether tuples that only contain random int2 array are successfully read and written by VictorDatabase 121 """ 122 self.generic_test_round_trip_data([int2arrayoid], [int2_array_vdb_type_param], 'round_trip_single_int2_array_type')123 124126 """ 127 Tests whether tuples that only contain random int4 array are successfully read and written by VictorDatabase 128 """ 129 self.generic_test_round_trip_data([int4arrayoid], [int4_array_vdb_type_param], 'round_trip_single_int4_array_type')130 131133 """ 134 Tests whether tuples that only contain random int8 array are successfully read and written by VictorDatabase 135 """ 136 self.generic_test_round_trip_data([int8arrayoid], [int8_array_vdb_type_param], 'round_trip_single_int8_array_type')137 138140 """ 141 Tests whether tuples that only contain random float4 array are successfully read and written by VictorDatabase 142 """ 143 self.generic_test_round_trip_data([float4arrayoid], [float4_array_vdb_type_param], 'round_trip_single_float4_array_type')144 145147 """ 148 Tests whether tuples that only contain random float8 array are successfully read and written by VictorDatabase 149 """ 150 self.generic_test_round_trip_data([float8arrayoid], [float8_array_vdb_type_param], 'round_trip_single_float8_array_type')151 152154 """ 155 Tests whether tuples that only contain random float8 2d array are successfully read and written by VictorDatabase 156 """ 157 self.generic_test_round_trip_data([float82darrayoid], [float8_2d_array_vdb_type_param], 158 'round_trip_single_float8_2d_array_type')159 160162 """ 163 This method tests read and write of tuples with possible non-array data type combinations. 164 Since there are 7 non-array data types, all combinations produce 127 different schema. 165 """ 166 test_tuples_with_non_array_data(self.generic_test_round_trip_data, limit_test, with_sql)167 168170 """ 171 This method tests read and write of tuples with possible array(1d or 2d) data type combinations. 172 Since there are 7 array data types, all combinations produce 127 different schema. 173 """ 174 test_tuples_with_array_data(self.generic_test_round_trip_data, limit_test, with_sql)175 176178 """ 179 This method tests read and write of tuples with possible non-array and array(1d or 2d) data type combinations. 180 Since there are 14 data types, all combinations should produce 2 ** 14 - 1 different schema. 181 """ 182 test_tuples_with_data(self.generic_test_round_trip_data, limit_test, with_sql)
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Feb 28 00:56:45 2011 | http://epydoc.sourceforge.net |