Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update tests for builtin objects to python 3.12.8 #5481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/ctypes/test/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ def test_alignments(self):

# alignment of the type...
self.assertEqual((code, alignment(t)),
(code, align))
(code, align))
# and alignment of an instance
self.assertEqual((code, alignment(t())),
(code, align))
(code, align))

def test_int_from_address(self):
from array import array
Expand Down
17 changes: 17 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2555,3 +2555,20 @@ def adjust_int_max_str_digits(max_digits):
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
'skipped on s390x')
HAVE_ASAN_FORK_BUG = check_sanitizer(address=True)

# From python 3.12.8
class BrokenIter:
def __init__(self, init_raises=False, next_raises=False, iter_raises=False):
if init_raises:
1/0
self.next_raises = next_raises
self.iter_raises = iter_raises

def __next__(self):
if self.next_raises:
1/0

def __iter__(self):
if self.iter_raises:
1/0
return self
32 changes: 16 additions & 16 deletions Lib/test/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def check(s):
with self.assertRaises(ValueError, msg='float(%r)' % (s,)) as cm:
float(s)
self.assertEqual(str(cm.exception),
'could not convert string to float: %r' % (s,))
'could not convert string to float: %r' % (s,))

check('\xbd')
check('123\xbd')
Expand All @@ -155,7 +155,9 @@ def check(s):
# non-UTF-8 byte string
check(b'123\xa0')

@support.run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE')
# TODO: RUSTPYTHON
@unittest.skip("RustPython panics on this")
@support.run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE', '')
def test_float_with_comma(self):
# set locale to something that doesn't use '.' for the decimal point
# float must not accept the locale specific decimal point but
Expand Down Expand Up @@ -290,11 +292,11 @@ def test_is_integer(self):

def test_floatasratio(self):
for f, ratio in [
(0.875, (7, 8)),
(-0.875, (-7, 8)),
(0.0, (0, 1)),
(11.5, (23, 2)),
]:
(0.875, (7, 8)),
(-0.875, (-7, 8)),
(0.0, (0, 1)),
(11.5, (23, 2)),
]:
self.assertEqual(f.as_integer_ratio(), ratio)

for i in range(10000):
Expand Down Expand Up @@ -337,7 +339,7 @@ def test_float_containment(self):
self.assertTrue((f,) == (f,), "(%r,) != (%r,)" % (f, f))
self.assertTrue({f} == {f}, "{%r} != {%r}" % (f, f))
self.assertTrue({f : None} == {f: None}, "{%r : None} != "
"{%r : None}" % (f, f))
"{%r : None}" % (f, f))

# identical containers
l, t, s, d = [f], (f,), {f}, {f: None}
Expand Down Expand Up @@ -667,8 +669,6 @@ def test_float_specials_do_unpack(self):
('<f', LE_FLOAT_NAN)]:
struct.unpack(fmt, data)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@support.requires_IEEE_754
@unittest.skipIf(_testcapi is None, 'needs _testcapi')
def test_serialized_float_rounding(self):
Expand Down Expand Up @@ -776,7 +776,7 @@ def test_issue35560(self):
class ReprTestCase(unittest.TestCase):
def test_repr(self):
with open(os.path.join(os.path.split(__file__)[0],
'floating_points.txt'), encoding="utf-8") as floats_file:
'floating_points.txt'), encoding="utf-8") as floats_file:
for line in floats_file:
line = line.strip()
if not line or line.startswith('#'):
Expand Down Expand Up @@ -826,7 +826,7 @@ def test_short_repr(self):
'2.86438000439698e+28',
'8.89142905246179e+28',
'3.08578087079232e+35',
]
]

for s in test_strings:
negs = '-'+s
Expand Down Expand Up @@ -883,7 +883,7 @@ def test_overflow(self):
def test_previous_round_bugs(self):
# particular cases that have occurred in bug reports
self.assertEqual(round(562949953421312.5, 1),
562949953421312.5)
562949953421312.5)
self.assertEqual(round(56294995342131.5, 3),
56294995342131.5)
# round-half-even
Expand Down Expand Up @@ -1133,7 +1133,7 @@ def test_invalid_inputs(self):
'0x1.\uff10p0',
'0x1p0 \n 0x2p0',
'0x1p0\0 0x1p0', # embedded null byte is not end of string
]
]
for x in invalid_inputs:
try:
result = fromHex(x)
Expand All @@ -1152,7 +1152,7 @@ def test_whitespace(self):
('1.0', 1.0),
('-0x.2', -0.125),
('-0.0', -0.0)
]
]
whitespace = [
'',
' ',
Expand All @@ -1162,7 +1162,7 @@ def test_whitespace(self):
'\f',
'\v',
'\r'
]
]
for inp, expected in value_pairs:
for lead in whitespace:
for trail in whitespace:
Expand Down
36 changes: 33 additions & 3 deletions Lib/test/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def test_basic(self):

if sys.maxsize == 0x7fffffff:
# This test can currently only work on 32-bit machines.
# XXX If/when PySequence_Length() returns a ssize_t, it should be
# XXX re-enabled.
# Verify clearing of bug #556025.
# This assumes that the max data size (sys.maxint) == max
# address size this also assumes that the address size is at
Expand Down Expand Up @@ -97,15 +99,15 @@ def imul(a, b): a *= b
self.assertRaises((MemoryError, OverflowError), imul, lst, n)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.skip("Crashes on windows debug build")
def test_list_resize_overflow(self):
# gh-97616: test new_allocated * sizeof(PyObject*) overflow
# check in list_resize()
lst = [0] * 65
del lst[1:]
self.assertEqual(len(lst), 1)

size = ((2 ** (tuple.__itemsize__ * 8) - 1) // 2)
size = sys.maxsize
with self.assertRaises((MemoryError, OverflowError)):
lst * size
with self.assertRaises((MemoryError, OverflowError)):
Expand All @@ -117,7 +119,7 @@ def check(n):
l = [0] * n
s = repr(l)
self.assertEqual(s,
'[' + ', '.join(['0'] * n) + ']')
'[' + ', '.join(['0'] * n) + ']')
check(10) # check our checking code
check(1000000)

Expand Down Expand Up @@ -206,6 +208,7 @@ class L(list): pass
with self.assertRaises(TypeError):
(3,) + L([1,2])

# TODO: RUSTPYTHON
@unittest.skip("TODO: RUSTPYTHON; hang")
def test_equal_operator_modifying_operand(self):
# test fix for seg fault reported in bpo-38588 part 2.
Expand All @@ -232,6 +235,33 @@ def __eq__(self, other):
list4 = [1]
self.assertFalse(list3 == list4)

# TODO: RUSTPYTHON
@unittest.skip("TODO: RUSTPYTHON; hang")
def test_lt_operator_modifying_operand(self):
# See gh-120298
class evil:
def __lt__(self, other):
other.clear()
return NotImplemented

a = [[evil()]]
with self.assertRaises(TypeError):
a[0] < a

def test_list_index_modifing_operand(self):
# See gh-120384
class evil:
def __init__(self, lst):
self.lst = lst
def __iter__(self):
yield from self.lst
self.lst.clear()

lst = list(range(5))
operand = evil(lst)
with self.assertRaises(ValueError):
lst[::-1] = operand

@cpython_only
def test_preallocation(self):
iterable = [0] * 10
Expand Down
Loading
Loading