Package unittests :: Package atomic_data_processor :: Module atomic_data_processor_read_tests
[hide private]
[frames] | no frames]

Source Code for Module unittests.atomic_data_processor.atomic_data_processor_read_tests

  1  """ 
  2  This module implements the unit tests for 
  3  read of the atomic data types. 
  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 AtomicDataProcessorReadRegressionTests(unittest.TestCase):
18 - def generic_test_read_data(self, is_array_type, random_fnc, elm_size, elm_type, pack_fnc, 19 read_fnc, method_name):
20 """ 21 Tests whether random data types are successfully read by atomic_data_processor 22 @type is_array_type: number 23 @param is_array_type: whether data type is non-array, 1d array or 2d array 24 @type random_fnc: function 25 @param random_fnc: random function that creates a random atomic data 26 @type elm_size: number 27 @param elm_size: Size of the atomic type (e.g. char is 1) 28 @type elm_type: number 29 @param elm_type: oid of the data type 30 @type pack_fnc: function 31 @param pack_fnc: pack function that converts atomic data to the binary representation 32 @type read_fnc: function 33 @param read_fnc: function in the atomic_data_processor to read the atomic data 34 @type method_name: string 35 @param method_name: the name of the method who calls this generic method 36 """ 37 for i in range(test_num): 38 b = cStringIO.StringIO() 39 #create rand data 40 rand_data = create_rand_data(is_array_type, random_fnc) 41 #write rand data to the buffer 42 write_rand_data(is_array_type, b, rand_data, elm_size, elm_type, pack_fnc) 43 44 # create victor buf 45 victor_buf = VictorBuffer(b.getvalue()) 46 # read data 47 ret_data = read_fnc(victor_buf) 48 49 compare_data(is_array_type, self, rand_data, ret_data, method_name, exact_equal)
50 51
52 - def test_read_char(self):
53 """ 54 Tests whether random chars are successfully read by atomic_data_processor 55 """ 56 self.generic_test_read_data(type_non_array, create_random_char, oid_dict[charoid][data_size_field], 57 charoid, struct_char.pack, Atomic_Data_Processor().read_char, 'read_char')
58
59 - def test_read_bool(self):
60 """ 61 Tests whether random bools are successfully read by atomic_data_processor 62 """ 63 self.generic_test_read_data(type_non_array, create_random_bool, oid_dict[booloid][data_size_field], 64 booloid, struct_bool.pack, Atomic_Data_Processor().read_bool, 'read_bool')
65
66 - def test_read_int2(self):
67 """ 68 Tests whether random int2s are successfully read by atomic_data_processor 69 """ 70 self.generic_test_read_data(type_non_array, create_random_int2, oid_dict[int2oid][data_size_field], 71 int2oid, struct_int2.pack, Atomic_Data_Processor().read_int2, 'read_int2')
72 73
74 - def test_read_int4(self):
75 """ 76 Tests whether random int4s are successfully read by atomic_data_processor 77 """ 78 self.generic_test_read_data(type_non_array, create_random_int4, oid_dict[int4oid][data_size_field], 79 int4oid, struct_int4.pack, Atomic_Data_Processor().read_int4, 'read_int4')
80 81
82 - def test_read_int8(self):
83 """ 84 Tests whether random int8s are successfully read by atomic_data_processor 85 """ 86 self.generic_test_read_data(type_non_array, create_random_int8, oid_dict[int8oid][data_size_field], 87 int8oid, struct_int8.pack, Atomic_Data_Processor().read_int8, 'read_int8')
88 89
90 - def test_read_float4(self):
91 """ 92 Tests whether random float4s are successfully read by atomic_data_processor 93 """ 94 self.generic_test_read_data(type_non_array, create_random_float4, oid_dict[float4oid][data_size_field], 95 float4oid, struct_float4.pack, Atomic_Data_Processor().read_float4, 'read_float4')
96 97
98 - def test_read_float8(self):
99 """ 100 Tests whether random float8s are successfully read by atomic_data_processor 101 """ 102 self.generic_test_read_data(type_non_array, create_random_float8, oid_dict[float8oid][data_size_field], 103 float8oid, struct_float8.pack, Atomic_Data_Processor().read_float8, 'read_float8')
104 105
106 - def test_read_char_array(self):
107 """ 108 Tests whether random char arrays are successfully read by atomic_data_processor 109 """ 110 self.generic_test_read_data(type_1d_array, create_random_char, oid_dict[charoid][data_size_field], 111 charoid, struct_char.pack, Atomic_Data_Processor().read_char_array, 'read_char_array')
112 113
114 - def test_read_bool_array(self):
115 """ 116 Tests whether random bool arrays are successfully read by atomic_data_processor 117 """ 118 self.generic_test_read_data(type_1d_array, create_random_bool, oid_dict[booloid][data_size_field], 119 booloid, struct_bool.pack, Atomic_Data_Processor().read_bool_array, 'read_bool_array')
120 121
122 - def test_read_int2_array(self):
123 """ 124 Tests whether random int2 arrays are successfully read by atomic_data_processor 125 """ 126 self.generic_test_read_data(type_1d_array, create_random_int2, oid_dict[int2oid][data_size_field], 127 int2oid, struct_int2.pack, Atomic_Data_Processor().read_int2_array, 'read_int2_array')
128 129
130 - def test_read_int4_array(self):
131 """ 132 Tests whether random int4 arrays are successfully read by atomic_data_processor 133 """ 134 self.generic_test_read_data(type_1d_array, create_random_int4, oid_dict[int4oid][data_size_field], 135 int4oid, struct_int4.pack, Atomic_Data_Processor().read_int4_array, 'read_int4_array')
136 137
138 - def test_read_int8_array(self):
139 """ 140 Tests whether random int8 arrays are successfully read by atomic_data_processor 141 """ 142 self.generic_test_read_data(type_1d_array, create_random_int8, oid_dict[int8oid][data_size_field], 143 int8oid, struct_int8.pack, Atomic_Data_Processor().read_int8_array, 'read_int8_array')
144 145
146 - def test_read_float4_array(self):
147 """ 148 Tests whether random float4 arrays are successfully read by atomic_data_processor 149 """ 150 self.generic_test_read_data(type_1d_array, create_random_float4, oid_dict[float4oid][data_size_field], 151 float4oid, struct_float4.pack, Atomic_Data_Processor().read_float4_array, 'read_float4_array')
152 153
154 - def test_read_float8_array(self):
155 """ 156 Tests whether random float8 arrays are successfully read by atomic_data_processor 157 """ 158 self.generic_test_read_data(type_1d_array, create_random_float8, oid_dict[float8oid][data_size_field], 159 float8oid, struct_float8.pack, Atomic_Data_Processor().read_float8_array, 'read_float8_array')
160
162 """ 163 Tests whether random float8 2d arrays are successfully read by atomic_data_processor 164 """ 165 self.generic_test_read_data(type_2d_array, create_random_float8, oid_dict[float8oid][data_size_field], 166 float8oid, struct_float8.pack, Atomic_Data_Processor().read_float8_2d_array, 167 'read_float8_2d_array')
168