Package unittests :: Package tuple_processor :: Module tuple_round_trip_tests
[hide private]
[frames] | no frames]

Source Code for Module unittests.tuple_processor.tuple_round_trip_tests

  1  """ 
  2  This module implements the unit tests for 
  3  read and write of the atomic data types by TupleReader and TupleWriter. 
  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  import cStringIO 
 16   
17 -class TupleRoundTripRegressionTests(unittest.TestCase):
18
19 - def generic_test_round_trip_data(self, schema, type_params, method_name):
20 """ 21 Tests whether random data types are successfully read and written by TupleReader and TupleWriter 22 @type schema: tuple 23 @param schema: represents the data types in the tuple 24 @type type_params: tuple 25 @param type_params: contains information(is_array_type, elm_size, random_fnc, elm_type, pack_fnc) 26 about each data type in the tuple. 27 @type method_name: string 28 @param method_name: the name of the method who calls this generic method 29 """ 30 for i in range(test_num): 31 b = cStringIO.StringIO() 32 33 rand_tuple = [] 34 for (is_array_type, elm_size, random_fnc, elm_type, pack_fnc) in type_params: 35 # create data 36 data = create_rand_data(is_array_type, random_fnc) 37 38 #append to the tuple 39 rand_tuple.append(data) 40 41 ts = TupleSchema(schema) 42 tw = TupleWriter(b, ts) 43 tw.write_tuple(rand_tuple) 44 tr = TupleReader(b.getvalue(), ts) 45 ret_tuple = tr.read_tuple() 46 47 compare_tuples(self, type_params, rand_tuple, ret_tuple, method_name, exact_equal)
48 49
51 """ 52 Tests whether tuples that only contain random char are successfully read and written 53 by TupleReader and TupleWriter 54 """ 55 self.generic_test_round_trip_data([charoid], [char_type_param], 'round_trip_single_char_tuple')
56 57
59 """ 60 Tests whether tuples that only contain random bool are successfully read and written 61 by TupleReader and TupleWriter 62 """ 63 self.generic_test_round_trip_data([booloid], [bool_type_param], 'round_trip_single_bool_tuple')
64 65
67 """ 68 Tests whether tuples that only contain random int2 are successfully read and written 69 by TupleReader and TupleWriter 70 """ 71 self.generic_test_round_trip_data([int2oid], [int2_type_param], 'round_trip_single_int2_tuple')
72 73
75 """ 76 Tests whether tuples that only contain random int4 are successfully read and written 77 by TupleReader and TupleWriter 78 """ 79 self.generic_test_round_trip_data([int4oid], [int4_type_param], 'round_trip_single_int4_tuple')
80 81
83 """ 84 Tests whether tuples that only contain random int8 are successfully read and written 85 by TupleReader and TupleWriter 86 """ 87 self.generic_test_round_trip_data([int8oid], [int8_type_param], 'round_trip_single_int8_tuple')
88 89
91 """ 92 Tests whether tuples that only contain random float4 are successfully read and written 93 by TupleReader and TupleWriter 94 """ 95 self.generic_test_round_trip_data([float4oid], [float4_type_param], 'round_trip_single_float4_tuple')
96 97
99 """ 100 Tests whether tuples that only contain random float8 are successfully read and written 101 by TupleReader and TupleWriter 102 """ 103 self.generic_test_round_trip_data([float8oid], [float8_type_param], 'round_trip_single_float8_tuple')
104 105
107 """ 108 Tests whether tuples that only contain random char array are successfully read and written 109 by TupleReader and TupleWriter 110 """ 111 self.generic_test_round_trip_data([chararrayoid], [char_array_type_param], 'round_trip_single_char_array_tuple')
112 113
115 """ 116 Tests whether tuples that only contain random bool array are successfully read and written 117 by TupleReader and TupleWriter 118 """ 119 self.generic_test_round_trip_data([boolarrayoid], [bool_array_type_param], 'round_trip_single_bool_array_tuple')
120 121
123 """ 124 Tests whether tuples that only contain random int2 array are successfully read and written 125 by TupleReader and TupleWriter 126 """ 127 self.generic_test_round_trip_data([int2arrayoid], [int2_array_type_param], 'round_trip_single_int2_array_tuple')
128 129
131 """ 132 Tests whether tuples that only contain random int4 array are successfully read and written 133 by TupleReader and TupleWriter 134 """ 135 self.generic_test_round_trip_data([int4arrayoid], [int4_array_type_param], 'round_trip_single_int4_array_tuple')
136 137
139 """ 140 Tests whether tuples that only contain random int8 array are successfully read and written 141 by TupleReader and TupleWriter 142 """ 143 self.generic_test_round_trip_data([int8arrayoid], [int8_array_type_param], 'round_trip_single_int8_array_tuple')
144 145
147 """ 148 Tests whether tuples that only contain random float4 array are successfully read and written 149 by TupleReader and TupleWriter 150 """ 151 self.generic_test_round_trip_data([float4arrayoid], [float4_array_type_param], 'round_trip_single_float4_array_tuple')
152 153
155 """ 156 Tests whether tuples that only contain random float8 array are successfully read and written 157 by TupleReader and TupleWriter 158 """ 159 self.generic_test_round_trip_data([float8arrayoid], [float8_array_type_param], 'round_trip_single_float8_array_tuple')
160 161
163 """ 164 Tests whether tuples that only contain random float8 2d array are successfully read and written 165 by TupleReader and TupleWriter 166 """ 167 self.generic_test_round_trip_data([float82darrayoid], [float8_2d_array_type_param], 168 'round_trip_single_float8_2d_array_tuple')
169 170
172 """ 173 This method tests read and write of tuples with possible non-array data type combinations. 174 Since there are 7 non-array data types, all combinations produce 127 different schema. 175 """ 176 test_tuples_with_non_array_data(self.generic_test_round_trip_data, limit_test, without_sql)
177 178
180 """ 181 This method tests read and write of tuples with possible array(1d or 2d) data type combinations. 182 Since there are 8 array data types, all combinations produce 255 different schema. 183 """ 184 test_tuples_with_array_data(self.generic_test_round_trip_data, limit_test, without_sql)
185 186
187 - def test_tuples_with_data(self):
188 """ 189 This method tests read and write of tuples with possible non-array and array(1d or 2d) data type combinations. 190 Since there are 15 data types, all combinations should produce 2 ** 15 - 1 different schema. 191 """ 192 test_tuples_with_data(self.generic_test_round_trip_data, limit_test, without_sql)
193