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

Source Code for Module unittests.victor_file.victor_file_round_trip_tests

  1  """ 
  2  This module implements the unit tests for 
  3  read and write 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 
 19  import mmap_wrapper 
 20   
21 -class VictorFileRoundTripRegressionTests(unittest.TestCase):
22
23 - def generic_test_round_trip_data(self, schema, type_params, method_name):
24 """ 25 Tests whether random data types are successfully read and written by VictorFile 26 @type schema: tuple 27 @param schema: represents the data types in the tuple 28 @type type_params: tuple 29 @param type_params: contains information(is_array_type, elm_size, random_fnc, elm_type, pack_fnc, convert_sql_fnc, 30 sql_create_type) about each data type in the tuple. 31 @type method_name: string 32 @param method_name: the name of the method who calls this generic method 33 """ 34 db_conn = psycopg2.connect('dbname={0}'.format(dbname)) 35 cur = db_conn.cursor() 36 37 for i in range(test_num): 38 create_table_query = create_table_from_fields(type_params) 39 cur.execute(create_table_query) 40 41 all_tuples = [] 42 for j in range(tuple_size): 43 rand_tuple = [] 44 converted_data = [] 45 46 for (is_array_type, elm_size, random_fnc, elm_type, pack_fnc, convert_sql_fnc, sql_create_type) in type_params: 47 # create rand data 48 data = create_rand_data(is_array_type, random_fnc) 49 50 # append to the tuple 51 rand_tuple.append(data) 52 53 all_tuples.append(rand_tuple) 54 55 db_conn.commit() 56 57 try: 58 f = open(temp_file_name, "r+b") 59 except IOError: 60 f = open(temp_file_name, "wb") 61 f.write("t") 62 f.close() 63 f = open(temp_file_name, "r+b") 64 65 mem_map = mmap_wrapper.MMapWrapper(f.fileno(), 0, mmap_wrapper.WRITE_MODE, True) 66 67 vdb = VictorFile(mem_map, schema, mmap_wrapper.WRITE_MODE) 68 vdb.write_tuples(all_tuples) 69 vdb.flush() 70 f = open(temp_file_name, "r+b") 71 mem_map = mmap_wrapper.MMapWrapper(f.fileno(), 0, mmap_wrapper.READ_MODE) 72 73 vdb = VictorFile(mem_map, schema, mmap_wrapper.READ_MODE) 74 ret_tuples = vdb.read_tuples() 75 76 compare_set_of_tuples(self, type_params, all_tuples, ret_tuples, method_name, exact_equal)
77 78
80 """ 81 Tests whether tuples that only contain random char are successfully read and written by VictorFile 82 """ 83 self.generic_test_round_trip_data([charoid], [char_vdb_type_param], 'round_trip_single_char_type')
84 85
87 """ 88 Tests whether tuples that only contain random bool are successfully read and written by VictorFile 89 """ 90 self.generic_test_round_trip_data([booloid], [bool_vdb_type_param], 'round_trip_single_bool_type')
91 92
94 """ 95 Tests whether tuples that only contain random int2 are successfully read and written by VictorFile 96 """ 97 self.generic_test_round_trip_data([int2oid], [int2_vdb_type_param], 'round_trip_single_int2_type')
98 99
101 """ 102 Tests whether tuples that only contain random int4 are successfully read and written by VictorFile 103 """ 104 self.generic_test_round_trip_data([int4oid], [int4_vdb_type_param], 'round_trip_single_int4_type')
105 106
108 """ 109 Tests whether tuples that only contain random int8 are successfully read and written by VictorFile 110 """ 111 self.generic_test_round_trip_data([int8oid], [int8_vdb_type_param], 'round_trip_single_int8_type')
112 113
115 """ 116 Tests whether tuples that only contain random float4 are successfully read and written by VictorFile 117 """ 118 self.generic_test_round_trip_data([float4oid], [float4_vdb_type_param], 'round_trip_single_float4_type')
119 120
122 """ 123 Tests whether tuples that only contain random float8 are successfully read and written by VictorFile 124 """ 125 self.generic_test_round_trip_data([float8oid], [float8_vdb_type_param], 'round_trip_single_float8_type')
126 127
129 """ 130 Tests whether tuples that only contain random bool array are successfully read and written by VictorFile 131 """ 132 self.generic_test_round_trip_data([boolarrayoid], [bool_array_vdb_type_param], 'round_trip_single_bool_array_type')
133 134
136 """ 137 Tests whether tuples that only contain random int2 array are successfully read and written by VictorFile 138 """ 139 self.generic_test_round_trip_data([int2arrayoid], [int2_array_vdb_type_param], 'round_trip_single_int2_array_type')
140 141
143 """ 144 Tests whether tuples that only contain random int4 array are successfully read and written by VictorFile 145 """ 146 self.generic_test_round_trip_data([int4arrayoid], [int4_array_vdb_type_param], 'round_trip_single_int4_array_type')
147 148
150 """ 151 Tests whether tuples that only contain random int8 array are successfully read and written by VictorFile 152 """ 153 self.generic_test_round_trip_data([int8arrayoid], [int8_array_vdb_type_param], 'round_trip_single_int8_array_type')
154 155
157 """ 158 Tests whether tuples that only contain random float4 array are successfully read and written by VictorFile 159 """ 160 self.generic_test_round_trip_data([float4arrayoid], [float4_array_vdb_type_param], 'round_trip_single_float4_array_type')
161 162
164 """ 165 Tests whether tuples that only contain random float8 array are successfully read and written by VictorFile 166 """ 167 self.generic_test_round_trip_data([float8arrayoid], [float8_array_vdb_type_param], 'round_trip_single_float8_array_type')
168 169
171 """ 172 Tests whether tuples that only contain random float8 2d array are successfully read and written by VictorFile 173 """ 174 self.generic_test_round_trip_data([float82darrayoid], [float8_2d_array_vdb_type_param], 175 'round_trip_single_float8_2d_array_type')
176 177
179 """ 180 This method tests read and write of tuples with possible non-array data type combinations. 181 Since there are 7 non-array data types, all combinations produce 127 different schema. 182 """ 183 test_tuples_with_non_array_data(self.generic_test_round_trip_data, limit_test, with_sql)
184 185
187 """ 188 This method tests read and write of tuples with possible array(1d or 2d) data type combinations. 189 Since there are 7 array data types, all combinations produce 127 different schema. 190 """ 191 test_tuples_with_array_data(self.generic_test_round_trip_data, limit_test, with_sql)
192 193
194 - def test_tuples_with_data(self):
195 """ 196 This method tests read and write of tuples with possible non-array and array(1d or 2d) data type combinations. 197 Since there are 14 data types, all combinations should produce 2 ** 14 - 1 different schema. 198 """ 199 test_tuples_with_data(self.generic_test_round_trip_data, limit_test, with_sql)
200