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
18
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
36 data = create_rand_data(is_array_type, random_fnc)
37
38
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
177
178
185
186
193