Back to index

python3.2  3.2.2
Public Member Functions
test.test_array.ArrayReconstructorTest Class Reference

List of all members.

Public Member Functions

def test_error
def test_numbers
def test_unicode

Detailed Description

Definition at line 68 of file test_array.py.


Member Function Documentation

Definition at line 70 of file test_array.py.

00070 
00071     def test_error(self):
00072         self.assertRaises(TypeError, array_reconstructor,
00073                           "", "b", 0, b"")
00074         self.assertRaises(TypeError, array_reconstructor,
00075                           str, "b", 0, b"")
00076         self.assertRaises(TypeError, array_reconstructor,
00077                           array.array, "b", '', b"")
00078         self.assertRaises(TypeError, array_reconstructor,
00079                           array.array, "b", 0, "")
00080         self.assertRaises(ValueError, array_reconstructor,
00081                           array.array, "?", 0, b"")
00082         self.assertRaises(ValueError, array_reconstructor,
00083                           array.array, "b", UNKNOWN_FORMAT, b"")
00084         self.assertRaises(ValueError, array_reconstructor,
00085                           array.array, "b", 22, b"")
00086         self.assertRaises(ValueError, array_reconstructor,
00087                           array.array, "d", 16, b"a")

Here is the call graph for this function:

Definition at line 88 of file test_array.py.

00088 
00089     def test_numbers(self):
00090         testcases = (
00091             (['B', 'H', 'I', 'L'], UNSIGNED_INT8, '=BBBB',
00092              [0x80, 0x7f, 0, 0xff]),
00093             (['b', 'h', 'i', 'l'], SIGNED_INT8, '=bbb',
00094              [-0x80, 0x7f, 0]),
00095             (['H', 'I', 'L'], UNSIGNED_INT16_LE, '<HHHH',
00096              [0x8000, 0x7fff, 0, 0xffff]),
00097             (['H', 'I', 'L'], UNSIGNED_INT16_BE, '>HHHH',
00098              [0x8000, 0x7fff, 0, 0xffff]),
00099             (['h', 'i', 'l'], SIGNED_INT16_LE, '<hhh',
00100              [-0x8000, 0x7fff, 0]),
00101             (['h', 'i', 'l'], SIGNED_INT16_BE, '>hhh',
00102              [-0x8000, 0x7fff, 0]),
00103             (['I', 'L'], UNSIGNED_INT32_LE, '<IIII',
00104              [1<<31, (1<<31)-1, 0, (1<<32)-1]),
00105             (['I', 'L'], UNSIGNED_INT32_BE, '>IIII',
00106              [1<<31, (1<<31)-1, 0, (1<<32)-1]),
00107             (['i', 'l'], SIGNED_INT32_LE, '<iii',
00108              [-1<<31, (1<<31)-1, 0]),
00109             (['i', 'l'], SIGNED_INT32_BE, '>iii',
00110              [-1<<31, (1<<31)-1, 0]),
00111             (['L'], UNSIGNED_INT64_LE, '<QQQQ',
00112              [1<<31, (1<<31)-1, 0, (1<<32)-1]),
00113             (['L'], UNSIGNED_INT64_BE, '>QQQQ',
00114              [1<<31, (1<<31)-1, 0, (1<<32)-1]),
00115             (['l'], SIGNED_INT64_LE, '<qqq',
00116              [-1<<31, (1<<31)-1, 0]),
00117             (['l'], SIGNED_INT64_BE, '>qqq',
00118              [-1<<31, (1<<31)-1, 0]),
00119             # The following tests for INT64 will raise an OverflowError
00120             # when run on a 32-bit machine. The tests are simply skipped
00121             # in that case.
00122             (['L'], UNSIGNED_INT64_LE, '<QQQQ',
00123              [1<<63, (1<<63)-1, 0, (1<<64)-1]),
00124             (['L'], UNSIGNED_INT64_BE, '>QQQQ',
00125              [1<<63, (1<<63)-1, 0, (1<<64)-1]),
00126             (['l'], SIGNED_INT64_LE, '<qqq',
00127              [-1<<63, (1<<63)-1, 0]),
00128             (['l'], SIGNED_INT64_BE, '>qqq',
00129              [-1<<63, (1<<63)-1, 0]),
00130             (['f'], IEEE_754_FLOAT_LE, '<ffff',
00131              [16711938.0, float('inf'), float('-inf'), -0.0]),
00132             (['f'], IEEE_754_FLOAT_BE, '>ffff',
00133              [16711938.0, float('inf'), float('-inf'), -0.0]),
00134             (['d'], IEEE_754_DOUBLE_LE, '<dddd',
00135              [9006104071832581.0, float('inf'), float('-inf'), -0.0]),
00136             (['d'], IEEE_754_DOUBLE_BE, '>dddd',
00137              [9006104071832581.0, float('inf'), float('-inf'), -0.0])
00138         )
00139         for testcase in testcases:
00140             valid_typecodes, mformat_code, struct_fmt, values = testcase
00141             arraystr = struct.pack(struct_fmt, *values)
00142             for typecode in valid_typecodes:
00143                 try:
00144                     a = array.array(typecode, values)
00145                 except OverflowError:
00146                     continue  # Skip this test case.
00147                 b = array_reconstructor(
00148                     array.array, typecode, mformat_code, arraystr)
00149                 self.assertEqual(a, b,
00150                     msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase))

Here is the call graph for this function:

Definition at line 151 of file test_array.py.

00151 
00152     def test_unicode(self):
00153         teststr = "Bonne Journ\xe9e \U0002030a\U00020347"
00154         testcases = (
00155             (UTF16_LE, "UTF-16-LE"),
00156             (UTF16_BE, "UTF-16-BE"),
00157             (UTF32_LE, "UTF-32-LE"),
00158             (UTF32_BE, "UTF-32-BE")
00159         )
00160         for testcase in testcases:
00161             mformat_code, encoding = testcase
00162             a = array.array('u', teststr)
00163             b = array_reconstructor(
00164                 array.array, 'u', mformat_code, teststr.encode(encoding))
00165             self.assertEqual(a, b,
00166                 msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase))
00167 
00168 
00169 tests.append(ArrayReconstructorTest)
00170 

Here is the call graph for this function:


The documentation for this class was generated from the following file: