Commit 3a20a5de authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #20546: Use specific asserts in int tests.

parent 016a3f33
...@@ -130,7 +130,7 @@ class LongTest(unittest.TestCase): ...@@ -130,7 +130,7 @@ class LongTest(unittest.TestCase):
# The sign of the number is also random. # The sign of the number is also random.
def getran(self, ndigits): def getran(self, ndigits):
self.assertTrue(ndigits > 0) self.assertGreater(ndigits, 0)
nbits_hi = ndigits * SHIFT nbits_hi = ndigits * SHIFT
nbits_lo = nbits_hi - SHIFT + 1 nbits_lo = nbits_hi - SHIFT + 1
answer = 0 answer = 0
...@@ -865,21 +865,21 @@ class LongTest(unittest.TestCase): ...@@ -865,21 +865,21 @@ class LongTest(unittest.TestCase):
def test_small_ints(self): def test_small_ints(self):
for i in range(-5, 257): for i in range(-5, 257):
self.assertTrue(i is i + 0) self.assertIs(i, i + 0)
self.assertTrue(i is i * 1) self.assertIs(i, i * 1)
self.assertTrue(i is i - 0) self.assertIs(i, i - 0)
self.assertTrue(i is i // 1) self.assertIs(i, i // 1)
self.assertTrue(i is i & -1) self.assertIs(i, i & -1)
self.assertTrue(i is i | 0) self.assertIs(i, i | 0)
self.assertTrue(i is i ^ 0) self.assertIs(i, i ^ 0)
self.assertTrue(i is ~~i) self.assertIs(i, ~~i)
self.assertTrue(i is i**1) self.assertIs(i, i**1)
self.assertTrue(i is int(str(i))) self.assertIs(i, int(str(i)))
self.assertTrue(i is i<<2>>2, str(i)) self.assertIs(i, i<<2>>2, str(i))
# corner cases # corner cases
i = 1 << 70 i = 1 << 70
self.assertTrue(i - i is 0) self.assertIs(i - i, 0)
self.assertTrue(0 * i is 0) self.assertIs(0 * i, 0)
def test_bit_length(self): def test_bit_length(self):
tiny = 1e-10 tiny = 1e-10
...@@ -926,7 +926,7 @@ class LongTest(unittest.TestCase): ...@@ -926,7 +926,7 @@ class LongTest(unittest.TestCase):
got = round(k+offset, -1) got = round(k+offset, -1)
expected = v+offset expected = v+offset
self.assertEqual(got, expected) self.assertEqual(got, expected)
self.assertTrue(type(got) is int) self.assertIs(type(got), int)
# larger second argument # larger second argument
self.assertEqual(round(-150, -2), -200) self.assertEqual(round(-150, -2), -200)
...@@ -965,7 +965,7 @@ class LongTest(unittest.TestCase): ...@@ -965,7 +965,7 @@ class LongTest(unittest.TestCase):
got = round(10**k + 324678, -3) got = round(10**k + 324678, -3)
expect = 10**k + 325000 expect = 10**k + 325000
self.assertEqual(got, expect) self.assertEqual(got, expect)
self.assertTrue(type(got) is int) self.assertIs(type(got), int)
# nonnegative second argument: round(x, n) should just return x # nonnegative second argument: round(x, n) should just return x
for n in range(5): for n in range(5):
...@@ -973,7 +973,7 @@ class LongTest(unittest.TestCase): ...@@ -973,7 +973,7 @@ class LongTest(unittest.TestCase):
x = random.randrange(-10000, 10000) x = random.randrange(-10000, 10000)
got = round(x, n) got = round(x, n)
self.assertEqual(got, x) self.assertEqual(got, x)
self.assertTrue(type(got) is int) self.assertIs(type(got), int)
for huge_n in 2**31-1, 2**31, 2**63-1, 2**63, 2**100, 10**100: for huge_n in 2**31-1, 2**31, 2**63-1, 2**63, 2**100, 10**100:
self.assertEqual(round(8979323, huge_n), 8979323) self.assertEqual(round(8979323, huge_n), 8979323)
...@@ -982,7 +982,7 @@ class LongTest(unittest.TestCase): ...@@ -982,7 +982,7 @@ class LongTest(unittest.TestCase):
x = random.randrange(-10000, 10000) x = random.randrange(-10000, 10000)
got = round(x) got = round(x)
self.assertEqual(got, x) self.assertEqual(got, x)
self.assertTrue(type(got) is int) self.assertIs(type(got), int)
# bad second argument # bad second argument
bad_exponents = ('brian', 2.0, 0j, None) bad_exponents = ('brian', 2.0, 0j, None)
...@@ -1187,15 +1187,15 @@ class LongTest(unittest.TestCase): ...@@ -1187,15 +1187,15 @@ class LongTest(unittest.TestCase):
class myint(int): class myint(int):
pass pass
self.assertTrue(type(myint.from_bytes(b'\x00', 'big')) is myint) self.assertIs(type(myint.from_bytes(b'\x00', 'big')), myint)
self.assertEqual(myint.from_bytes(b'\x01', 'big'), 1) self.assertEqual(myint.from_bytes(b'\x01', 'big'), 1)
self.assertTrue( self.assertIs(
type(myint.from_bytes(b'\x00', 'big', signed=False)) is myint) type(myint.from_bytes(b'\x00', 'big', signed=False)), myint)
self.assertEqual(myint.from_bytes(b'\x01', 'big', signed=False), 1) self.assertEqual(myint.from_bytes(b'\x01', 'big', signed=False), 1)
self.assertTrue(type(myint.from_bytes(b'\x00', 'little')) is myint) self.assertIs(type(myint.from_bytes(b'\x00', 'little')), myint)
self.assertEqual(myint.from_bytes(b'\x01', 'little'), 1) self.assertEqual(myint.from_bytes(b'\x01', 'little'), 1)
self.assertTrue(type(myint.from_bytes( self.assertIs(type(myint.from_bytes(
b'\x00', 'little', signed=False)) is myint) b'\x00', 'little', signed=False)), myint)
self.assertEqual(myint.from_bytes(b'\x01', 'little', signed=False), 1) self.assertEqual(myint.from_bytes(b'\x01', 'little', signed=False), 1)
self.assertEqual( self.assertEqual(
int.from_bytes([255, 0, 0], 'big', signed=True), -65536) int.from_bytes([255, 0, 0], 'big', signed=True), -65536)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment