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
18
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)))
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
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
155
156
163
164
171
172
179