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

Source Code for Module unittests.tuple_processor.tuple_writer_write_tests

  1  """ 
  2  This module implements the unit tests for 
  3  write of the atomic data types by 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 TupleWriterWriteRegressionTests(unittest.TestCase):
18
19 - def generic_test_write_data(self, schema, type_params, method_name):
20 """ 21 Tests whether random data types are successfully written by 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 comp_b = cStringIO.StringIO() 33 comp_b.write(struct_int2.pack(len(type_params))) #nFields 34 rand_tuple = [] 35 for (is_array_type, elm_size, random_fnc, elm_type, pack_fnc) in type_params: 36 # create data 37 data = create_rand_data(is_array_type, random_fnc) 38 39 #append to the tuple 40 rand_tuple.append(data) 41 42 #write data 43 write_rand_data(is_array_type, comp_b, data, elm_size, elm_type, pack_fnc) 44 45 ts = TupleSchema(schema) 46 tw = TupleWriter(b, ts) 47 tw.write_tuple(rand_tuple) 48 49 self.assertEqual(b.getvalue(), comp_b.getvalue(), method_name + ' fails')
50 51
53 """ 54 Tests whether tuples that only contain random char are successfully written by TupleWriter 55 """ 56 self.generic_test_write_data([charoid], [char_type_param], 'write_single_char_tuple')
57 58
60 """ 61 Tests whether tuples that only contain random bool are successfully written by TupleWriter 62 """ 63 self.generic_test_write_data([booloid], [bool_type_param], 'write_single_bool_tuple')
64 65
67 """ 68 Tests whether tuples that only contain random int2 are successfully written by TupleWriter 69 """ 70 self.generic_test_write_data([int2oid], [int2_type_param], 'write_single_int2_tuple')
71 72
74 """ 75 Tests whether tuples that only contain random int4 are successfully written by TupleWriter 76 """ 77 self.generic_test_write_data([int4oid], [int4_type_param], 'write_single_int4_tuple')
78 79
81 """ 82 Tests whether tuples that only contain random int8 are successfully written by TupleWriter 83 """ 84 self.generic_test_write_data([int8oid], [int8_type_param], 'write_single_int8_tuple')
85 86
88 """ 89 Tests whether tuples that only contain random float4 are successfully written by TupleWriter 90 """ 91 self.generic_test_write_data([float4oid], [float4_type_param], 'write_single_float4_tuple')
92 93
95 """ 96 Tests whether tuples that only contain random float8 are successfully written by TupleWriter 97 """ 98 self.generic_test_write_data([float8oid], [float8_type_param], 'write_single_float8_tuple')
99 100
102 """ 103 Tests whether tuples that only contain random char array are successfully written by TupleWriter 104 """ 105 self.generic_test_write_data([chararrayoid], [char_array_type_param], 'write_single_char_array_tuple')
106 107
109 """ 110 Tests whether tuples that only contain random bool array are successfully written by TupleWriter 111 """ 112 self.generic_test_write_data([boolarrayoid], [bool_array_type_param], 'write_single_bool_array_tuple')
113 114
116 """ 117 Tests whether tuples that only contain random int2 array are successfully written by TupleWriter 118 """ 119 self.generic_test_write_data([int2arrayoid], [int2_array_type_param], 'write_single_int2_array_tuple')
120 121
123 """ 124 Tests whether tuples that only contain random int4 array are successfully written by TupleWriter 125 """ 126 self.generic_test_write_data([int4arrayoid], [int4_array_type_param], 'write_single_int4_array_tuple')
127 128
130 """ 131 Tests whether tuples that only contain random int8 array are successfully written by TupleWriter 132 """ 133 self.generic_test_write_data([int8arrayoid], [int8_array_type_param], 'write_single_int8_array_tuple')
134 135
137 """ 138 Tests whether tuples that only contain random float4 array are successfully written by TupleWriter 139 """ 140 self.generic_test_write_data([float4arrayoid], [float4_array_type_param], 'write_single_float4_array_tuple')
141 142
144 """ 145 Tests whether tuples that only contain random float8 array are successfully written by TupleWriter 146 """ 147 self.generic_test_write_data([float8arrayoid], [float8_array_type_param], 'write_single_float8_array_tuple')
148 149
151 """ 152 Tests whether tuples that only contain random float8 2d array are successfully written by TupleWriter 153 """ 154 self.generic_test_write_data([float82darrayoid], [float8_2d_array_type_param], 'write_single_float8_2d_array_tuple')
155 156
158 """ 159 This method tests write 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_write_data, limit_test, without_sql)
163 164
166 """ 167 This method tests write 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_write_data, limit_test, without_sql)
171 172
173 - def test_tuples_with_data(self):
174 """ 175 This method tests write 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_write_data, limit_test, without_sql)
179