Skip to content

Commit 2f08189

Browse files
committed
Adjust binascii free-threading tests
1 parent 2ead2e3 commit 2f08189

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed

Lib/test/test_binascii.py

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Test the binascii C module."""
22

3-
import sys
43
import threading
54
import unittest
65
import binascii
@@ -10,7 +9,6 @@
109
from test.support import bigmemtest, _1G, _4G
1110
from test.support.hypothesis_helper import hypothesis
1211
from test.support import threading_helper
13-
from test.support.script_helper import assert_python_ok
1412

1513

1614
# Note: "*_hex" functions are aliases for "(un)hexlify"
@@ -523,30 +521,11 @@ def test_big_buffer(self, size):
523521

524522

525523
class FreeThreadingTest(unittest.TestCase):
526-
@unittest.skipUnless(support.Py_GIL_DISABLED,
527-
'only meaningful in free-threaded builds')
528-
def test_import_does_not_enable_gil(self):
529-
assert_python_ok(
530-
'-X', 'gil=0',
531-
'-c',
532-
(
533-
'import sys\n'
534-
'if sys._is_gil_enabled():\n'
535-
' raise SystemExit("GIL unexpectedly enabled")\n'
536-
'import binascii\n'
537-
'if sys._is_gil_enabled():\n'
538-
' raise SystemExit("GIL unexpectedly enabled after import")\n'
539-
),
540-
)
541-
542524
@unittest.skipUnless(support.Py_GIL_DISABLED,
543525
'this test can only possibly fail with GIL disabled')
544526
@threading_helper.reap_threads
545527
@threading_helper.requires_working_threading()
546528
def test_free_threading(self):
547-
if sys._is_gil_enabled():
548-
self.skipTest('test requires running with -X gil=0')
549-
550529
num_threads = 8
551530
barrier = threading.Barrier(num_threads)
552531

@@ -557,20 +536,16 @@ def test_free_threading(self):
557536
hexed = binascii.hexlify(payload)
558537
b64 = binascii.b2a_base64(payload, newline=False)
559538
expected_crc = binascii.crc32(payload)
539+
assertEqual = self.assertEqual
560540

561541
def worker():
562542
barrier.wait(timeout=support.SHORT_TIMEOUT)
563543
for _ in range(1000):
564-
if binascii.unhexlify(hexed) != payload:
565-
raise AssertionError('unhexlify mismatch')
566-
if binascii.hexlify(payload) != hexed:
567-
raise AssertionError('hexlify mismatch')
568-
if binascii.a2b_base64(b64) != payload:
569-
raise AssertionError('a2b_base64 mismatch')
570-
if binascii.b2a_base64(payload, newline=False) != b64:
571-
raise AssertionError('b2a_base64 mismatch')
572-
if binascii.crc32(payload) != expected_crc:
573-
raise AssertionError('crc32 mismatch')
544+
assertEqual(binascii.unhexlify(hexed), payload, 'unhexlify mismatch')
545+
assertEqual(binascii.hexlify(payload), hexed, 'hexlify mismatch')
546+
assertEqual(binascii.a2b_base64(b64), payload, 'a2b_base64 mismatch')
547+
assertEqual(binascii.b2a_base64(payload, newline=False), b64, 'b2a_base64 mismatch')
548+
assertEqual(binascii.crc32(payload), expected_crc, 'crc32 mismatch')
574549

575550
threads = [threading.Thread(target=worker) for _ in range(num_threads)]
576551
with threading_helper.catch_threading_exception() as cm:

Misc/NEWS.d/next/Tests/2025-12-27-20-13-12.gh-issue-116738.efglNB.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)