Package unittests :: Package victor_file :: Module victor_file_read_tests
[hide private]
[frames] | no frames]

Source Code for Module unittests.victor_file.victor_file_read_tests

  1  """ 
  2  This module implements the unit tests for 
  3  read of the atomic data types by VictorFile. 
  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  import mmap_wrapper 
 19   
20 -class VictorFileReadRegressionTests(unittest.TestCase):
21
22 - def generic_test_read_data(self, schema, type_params, method_name):
23 """ 24 Tests whether random data types are successfully read by VictorFile 25 @type schema: tuple 26 @param schema: represents the data types in the tuple 27 @type type_params: tuple 28 @param type_params: contains information(is_array_type, elm_size, random_fnc, elm_type, pack_fnc, convert_sql_fnc, 29 sql_create_type) about each data type in the tuple. 30 @type method_name: string 31 @param method_name: the name of the method who calls this generic method 32 """ 33 db_conn = psycopg2.connect('dbname={0}'.format(dbname)) 34 cur = db_conn.cursor() 35 36 for i in range(test_num): 37 create_table_query = create_table_from_fields(type_params) 38 cur.execute(create_table_query) 39 40 all_tuples = [] 41 for j in range(tuple_size): 42 rand_tuple = [] 43 converted_data = [] 44 insert_query = 'INSERT INTO ' + temp_table_name + ' VALUES (' 45 for (is_array_type, elm_size, random_fnc, elm_type, pack_fnc, convert_sql_fnc, sql_create_type) in type_params: 46 # create rand data 47 data = create_rand_data(is_array_type, random_fnc) 48 49 # append to the tuple 50 rand_tuple.append(data) 51 converted_data.append(convert_sql_fnc(data)) 52 53 54 insert_query += ','.join(converted_data) 55 insert_query += ');' 56 cur.execute(insert_query) 57 all_tuples.append(rand_tuple) 58 59 db_conn.commit() 60 61 b = cStringIO.StringIO() 62 cur.copy_expert("COPY " + temp_table_name + " TO STDOUT WITH BINARY;", b) 63 f = open(temp_file_name, "wb") 64 f.write(b.getvalue()) 65 f.close() 66 f = open(temp_file_name, "r+b") 67 mem_map = mmap_wrapper.MMapWrapper(f.fileno(), 0, mmap_wrapper.READ_MODE) 68 69 vdb = VictorFile(mem_map, schema, mmap_wrapper.READ_MODE) 70 t = time.time() 71 ret_tuples = vdb.read_tuples() 72 73 compare_set_of_tuples(self, type_params, all_tuples, ret_tuples, method_name, exact_equal)
74 75
77 """ 78 Tests whether tuples that only contain random char are successfully read by VictorFile 79 """ 80 self.generic_test_read_data([charoid], [char_vdb_type_param], 'read_single_char_type')
81 82
84 """ 85 Tests whether tuples that only contain random bool are successfully read by VictorFile 86 """ 87 self.generic_test_read_data([booloid], [bool_vdb_type_param], 'read_single_bool_type')
88 89
91 """ 92 Tests whether tuples that only contain random int2 are successfully read by VictorFile 93 """ 94 self.generic_test_read_data([int2oid], [int2_vdb_type_param], 'read_single_int2_type')
95 96
98 """ 99 Tests whether tuples that only contain random int4 are successfully read by VictorFile 100 """ 101 self.generic_test_read_data([int4oid], [int4_vdb_type_param], 'read_single_int4_type')
102 103
105 """ 106 Tests whether tuples that only contain random int8 are successfully read by VictorFile 107 """ 108 self.generic_test_read_data([int8oid], [int8_vdb_type_param], 'read_single_int8_type')
109 110
112 """ 113 Tests whether tuples that only contain random float4 are successfully read by VictorFile 114 """ 115 self.generic_test_read_data([float4oid], [float4_vdb_type_param], 'read_single_float4_type')
116 117
119 """ 120 Tests whether tuples that only contain random float8 are successfully read by VictorFile 121 """ 122 self.generic_test_read_data([float8oid], [float8_vdb_type_param], 'read_single_float8_type')
123 124
126 """ 127 Tests whether tuples that only contain random bool array are successfully read by VictorFile 128 """ 129 self.generic_test_read_data([boolarrayoid], [bool_array_vdb_type_param], 'read_single_bool_array_type')
130 131
133 """ 134 Tests whether tuples that only contain random int2 array are successfully read by VictorFile 135 """ 136 self.generic_test_read_data([int2arrayoid], [int2_array_vdb_type_param], 'read_single_int2_array_type')
137 138
140 """ 141 Tests whether tuples that only contain random int4 array are successfully read by VictorFile 142 """ 143 self.generic_test_read_data([int4arrayoid], [int4_array_vdb_type_param], 'read_single_int4_array_type')
144 145
147 """ 148 Tests whether tuples that only contain random int8 array are successfully read by VictorFile 149 """ 150 self.generic_test_read_data([int8arrayoid], [int8_array_vdb_type_param], 'read_single_int8_array_type')
151 152
154 """ 155 Tests whether tuples that only contain random float4 array are successfully read by VictorFile 156 """ 157 self.generic_test_read_data([float4arrayoid], [float4_array_vdb_type_param], 'read_single_float4_array_type')
158 159
161 """ 162 Tests whether tuples that only contain random float8 array are successfully read by VictorFile 163 """ 164 self.generic_test_read_data([float8arrayoid], [float8_array_vdb_type_param], 'read_single_float8_array_type')
165 166
168 """ 169 Tests whether tuples that only contain random float8 2d array are successfully read by VictorFile 170 """ 171 self.generic_test_read_data([float82darrayoid], [float8_2d_array_vdb_type_param], 'read_single_float8_2d_array_type')
172 173
175 """ 176 This method tests read of tuples with possible non-array data type combinations. 177 Since there are 7 non-array data types, all combinations produce 127 different schema. 178 """ 179 test_tuples_with_non_array_data(self.generic_test_read_data, limit_test, with_sql)
180 181
183 """ 184 This method tests read of tuples with possible array(1d or 2d) data type combinations. 185 Since there are 7 array data types, all combinations produce 127 different schema. 186 """ 187 test_tuples_with_array_data(self.generic_test_read_data, limit_test, with_sql)
188 189
190 - def test_tuples_with_data(self):
191 """ 192 This method tests read of tuples with possible non-array and array(1d or 2d) data type combinations. 193 Since there are 14 data types, all combinations should produce 2 ** 14 - 1 different schema. 194 """ 195 test_tuples_with_data(self.generic_test_read_data, limit_test, with_sql)
196