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

Source Code for Module unittests.atomic_data_processor.atomic_data_processor_round_trip_tests

  1  """ 
  2  This module implements the unit tests for 
  3  read and write together 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 AtomicDataProcessorRoundTripRegressionTests(unittest.TestCase):
18
19 - def generic_test_round_trip_data(self, is_array_type, random_fnc, write_fnc, read_fnc, method_name):
20 """ 21 Tests whether random data types are successfully read and written 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 write_fnc: function 27 @param write_fnc: function in the atomic_data_processor to write the atomic data 28 @type read_fnc: function 29 @param read_fnc: function in the atomic_data_processor to read the atomic data 30 @type method_name: string 31 @param method_name: the name of the method who calls this generic method 32 """ 33 for i in range(test_num): 34 b = cStringIO.StringIO() 35 #create rand data 36 rand_data = create_rand_data(is_array_type, random_fnc) 37 write_fnc(b, rand_data) 38 ret_data = read_fnc(VictorBuffer(b.getvalue())) 39 #compare the data 40 compare_data(is_array_type, self, rand_data, ret_data, method_name, exact_equal)
41 42
43 - def test_round_trip_char(self):
44 """ 45 Tests whether random chars are successfully read and written by atomic_data_processor 46 """ 47 self.generic_test_round_trip_data(type_non_array, create_random_char, 48 Atomic_Data_Processor().write_char, 49 Atomic_Data_Processor().read_char, 'round_trip_char')
50 51 52
53 - def test_round_trip_bool(self):
54 """ 55 Tests whether random bools are successfully read and written by atomic_data_processor 56 """ 57 self.generic_test_round_trip_data(type_non_array, create_random_bool, 58 Atomic_Data_Processor().write_bool, 59 Atomic_Data_Processor().read_bool, 'round_trip_bool')
60 61
62 - def test_round_trip_int2(self):
63 """ 64 Tests whether random int2s are successfully read and written by atomic_data_processor 65 """ 66 self.generic_test_round_trip_data(type_non_array, create_random_int2, 67 Atomic_Data_Processor().write_int2, 68 Atomic_Data_Processor().read_int2, 'round_trip_int2')
69 70
71 - def test_round_trip_int4(self):
72 """ 73 Tests whether random int4s are successfully read and written by atomic_data_processor 74 """ 75 self.generic_test_round_trip_data(type_non_array, create_random_int4, 76 Atomic_Data_Processor().write_int4, 77 Atomic_Data_Processor().read_int4, 'round_trip_int4')
78 79
80 - def test_round_trip_int8(self):
81 """ 82 Tests whether random int8s are successfully read and written by atomic_data_processor 83 """ 84 self.generic_test_round_trip_data(type_non_array, create_random_int8, 85 Atomic_Data_Processor().write_int8, 86 Atomic_Data_Processor().read_int8, 'round_trip_int8')
87 88
89 - def test_round_trip_float4(self):
90 """ 91 Tests whether random float4s are successfully read and written by atomic_data_processor 92 """ 93 self.generic_test_round_trip_data(type_non_array, create_random_float4, 94 Atomic_Data_Processor().write_float4, 95 Atomic_Data_Processor().read_float4, 'round_trip_float4')
96 97
98 - def test_round_trip_float8(self):
99 """ 100 Tests whether random float8s are successfully read and written by atomic_data_processor 101 """ 102 self.generic_test_round_trip_data(type_non_array, create_random_float8, 103 Atomic_Data_Processor().write_float8, 104 Atomic_Data_Processor().read_float8, 'round_trip_float8')
105 106
108 """ 109 Tests whether random char arrays are successfully read and written by atomic_data_processor 110 """ 111 self.generic_test_round_trip_data(type_1d_array, create_random_char, 112 Atomic_Data_Processor().write_char_array, 113 Atomic_Data_Processor().read_char_array, 'round_trip_char_array')
114 115
117 """ 118 Tests whether random bool arrays are successfully read and written by atomic_data_processor 119 """ 120 self.generic_test_round_trip_data(type_1d_array, create_random_bool, 121 Atomic_Data_Processor().write_bool_array, 122 Atomic_Data_Processor().read_bool_array, 'round_trip_bool_array')
123 124
126 """ 127 Tests whether random int2 arrays are successfully read and written by atomic_data_processor 128 """ 129 self.generic_test_round_trip_data(type_1d_array, create_random_int2, 130 Atomic_Data_Processor().write_int2_array, 131 Atomic_Data_Processor().read_int2_array, 'round_trip_int2_array')
132 133
135 """ 136 Tests whether random int4 arrays are successfully read and written by atomic_data_processor 137 """ 138 self.generic_test_round_trip_data(type_1d_array, create_random_int4, 139 Atomic_Data_Processor().write_int4_array, 140 Atomic_Data_Processor().read_int4_array, 'round_trip_int4_array')
141 142
144 """ 145 Tests whether random int8 arrays are successfully read and written by atomic_data_processor 146 """ 147 self.generic_test_round_trip_data(type_1d_array, create_random_int8, 148 Atomic_Data_Processor().write_int8_array, 149 Atomic_Data_Processor().read_int8_array, 'round_trip_int8_array')
150 151
153 """ 154 Tests whether random float4 arrays are successfully read and written by atomic_data_processor 155 """ 156 self.generic_test_round_trip_data(type_1d_array, create_random_float4, 157 Atomic_Data_Processor().write_float4_array, 158 Atomic_Data_Processor().read_float4_array, 'round_trip_float4_array')
159 160
162 """ 163 Tests whether random float8 arrays are successfully read and written by atomic_data_processor 164 """ 165 self.generic_test_round_trip_data(type_1d_array, create_random_float8, 166 Atomic_Data_Processor().write_float8_array, 167 Atomic_Data_Processor().read_float8_array, 'round_trip_float8_array')
168 169
171 """ 172 Tests whether random float8 2d arrays are successfully read and written by atomic_data_processor 173 """ 174 self.generic_test_round_trip_data(type_2d_array, create_random_float8, 175 Atomic_Data_Processor().write_float8_2d_array, 176 Atomic_Data_Processor().read_float8_2d_array, 'round_trip_float8_2d_array')
177