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

Source Code for Module unittests.tuple_processor.tuple_reader_read_tests

  1  """ 
  2  This module implements the unit tests for 
  3  read of the atomic data types by TupleReader. 
  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 TupleReaderReadRegressionTests(unittest.TestCase):
18
19 - def generic_test_read_data(self, schema, type_params, method_name):
20 """ 21 Tests whether random data types are successfully read by TupleReader 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 b.write(struct_int2.pack(len(type_params))) #nFields 33 rand_tuple = [] 34 for (is_array_type, elm_size, random_fnc, elm_type, pack_fnc) in type_params: 35 #create rand data 36 data = create_rand_data(is_array_type, random_fnc) 37 38 # append to the tuple 39 rand_tuple.append(data) 40 41 #write data 42 write_rand_data(is_array_type, b, data, elm_size, elm_type, pack_fnc) 43 44 ts = TupleSchema(schema) 45 tr = TupleReader(b.getvalue(), ts) 46 ret_tuple = tr.read_tuple() 47 48 compare_tuples(self, type_params, rand_tuple, ret_tuple, method_name, exact_equal)
49 50 51
53 """ 54 Tests whether tuples that only contain random char are successfully read by TupleReader 55 """ 56 self.generic_test_read_data([charoid], [char_type_param], 'read_single_char_tuple')
57 58
60 """ 61 Tests whether tuples that only contain random bool are successfully read by TupleReader 62 """ 63 self.generic_test_read_data([booloid], [bool_type_param], 'read_single_bool_tuple')
64 65
67 """ 68 Tests whether tuples that only contain random int2 are successfully read by TupleReader 69 """ 70 self.generic_test_read_data([int2oid], [int2_type_param], 'read_single_int2_tuple')
71 72
74 """ 75 Tests whether tuples that only contain random int4 are successfully read by TupleReader 76 """ 77 self.generic_test_read_data([int4oid], [int4_type_param], 'read_single_int4_tuple')
78 79
81 """ 82 Tests whether tuples that only contain random int8 are successfully read by TupleReader 83 """ 84 self.generic_test_read_data([int8oid], [int8_type_param], 'read_single_int8_tuple')
85 86
88 """ 89 Tests whether tuples that only contain random float4 are successfully read by TupleReader 90 """ 91 self.generic_test_read_data([float4oid], [float4_type_param], 'read_single_float4_tuple')
92 93
95 """ 96 Tests whether tuples that only contain random float8 are successfully read by TupleReader 97 """ 98 self.generic_test_read_data([float8oid], [float8_type_param], 'read_single_float8_tuple')
99 100
102 """ 103 Tests whether tuples that only contain random char array are successfully read by TupleReader 104 """ 105 self.generic_test_read_data([chararrayoid], [char_array_type_param], 'read_single_char_array_tuple')
106 107
109 """ 110 Tests whether tuples that only contain random bool array are successfully read by TupleReader 111 """ 112 self.generic_test_read_data([boolarrayoid], [bool_array_type_param], 'read_single_bool_array_tuple')
113 114
116 """ 117 Tests whether tuples that only contain random int2 array are successfully read by TupleReader 118 """ 119 self.generic_test_read_data([int2arrayoid], [int2_array_type_param], 'read_single_int2_array_tuple')
120 121
123 """ 124 Tests whether tuples that only contain random int4 array are successfully read by TupleReader 125 """ 126 self.generic_test_read_data([int4arrayoid], [int4_array_type_param], 'read_single_int4_array_tuple')
127 128
130 """ 131 Tests whether tuples that only contain random int8 array are successfully read by TupleReader 132 """ 133 self.generic_test_read_data([int8arrayoid], [int8_array_type_param], 'read_single_int8_array_tuple')
134 135
137 """ 138 Tests whether tuples that only contain random float4 array are successfully read by TupleReader 139 """ 140 self.generic_test_read_data([float4arrayoid], [float4_array_type_param], 'read_single_float4_array_tuple')
141 142
144 """ 145 Tests whether tuples that only contain random float8 array are successfully read by TupleReader 146 """ 147 self.generic_test_read_data([float8arrayoid], [float8_array_type_param], 'read_single_float8_array_tuple')
148 149
151 """ 152 Tests whether tuples that only contain random float8 2d array are successfully read by TupleReader 153 """ 154 self.generic_test_read_data([float82darrayoid], [float8_2d_array_type_param], 'read_single_float8_2d_array_tuple')
155 156
158 """ 159 This method tests read of tuples with possible non-array data type combinations. 160 Since there are 7 non-array data types, all combinations produce 127 different schema. 161 """ 162 test_tuples_with_non_array_data(self.generic_test_read_data, limit_test, without_sql)
163 164
166 """ 167 This method tests read of tuples with possible array(1d or 2d) data type combinations. 168 Since there are 8 array data types, all combinations produce 255 different schema. 169 """ 170 test_tuples_with_array_data(self.generic_test_read_data, limit_test, without_sql)
171 172
173 - def test_tuples_with_data(self):
174 """ 175 This method tests read of tuples with possible non-array and array(1d or 2d) data type combinations. 176 Since there are 15 data types, all combinations should produce 2 ** 15 - 1 different schema. 177 """ 178 test_tuples_with_data(self.generic_test_read_data, limit_test, without_sql)
179