Skip to content

Commit 9c6c76b

Browse files
committed
fix: merge main fix conflict
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
2 parents c4b5152 + d3aa5f6 commit 9c6c76b

12 files changed

Lines changed: 109 additions & 56 deletions

File tree

Apple/iOS/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ Once you have a built an XCframework, you can test that framework by running:
224224

225225
$ python Apple test iOS
226226

227+
This test will attempt to find an "SE-class" simulator (i.e., an iPhone SE, or
228+
iPhone 16e, or similar), and run the test suite on the most recent version of
229+
iOS that is available. You can specify a simulator using the `--simulator`
230+
command line argument, providing the name of the simulator (e.g., `--simulator
231+
'iPhone 16 Pro'`). You can also use this argument to control the OS version used
232+
for testing; `--simulator 'iPhone 16 Pro,OS=18.2'` would attempt to run the
233+
tests on an iPhone 16 Pro running iOS 18.2.
234+
235+
If the test runner is executed on GitHub Actions, the `GITHUB_ACTIONS`
236+
environment variable will be exposed to the iOS process at runtime.
237+
227238
### Testing a single-architecture framework
228239

229240
The `Apple/testbed` folder that contains an Xcode project that is able to run

Apple/testbed/TestbedTests/TestbedTests.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ - (void)testPython {
3535
setenv("NO_COLOR", "1", true);
3636
setenv("PYTHON_COLORS", "0", true);
3737

38+
if (getenv("GITHUB_ACTIONS")) {
39+
NSLog(@"Running in a GitHub Actions environment");
40+
}
3841
// Arguments to pass into the test suite runner.
3942
// argv[0] must identify the process; any subsequent arg
4043
// will be handled as if it were an argument to `python -m test`

Apple/testbed/__main__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import json
3+
import os
34
import re
45
import shutil
56
import subprocess
@@ -78,13 +79,21 @@ def xcode_test(location: Path, platform: str, simulator: str, verbose: bool):
7879
check=True,
7980
)
8081

82+
# Any environment variable prefixed with TEST_RUNNER_ is exposed into the
83+
# test runner environment. There are some variables (like those identifying
84+
# CI platforms) that can be useful to have access to.
85+
test_env = os.environ.copy()
86+
if "GITHUB_ACTIONS" in os.environ:
87+
test_env["TEST_RUNNER_GITHUB_ACTIONS"] = os.environ["GITHUB_ACTIONS"]
88+
8189
print("Running test project...")
8290
# Test execution *can't* be run -quiet; verbose mode
8391
# is how we see the output of the test output.
8492
process = subprocess.Popen(
8593
["xcodebuild", "test-without-building"] + args,
8694
stdout=subprocess.PIPE,
8795
stderr=subprocess.STDOUT,
96+
env=test_env,
8897
)
8998
while line := (process.stdout.readline()).decode(*DECODE_ARGS):
9099
# Strip the timestamp/process prefix from each log line

Lib/profiling/sampling/_sync_coordinator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ def _execute_script(script_path: str, script_args: List[str], cwd: str) -> None:
177177
with open(script_path, 'rb') as f:
178178
source_code = f.read()
179179

180+
except FileNotFoundError as e:
181+
raise TargetError(f"Script file not found: {script_path}") from e
182+
except PermissionError as e:
183+
raise TargetError(f"Permission denied reading script: {script_path}") from e
184+
185+
try:
180186
# gh-140729: Create a __mp_main__ module to allow pickling
181187
main_module = types.ModuleType("__main__")
182188
main_module.__file__ = script_path
@@ -185,11 +191,6 @@ def _execute_script(script_path: str, script_args: List[str], cwd: str) -> None:
185191

186192
code = compile(source_code, script_path, 'exec')
187193
exec(code, main_module.__dict__)
188-
189-
except FileNotFoundError as e:
190-
raise TargetError(f"Script file not found: {script_path}") from e
191-
except PermissionError as e:
192-
raise TargetError(f"Permission denied reading script: {script_path}") from e
193194
except SyntaxError as e:
194195
raise TargetError(f"Syntax error in script {script_path}: {e}") from e
195196
except SystemExit:

Lib/test/support/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"BrokenIter",
6969
"in_systemd_nspawn_sync_suppressed",
7070
"run_no_yield_async_fn", "run_yielding_async_fn", "async_yield",
71-
"reset_code",
71+
"reset_code", "on_github_actions"
7272
]
7373

7474

@@ -1369,6 +1369,7 @@ def reset_code(f: types.FunctionType) -> types.FunctionType:
13691369
f.__code__ = f.__code__.replace()
13701370
return f
13711371

1372+
on_github_actions = "GITHUB_ACTIONS" in os.environ
13721373

13731374
#=======================================================================
13741375
# Check for the presence of docstrings.

Lib/test/test_dict.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,26 @@ def __hash__(self):
16011601
with self.assertRaises(KeyError):
16021602
d.get(key2)
16031603

1604+
def test_clear_at_lookup(self):
1605+
class X:
1606+
def __hash__(self):
1607+
return 1
1608+
def __eq__(self, other):
1609+
nonlocal d
1610+
d.clear()
1611+
1612+
d = {}
1613+
for _ in range(10):
1614+
d[X()] = None
1615+
1616+
self.assertEqual(len(d), 1)
1617+
1618+
d = {}
1619+
for _ in range(10):
1620+
d.setdefault(X(), None)
1621+
1622+
self.assertEqual(len(d), 1)
1623+
16041624

16051625
class CAPITest(unittest.TestCase):
16061626

Lib/test/test_profiling/test_sampling_profiler.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,22 @@ def test_valid_output_formats(self):
20862086
# Expected errors - we just want to test format validation
20872087
pass
20882088

2089+
def test_script_error_treatment(self):
2090+
script_file = tempfile.NamedTemporaryFile("w", delete=False, suffix=".py")
2091+
script_file.write("open('nonexistent_file.txt')\n")
2092+
script_file.close()
2093+
self.addCleanup(os.unlink, script_file.name)
2094+
2095+
result = subprocess.run(
2096+
[sys.executable, "-m", "profiling.sampling.sample", "-d", "1", script_file.name],
2097+
capture_output=True,
2098+
text=True,
2099+
)
2100+
output = result.stdout + result.stderr
2101+
2102+
self.assertNotIn("Script file not found", output)
2103+
self.assertIn("No such file or directory: 'nonexistent_file.txt'", output)
2104+
20892105

20902106
class TestSampleProfilerCLI(unittest.TestCase):
20912107
def _setup_sync_mocks(self, mock_socket, mock_popen):

Lib/test/test_socketserver.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,16 @@ def test_ForkingUDPServer(self):
223223
self.dgram_examine)
224224

225225
@requires_unix_sockets
226+
@unittest.skipIf(test.support.is_apple_mobile and test.support.on_github_actions,
227+
"gh-140702: Test fails regularly on iOS simulator on GitHub Actions")
226228
def test_UnixDatagramServer(self):
227229
self.run_server(socketserver.UnixDatagramServer,
228230
socketserver.DatagramRequestHandler,
229231
self.dgram_examine)
230232

231233
@requires_unix_sockets
234+
@unittest.skipIf(test.support.is_apple_mobile and test.support.on_github_actions,
235+
"gh-140702: Test fails regularly on iOS simulator on GitHub Actions")
232236
def test_ThreadingUnixDatagramServer(self):
233237
self.run_server(socketserver.ThreadingUnixDatagramServer,
234238
socketserver.DatagramRequestHandler,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed crash in :class:`dict` if :meth:`dict.clear` is called at the lookup
2+
stage. Patch by Mikhail Efimov and Inada Naoki.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`profiling.sampling.sample` incorrectly handling a
2+
:exc:`FileNotFoundError` or :exc:`PermissionError`.

0 commit comments

Comments
 (0)