Skip to content

Commit 7d8ab3d

Browse files
committed
Merge remote-tracking branch 'origin/master' into feature-symtable
2 parents 0d83cab + 0a8df91 commit 7d8ab3d

File tree

17 files changed

+3714
-2038
lines changed

17 files changed

+3714
-2038
lines changed

Lib/test/support/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,31 @@ def skip_if_buggy_ucrt_strfptime(test):
25682568
_buggy_ucrt = False
25692569
return unittest.skip("buggy MSVC UCRT strptime/strftime")(test) if _buggy_ucrt else test
25702570

2571+
2572+
def skip_if_broken_multiprocessing_synchronize():
2573+
"""
2574+
Skip tests if the multiprocessing.synchronize module is missing, if there
2575+
is no available semaphore implementation, or if creating a lock raises an
2576+
OSError (on Linux only).
2577+
"""
2578+
2579+
# Skip tests if the _multiprocessing extension is missing.
2580+
import_module('_multiprocessing')
2581+
2582+
# Skip tests if there is no available semaphore implementation:
2583+
# multiprocessing.synchronize requires _multiprocessing.SemLock.
2584+
synchronize = import_module('multiprocessing.synchronize')
2585+
2586+
if sys.platform == "linux":
2587+
try:
2588+
# bpo-38377: On Linux, creating a semaphore fails with OSError
2589+
# if the current user does not have the permission to create
2590+
# a file in /dev/shm/ directory.
2591+
synchronize.Lock(ctx=None)
2592+
except OSError as exc:
2593+
raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}")
2594+
2595+
25712596
class PythonSymlink:
25722597
"""Creates a symlink for the current Python executable"""
25732598
def __init__(self, link=None):

Lib/test/test_dis.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import subprocess
2+
import sys
3+
import unittest
4+
5+
# This only tests that it prints something in order
6+
# to avoid changing this test if the bytecode changes
7+
8+
# These tests start a new process instead of redirecting stdout because
9+
# stdout is being written to by rust code, which currently can't be
10+
# redirected by reassigning sys.stdout
11+
12+
13+
class TestDis(unittest.TestCase):
14+
@classmethod
15+
def setUpClass(cls):
16+
cls.setup = """
17+
import dis
18+
def tested_func(): pass
19+
"""
20+
cls.command = (sys.executable, "-c")
21+
22+
def test_dis(self):
23+
test_code = f"""
24+
{self.setup}
25+
dis.dis(tested_func)
26+
dis.dis("x = 2; print(x)")
27+
"""
28+
29+
result = subprocess.run(
30+
self.command + (test_code,), capture_output=True
31+
)
32+
self.assertNotEqual("", result.stdout.decode())
33+
self.assertEqual("", result.stderr.decode())
34+
35+
def test_disassemble(self):
36+
test_code = f"""
37+
{self.setup}
38+
dis.disassemble(tested_func)
39+
"""
40+
result = subprocess.run(
41+
self.command + (test_code,), capture_output=True
42+
)
43+
# In CPython this would raise an AttributeError, not a
44+
# TypeError because dis is implemented in python in CPython and
45+
# as such the type mismatch wouldn't be caught immeadiately
46+
self.assertIn("TypeError", result.stderr.decode())
47+
48+
test_code = f"""
49+
{self.setup}
50+
dis.disassemble(tested_func.__code__)
51+
"""
52+
result = subprocess.run(
53+
self.command + (test_code,), capture_output=True
54+
)
55+
self.assertNotEqual("", result.stdout.decode())
56+
self.assertEqual("", result.stderr.decode())
57+
58+
59+
if __name__ == "__main__":
60+
unittest.main()

0 commit comments

Comments
 (0)