Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(29619)

Side by Side Diff: Lib/test/test_array.py

Issue 1172711: long long support for array module
Patch Set: Created 8 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 """Test the arraymodule. 2 """Test the arraymodule.
3 Roger E. Masse 3 Roger E. Masse
4 """ 4 """
5 5
6 import unittest 6 import unittest
7 from test import support 7 from test import support
8 import weakref 8 import weakref
9 import pickle 9 import pickle
10 import operator 10 import operator
11 import io 11 import io
12 import math 12 import math
13 import struct 13 import struct
14 import warnings 14 import warnings
15 15
16 import array 16 import array
17 from array import _array_reconstructor as array_reconstructor 17 from array import _array_reconstructor as array_reconstructor
18 18
19 try:
20 # Try to determine availability of long long independently
21 # of the array module under test
22 struct.calcsize('@q')
23 have_long_long = True
24 except struct.error:
25 have_long_long = False
19 26
20 class ArraySubclass(array.array): 27 class ArraySubclass(array.array):
21 pass 28 pass
22 29
23 class ArraySubclassWithKwargs(array.array): 30 class ArraySubclassWithKwargs(array.array):
24 def __init__(self, typecode, newarg=None): 31 def __init__(self, typecode, newarg=None):
25 array.array.__init__(self) 32 array.array.__init__(self)
26 33
27 tests = [] # list to accumulate all tests 34 tests = [] # list to accumulate all tests
28 typecodes = "ubBhHiIlLfd" 35 typecodes = "ubBhHiIlLfd"
36 if have_long_long:
37 typecodes += 'qQ'
29 38
30 class BadConstructorTest(unittest.TestCase): 39 class BadConstructorTest(unittest.TestCase):
31 40
32 def test_constructor(self): 41 def test_constructor(self):
33 self.assertRaises(TypeError, array.array) 42 self.assertRaises(TypeError, array.array)
34 self.assertRaises(TypeError, array.array, spam=42) 43 self.assertRaises(TypeError, array.array, spam=42)
35 self.assertRaises(TypeError, array.array, 'xx') 44 self.assertRaises(TypeError, array.array, 'xx')
36 self.assertRaises(ValueError, array.array, 'x') 45 self.assertRaises(ValueError, array.array, 'x')
37 46
38 tests.append(BadConstructorTest) 47 tests.append(BadConstructorTest)
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 1206
1198 class LongTest(SignedNumberTest): 1207 class LongTest(SignedNumberTest):
1199 typecode = 'l' 1208 typecode = 'l'
1200 minitemsize = 4 1209 minitemsize = 4
1201 tests.append(LongTest) 1210 tests.append(LongTest)
1202 1211
1203 class UnsignedLongTest(UnsignedNumberTest): 1212 class UnsignedLongTest(UnsignedNumberTest):
1204 typecode = 'L' 1213 typecode = 'L'
1205 minitemsize = 4 1214 minitemsize = 4
1206 tests.append(UnsignedLongTest) 1215 tests.append(UnsignedLongTest)
1216
1217 @unittest.skipIf(not have_long_long, 'need long long support')
1218 class LongLongTest(SignedNumberTest):
1219 typecode = 'q'
1220 minitemsize = 8
1221 tests.append(LongLongTest)
1222
1223 @unittest.skipIf(not have_long_long, 'need long long support')
1224 class UnsignedLongLongTest(UnsignedNumberTest):
1225 typecode = 'Q'
1226 minitemsize = 8
1227 tests.append(UnsignedLongLongTest)
1207 1228
1208 class FPTest(NumberTest): 1229 class FPTest(NumberTest):
1209 example = [-42.0, 0, 42, 1e5, -1e10] 1230 example = [-42.0, 0, 42, 1e5, -1e10]
1210 smallerexample = [-42.0, 0, 42, 1e5, -2e10] 1231 smallerexample = [-42.0, 0, 42, 1e5, -2e10]
1211 biggerexample = [-42.0, 0, 42, 1e5, 1e10] 1232 biggerexample = [-42.0, 0, 42, 1e5, 1e10]
1212 outside = 23 1233 outside = 23
1213 1234
1214 def assertEntryEqual(self, entry1, entry2): 1235 def assertEntryEqual(self, entry1, entry2):
1215 self.assertAlmostEqual(entry1, entry2) 1236 self.assertAlmostEqual(entry1, entry2)
1216 1237
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 import gc 1289 import gc
1269 counts = [None] * 5 1290 counts = [None] * 5
1270 for i in range(len(counts)): 1291 for i in range(len(counts)):
1271 support.run_unittest(*tests) 1292 support.run_unittest(*tests)
1272 gc.collect() 1293 gc.collect()
1273 counts[i] = sys.gettotalrefcount() 1294 counts[i] = sys.gettotalrefcount()
1274 print(counts) 1295 print(counts)
1275 1296
1276 if __name__ == "__main__": 1297 if __name__ == "__main__":
1277 test_main(verbose=True) 1298 test_main(verbose=True)
OLDNEW
« no previous file with comments | « Doc/library/array.rst ('k') | Modules/arraymodule.c » ('j') | Modules/arraymodule.c » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+