8000 Merge pull request #5702 from arihant2math/struct-313 · RustPython/RustPython@2ca52bf · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ca52bf

Browse files
authored
Merge pull request #5702 from arihant2math/struct-313
Update struct to 3.13.3 and update parts of test.support
2 parents a917da3 + 662d3a1 commit 2ca52bf

File tree

5 files changed

+180
-168
lines changed

5 files changed

+180
-168
lines changed

Lib/test/support/__init__.py

Lines changed: 95 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,7 @@
7474
#
7575
# The timeout should be long enough for connect(), recv() and send() methods
7676
# of socket.socket.
77-
LOOPBACK_TIMEOUT = 5.0
78-
if sys.platform == 'win32' and ' 32 bit (ARM)' in sys.version:
79-
# bpo-37553: test_socket.SendfileUsingSendTest is taking longer than 2
80-
# seconds on Windows ARM32 buildbot
81-
LOOPBACK_TIMEOUT = 10
82-
elif sys.platform == 'vxworks':
83-
LOOPBACK_TIMEOUT = 10
77+
LOOPBACK_TIMEOUT = 10.0
8478

8579
# Timeout in seconds for network requests going to the internet. The timeout is
8680
# short enough to prevent a test to wait for too long if the internet request
@@ -113,7 +107,6 @@
113107
STDLIB_DIR = os.path.dirname(TEST_HOME_DIR)
114108
REPO_ROOT = os.path.dirname(STDLIB_DIR)
115109

116-
117110
class Error(Exception):
118111
"""Base class for regression test exceptions."""
119112

@@ -259,22 +252,16 @@ class USEROBJECTFLAGS(ctypes.Structure):
259252
# process not running under the same user id as the current console
260253
# user. To avoid that, raise an exception if the window manager
261254
# connection is not available.
262-
from ctypes import cdll, c_int, pointer, Structure
263-
from ctypes.util import find_library
264-
265-
app_services = cdll.LoadLibrary(find_library("ApplicationServices"))
266-
267-
if app_services.CGMainDisplayID() == 0:
268-
reason = "gui tests cannot run without OS X window manager"
255+
import subprocess
256+
try:
257+
rc = subprocess.run(["launchctl", "managername"],
258+
capture_output=True, check=True)
259+
managername = rc.stdout.decode("utf-8").strip()
260+
except subprocess.CalledProcessError:
261+
reason = "unable to detect macOS launchd job manager"
269262
else:
270-
class ProcessSerialNumber(Structure):
271-
_fields_ = [("highLongOfPSN", c_int),
272-
("lowLongOfPSN", c_int)]
273-
psn = ProcessSerialNumber()
274-
psn_p = pointer(psn)
275-
if ( (app_services.GetCurrentProcess(psn_p) < 0) or
276-
(app_services.SetFrontProcess(psn_p) < 0) ):
277-
reason = "cannot run without OS X gui process"
263+
if managername != "Aqua":
264+
reason = f"{managername=} -- can only run in a macOS GUI session"
278265

279266
# check on every platform whether tkinter can actually do anything
280267
if not reason:
@@ -391,11 +378,12 @@ def wrapper(*args, **kw):
391378

392379
def skip_if_buildbot(reason=None):
393380
"""Decorator raising SkipTest if running on a buildbot."""
381+
import getpass
394382
if not reason:
395383
reason = 'not suitable for buildbots'
396384
try:
397385
isbuildbot = getpass.getuser().lower() == 'buildbot'
398-
except (KeyError, EnvironmentError) as err:
386+
except (KeyError, OSError) as err:
399387
warnings.warn(f'getpass.getuser() failed {err}.', RuntimeWarning)
400388
isbuildbot = False
401389
return unittest.skipIf(isbuildbot, reason)
@@ -409,35 +397,48 @@ def check_sanitizer(*, address=False, memory=False, ub=False, thread=False):
409397
cflags = sysconfig.get_config_var('CFLAGS') or ''
410398
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
411399
memory_sanitizer = (
412-
'-fsanitize=memory' in cflags or
413-
'--with-memory-sanitizer' in config_args
400+
'-fsanitize=memory' in cflags or
401+
'--with-memory-sanitizer' in config_args
414402
)
415403
address_sanitizer = (
416-
'-fsanitize=address' in cflags or
417-
'--with-address-sanitizer' in config_args
404+
'-fsanitize=address' in cflags or
405+
'--with-address-sanitizer' in config_args
418406
)
419407
ub_sanitizer = (
420-
'-fsanitize=undefined' in cflags or
421-
'--with-undefined-behavior-sanitizer' in config_args
408+
'-fsanitize=undefined' in cflags or
409+
'--with-undefined-behavior-sanitizer' in config_args
422410
)
423411
thread_sanitizer = (
424-
'-fsanitize=thread' in cflags or
425-
'--with-thread-sanitizer' in config_args
412+
'-fsanitize=thread' in cflags or
413+
'--with-thread-sanitizer' in config_args
426414
)
427415
return (
428-
(memory and memory_sanitizer) or
429-
(address and address_sanitizer) or
430-
(ub and ub_sanitizer) or
431-
(thread and thread_sanitizer)
416+
(memory and memory_sanitizer) or
417+
(address and address_sanitizer) or
418+
(ub and ub_sanitizer) or
419+
(thread and thread_sanitizer)
432420
)
433421

422+
434423
def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False, thread=False):
435424
"""Decorator raising SkipTest if running with a sanitizer active."""
436425
if not reason:
437426
reason = 'not working with sanitizers active'
438-
skip = check_sanitizer(address=address, memory=memory, ub=ub)
427+
skip = check_sanitizer(address=address, memory=memory, ub=ub, thread=thread)
439428
return unittest.skipIf(skip, reason)
440429

430+
# gh-89363: True if fork() can hang if Python is built with Address Sanitizer
431+
# (ASAN): libasan race condition, dead lock in pthread_create().
432+
HAVE_ASAN_FORK_BUG = check_sanitizer(address=True)
433+
434+
435+
def set_sanitizer_env_var(env, option):
436+
for name in ('ASAN_OPTIONS', 'MSAN_OPTIONS', 'UBSAN_OPTIONS', 'TSAN_OPTIONS'):
437+
if name in env:
438+
env[name] += f':{option}'
439+
else:
440+
env[name] = option
441+
441442

442443
def system_must_validate_cert(f):
443444
"""Skip the test on TLS certificate validation failures."""
@@ -510,21 +511,42 @@ def has_no_debug_ranges():
510511
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
511512
return unittest.skipIf(has_no_debug_ranges(), reason)
512513

513-
def requires_legacy_unicode_capi():
514+
@contextlib.contextmanager
515+
def suppress_immortalization(suppress=True):
516+
"""Suppress immortalization of deferred objects."""
517+
try:
518+
import _testinternalcapi
519+
except ImportError:
520+
yield
521+
return
522+
523+
if not suppress:
524+
yield
525+
return
526+
527+
_testinternalcapi.suppress_immortalization(True)
528+
try:
529+
yield
530+
finally:
531+
_testinternalcapi.suppress_immortalization(False)
532+
533+
def skip_if_suppress_immortalization():
514534
try:
515-
from _testcapi import unicode_legacy_string
535+
import _testinternalcapi
516536
except ImportError:
517-
unicode_legacy_string = None
537+
return
538+
return unittest.skipUnless(_testinternalcapi.get_immortalize_deferred(),
539+
"requires immortalization of deferred objects")
540+
518541

519-
return unittest.skipUnless(unicode_legacy_string,
520-
'requires legacy Unicode C API')
542+
MS_WINDOWS = (sys.platform == 'win32')
521543

522544
# Is not actually used in tests, but is kept for compatibility.
523545
is_jython = sys.platform.startswith('java')
524546

525-
is_android = hasattr(sys, 'getandroidapilevel')
547+
is_android = sys.platform == "android"
526548

527-
if sys.platform not in ('win32', 'vxworks'):
549+
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos"}:
528550
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
529551
else:
530552
unix_shell = None
@@ -534,23 +556,44 @@ def requires_legacy_unicode_capi():
534556
is_emscripten = sys.platform == "emscripten"
535557
is_wasi = sys.platform == "wasi"
536558

537-
has_fork_support = hasattr(os, "fork") and not is_emscripten and not is_wasi
559+
is_apple_mobile = sys.platform in {"ios", "tvos", "watchos"}
560+
is_apple = is_apple_mobile or sys.platform == "darwin"
538561

539-
# From python 3.12.6
540-
is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
541-
skip_on_s390x = unittest.skipIf(is_s390x, 'skipped on s390x')
562+
has_fork_support = hasattr(os, "fork") and not (
563+
# WASM and Apple mobile platforms do not support subprocesses.
564+
is_emscripten
565+
or is_wasi
566+
or is_apple_mobile
567+
568+
# Although Android supports fork, it's unsafe to call it from Python because
569+
# all Android apps are multi-threaded.
570+
or is_android
571+
)
542572

543573
def requires_fork():
544574
return unittest.skipUnless(has_fork_support, "requires working os.fork()")
545575

546-
has_subprocess_support = not is_emscripten and not is_wasi
576+
has_subprocess_support = not (
577+
# WASM and Apple mobile platforms do not support subprocesses.
578+
is_emscripten
579+
or is_wasi
580+
or is_apple_mobile
581+
582+
# Although Android supports subproceses, they're almost never useful in
583+
# practice (see PEP 738). And most of the tests that use them are calling
584+
# sys.executable, which won't work when Python is embedded in an Android app.
585+
or is_android
586+
)
547587

548588
def requires_subprocess():
549589
"""Used for subprocess, os.spawn calls, fd inheritance"""
550590
return unittest.skipUnless(has_subprocess_support, "requires subprocess support")
551591

552592
# Emscripten's socket emulation and WASI sockets have limitations.
553-
has_socket_support = not is_emscripten and not is_wasi
593+
has_socket_support = not (
594+
is_emscripten
595+
or is_wasi
596+
)
554597

555598
def requires_working_socket(*, module=False):
556599
"""Skip tests or modules that require working sockets
@@ -2551,7 +2594,8 @@ def adjust_int_max_str_digits(max_digits):
25512594
# The default C recursion limit (from Include/cpython/pystate.h).
25522595
C_RECURSION_LIMIT = 1500
25532596

2554-
#Windows doesn't have os.uname() but it doesn't support s390x.
2597+
# Windows doesn't have os.uname() but it doesn't support s390x.
2598+
is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
25552599
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
25562600
'skipped on s390x')
25572601
HAVE_ASAN_FORK_BUG = check_sanitizer(address=True)

Lib/test/test_csv.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,6 @@ def test_writerows_errors(self):
291291
self.assertRaises(TypeError, writer.writerows, None)
292292
self.assertRaises(OSError, writer.writerows, BadIterable())
293293

294-
@support.cpython_only
295-
@support.requires_legacy_unicode_capi()
296-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
297-
def test_writerows_legacy_strings(self):
298-
import _testcapi
299-
c = _testcapi.unicode_legacy_string('a')
300-
with TemporaryFile("w+", encoding="utf-8", newline='') as fileobj:
301-
writer = csv.writer(fileobj)
302-
writer.writerows([[c]])
303-
fileobj.seek(0)
304-
self.assertEqual(fileobj.read(), "a\r\n")
305-
306294
def _read_test(self, input, expect, **kwargs):
307295
reader = csv.reader(input, **kwargs)
308296
result = list(reader)

Lib/test/test_decimal.py

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
import locale
3535
from test.support import (is_resource_enabled,
3636
requires_IEEE_754, requires_docstrings,
37-
requires_legacy_unicode_capi, check_sanitizer)
37+
check_disallow_instantiation)
3838
from test.support import (TestFailed,
3939
run_with_locale, cpython_only,
40-
darwin_malloc_err_warning, is_emscripten)
40+
darwin_malloc_err_warning)
4141
from test.support.import_helper import import_fresh_module
4242
from test.support import threading_helper
4343
from test.support import warnings_helper
@@ -586,18 +586,6 @@ def test_explicit_from_string(self):
586586
# underscores don't prevent errors
587587
self.assertRaises(InvalidOperation, Decimal, "1_2_\u00003")
588588

589-
@cpython_only
590-
@requires_legacy_unicode_capi()
591-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
592-
def test_from_legacy_strings(self):
593-
import _testcapi
594-
Decimal = self.decimal.Decimal
595-
context = self.decimal.Context()
596-
597-
s = _testcapi.unicode_legacy_string('9.999999')
598-
self.assertEqual(str(Decimal(s)), '9.999999')
599-
self.assertEqual(str(context.create_decimal(s)), '9.999999')
600-
601589
def test_explicit_from_tuples(self):
602590
Decimal = self.decimal.Decimal
603591

@@ -2928,23 +2916,6 @@ def test_none_args(self):
29282916
assert_signals(self, c, 'traps', [InvalidOperation, DivisionByZero,
29292917
Overflow])
29302918

2931-
@cpython_only
2932-
@requires_legacy_unicode_capi()
2933-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
2934-
def test_from_legacy_strings(self):
2935-
import _testcapi
2936-
c = self.decimal.Context()
2937-
2938-
for rnd in RoundingModes:
2939-
c.rounding = _testcapi.unicode_legacy_string(rnd)
2940-
self.assertEqual(c.rounding, rnd)
2941-
2942-
s = _testcapi.unicode_legacy_string('')
2943-
self.assertRaises(TypeError, setattr, c, 'rounding', s)
2944-
2945-
s = _testcapi.unicode_legacy_string('ROUND_\x00UP')
2946-
self.assertRaises(TypeError, setattr, c, 'rounding', s)
2947-
29482919
def test_pickle(self):
29492920

29502921
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
@@ -5654,48 +5625,6 @@ def __abs__(self):
56545625
self.assertEqual(Decimal.from_float(cls(101.1)),
56555626
Decimal.from_float(101.1))
56565627

5657-
# Issue 41540:
5658-
@unittest.skipIf(sys.platform.startswith("aix"),
5659-
"AIX: default ulimit: test is flaky because of extreme over-allocation")
5660-
@unittest.skipIf(is_emscripten, "Test is unstable on Emscripten")
5661-
@unittest.skipIf(check_sanitizer(address=True, memory=True),
5662-
"ASAN/MSAN sanitizer defaults to crashing "
5663-
"instead of returning NULL for malloc failure.")
5664-
def test_maxcontext_exact_arith(self):
5665-
5666-
# Make sure that exact operations do not raise MemoryError due
5667-
# to huge intermediate values when the context precision is very
5668-
# large.
5669-
5670-
# The following functions fill the available precision and are
5671-
# therefore not suitable for large precisions (by design of the
5672-
# specification).
5673-
MaxContextSkip = ['logical_invert', 'next_minus', 'next_plus',
5674-
'logical_and', 'logical_or', 'logical_xor',
5675-
'next_toward', 'rotate', 'shift']
5676-
5677-
Decimal = C.Decimal
5678-
Context = C.Context
5679-
localcontext = C.localcontext
5680-
5681-
# Here only some functions that are likely candidates for triggering a
5682-
# MemoryError are tested. deccheck.py has an exhaustive test.
5683-
maxcontext = Context(prec=C.MAX_PREC, Emin=C.MIN_EMIN, Emax=C.MAX_EMAX)
5684-
with localcontext(maxcontext):
5685-
self.assertEqual(Decimal(0).exp(), 1)
5686-
self.assertEqual(Decimal(1).ln(), 0)
5687-
self.assertEqual(Decimal(1).log10(), 0)
5688-
self.assertEqual(Decimal(10**2).log10(), 2)
5689-
self.assertEqual(Decimal(10**223).log10(), 223)
5690-
self.assertEqual(Decimal(10**19).logb(), 19)
5691-
self.assertEqual(Decimal(4).sqrt(), 2)
5692-
self.assertEqual(Decimal("40E9").sqrt(), Decimal('2.0E+5'))
5693-
self.assertEqual(divmod(Decimal(10), 3), (3, 1))
5694-
self.assertEqual(Decimal(10) // 3, 3)
5695-
self.assertEqual(Decimal(4) / 2, 2)
5696-
self.assertEqual(Decimal(400) ** -1, Decimal('0.0025'))
5697-
5698-
56995628
def test_c_signaldict_segfault(self):
57005629
# See gh-106263 for details.
57015630
SignalDict = type(C.Context().flags)

0 commit comments

Comments
 (0)
0