[3.6] bpo-28298: make array 'Q', 'L' and 'I' accept big intables as e… · python/cpython@26d013e (original) (raw)

`@@ -14,14 +14,6 @@

`

14

14

`import array

`

15

15

`from array import _array_reconstructor as array_reconstructor

`

16

16

``

17

``

`-

try:

`

18

``

`-

Try to determine availability of long long independently

`

19

``

`-

of the array module under test

`

20

``

`-

struct.calcsize('@q')

`

21

``

`-

have_long_long = True

`

22

``

`-

except struct.error:

`

23

``

`-

have_long_long = False

`

24

``

-

25

17

`sizeof_wchar = array.array('u').itemsize

`

26

18

``

27

19

``

`@@ -32,9 +24,7 @@ class ArraySubclassWithKwargs(array.array):

`

32

24

`def init(self, typecode, newarg=None):

`

33

25

`array.array.init(self)

`

34

26

``

35

``

`-

typecodes = "ubBhHiIlLfd"

`

36

``

`-

if have_long_long:

`

37

``

`-

typecodes += 'qQ'

`

``

27

`+

typecodes = 'ubBhHiIlLfdqQ'

`

38

28

``

39

29

`class MiscTest(unittest.TestCase):

`

40

30

``

`@@ -1240,7 +1230,26 @@ def test_frombytearray(self):

`

1240

1230

`b = array.array(self.typecode, a)

`

1241

1231

`self.assertEqual(a, b)

`

1242

1232

``

1243

``

`-

class SignedNumberTest(NumberTest):

`

``

1233

`+

class IntegerNumberTest(NumberTest):

`

``

1234

`+

def test_type_error(self):

`

``

1235

`+

a = array.array(self.typecode)

`

``

1236

`+

a.append(42)

`

``

1237

`+

with self.assertRaises(TypeError):

`

``

1238

`+

a.append(42.0)

`

``

1239

`+

with self.assertRaises(TypeError):

`

``

1240

`+

a[0] = 42.0

`

``

1241

+

``

1242

`+

class Intable:

`

``

1243

`+

def init(self, num):

`

``

1244

`+

self._num = num

`

``

1245

`+

def int(self):

`

``

1246

`+

return self._num

`

``

1247

`+

def sub(self, other):

`

``

1248

`+

return Intable(int(self) - int(other))

`

``

1249

`+

def add(self, other):

`

``

1250

`+

return Intable(int(self) + int(other))

`

``

1251

+

``

1252

`+

class SignedNumberTest(IntegerNumberTest):

`

1244

1253

`example = [-1, 0, 1, 42, 0x7f]

`

1245

1254

`smallerexample = [-1, 0, 1, 42, 0x7e]

`

1246

1255

`biggerexample = [-1, 0, 1, 43, 0x7f]

`

`@@ -1251,8 +1260,9 @@ def test_overflow(self):

`

1251

1260

`lower = -1 * int(pow(2, a.itemsize * 8 - 1))

`

1252

1261

`upper = int(pow(2, a.itemsize * 8 - 1)) - 1

`

1253

1262

`self.check_overflow(lower, upper)

`

``

1263

`+

self.check_overflow(Intable(lower), Intable(upper))

`

1254

1264

``

1255

``

`-

class UnsignedNumberTest(NumberTest):

`

``

1265

`+

class UnsignedNumberTest(IntegerNumberTest):

`

1256

1266

`example = [0, 1, 17, 23, 42, 0xff]

`

1257

1267

`smallerexample = [0, 1, 17, 23, 42, 0xfe]

`

1258

1268

`biggerexample = [0, 1, 17, 23, 43, 0xff]

`

`@@ -1263,6 +1273,7 @@ def test_overflow(self):

`

1263

1273

`lower = 0

`

1264

1274

`upper = int(pow(2, a.itemsize * 8)) - 1

`

1265

1275

`self.check_overflow(lower, upper)

`

``

1276

`+

self.check_overflow(Intable(lower), Intable(upper))

`

1266

1277

``

1267

1278

`def test_bytes_extend(self):

`

1268

1279

`s = bytes(self.example)

`

`@@ -1314,12 +1325,10 @@ class UnsignedLongTest(UnsignedNumberTest, unittest.TestCase):

`

1314

1325

`typecode = 'L'

`

1315

1326

`minitemsize = 4

`

1316

1327

``

1317

``

`-

@unittest.skipIf(not have_long_long, 'need long long support')

`

1318

1328

`class LongLongTest(SignedNumberTest, unittest.TestCase):

`

1319

1329

`typecode = 'q'

`

1320

1330

`minitemsize = 8

`

1321

1331

``

1322

``

`-

@unittest.skipIf(not have_long_long, 'need long long support')

`

1323

1332

`class UnsignedLongLongTest(UnsignedNumberTest, unittest.TestCase):

`

1324

1333

`typecode = 'Q'

`

1325

1334

`minitemsize = 8

`