Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit89bb435

Browse files
committed
Add documentation for using the testbed runner.
1 parent0b9baa1 commit89bb435

File tree

2 files changed

+71
-36
lines changed

2 files changed

+71
-36
lines changed

‎Doc/using/ios.rst‎

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,12 @@ To add Python to an iOS Xcode project:
292292
10. Add Objective C code to initialize and use a Python interpreter in embedded
293293
mode. You should ensure that:
294294

295-
*:c:member:`UTF-8 mode <PyPreConfig.utf8_mode>` is *enabled*;
296-
*:c:member:`Buffered stdio <PyConfig.buffered_stdio>` is *disabled*;
297-
*:c:member:`Writing bytecode <PyConfig.write_bytecode>` is *disabled*;
298-
*:c:member:`Signal handlers <PyConfig.install_signal_handlers>` are *enabled*;
295+
* UTF-8 mode (:c:member:`PyPreConfig.utf8_mode`) is *enabled*;
296+
* Buffered stdio (:c:member:`PyConfig.buffered_stdio`) is *disabled*;
297+
* Writing bytecode (:c:member:`PyConfig.write_bytecode`) is *disabled*;
298+
* Signal handlers (:c:member:`PyConfig.install_signal_handlers`) are *enabled*;
299+
* System logging (:c:member:`PyConfig.use_system_logger`) is *enabled*
300+
(optional, but strongly recommended);
299301
* ``PYTHONHOME`` for the interpreter is configured to point at the
300302
``python`` subfolder of your app's bundle; and
301303
* The ``PYTHONPATH`` for the interpreter includes:
@@ -324,6 +326,49 @@ modules in your app, some additional steps will be required:
324326
* If you're using a separate folder for third-party packages, ensure that folder
325327
is included as part of the ``PYTHONPATH`` configuration in step 10.
326328

329+
Testing a Python package
330+
------------------------
331+
332+
The CPython source tree contains:source:`a testbed project <iOS/testbed>` that
333+
is used to run the CPython test suite on the iOS simulator. This testbed can also
334+
be used as a testbed project for running your Python library's test suite on iOS.
335+
336+
After building or obtaining an iOS XCFramework (See:source:`iOS/README.rst`
337+
for details), create a clone of the Python iOS testbed project by running:
338+
339+
..code-block::bash
340+
341+
$ python iOS/testbed clone --framework<path/to/Python.xcframework> --app<path/to/module1> --app<path/to/module2> app-testbed
342+
343+
You will need to modify the ``iOS/testbed`` reference to point to that
344+
directory in the CPython source tree; any folders specified with the ``--app``
345+
flag will be copied into the cloned testbed project. The resulting testbed will
346+
be created in the ``app-testbed`` folder. In this example, the ``module1`` and
347+
``module2`` would be importable modules at runtime. If your project has
348+
additional dependencies, they can be installed into the
349+
``app-testbed/iOSTestbed/app_packages`` folder (using ``pip install --target
350+
app-testbed/iOSTestbed/app_packages`` or similar).
351+
352+
You can then use the ``app-testbed`` folder to run the test suite for your app,
353+
For example, if ``module1.tests`` was the entry point to your test suite, you
354+
could run:
355+
356+
..code-block::bash
357+
358+
$ python app-testbed run -- module1.tests
359+
360+
This is the equivalent of running ``python -m module1.tests`` on a desktop
361+
Python build. Any arguments after the ``--`` will be passed to the testbed as
362+
if they were arguments to ``python -m`` on a desktop machine.
363+
364+
You can also open the testbed project in Xcode by running:
365+
366+
..code-block::bash
367+
368+
$ open app-testbed/iOSTestbed.xcodeproj
369+
370+
This will allow you to use the full Xcode suite of tools for debugging.
371+
327372
App Store Compliance
328373
====================
329374

‎iOS/README.rst‎

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -285,52 +285,42 @@ This will:
285285
* Install the Python iOS framework into the copy of the testbed project; and
286286
* Run the test suite on an "iPhone SE (3rd generation)" simulator.
287287

288-
While the test suite is running, Xcode does not display any console output.
289-
After showing some Xcode build commands, the console output will print ``Testing
290-
started``, and then appear to stop. It will remain in this state until the test
291-
suite completes. On a 2022 M1 MacBook Pro, the test suite takes approximately 12
292-
minutes to run; a couple of extra minutes is required to boot and prepare the
293-
iOS simulator.
294-
295288
On success, the test suite will exit and report successful completion of the
296-
test suite. No output of the Python test suite will be displayed.
297-
298-
On failure, the output of the Python test suite *will* be displayed. This will
299-
show the details of the tests that failed.
289+
test suite. On a 2022 M1 MacBook Pro, the test suite takes approximately 12
290+
minutes to run; a couple of extra minutes is required to compile the testbed
291+
project, and then boot and prepare the iOS simulator.
300292

301293
Debugging test failures
302294
-----------------------
303295

304-
The easiest way to diagnose a single test failure is to open the testbed project
305-
in Xcode and run the tests from there using the "Product > Test" menu item.
306-
307-
To test in Xcode, you must ensure the testbed project has a copy of a compiled
308-
framework. If you've configured your build with the default install location of
309-
``iOS/Frameworks``, you can copy from that location into the test project. To
310-
test on an ARM64 simulator, run::
311-
312-
$ rm -rf iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/*
313-
$ cp -r iOS/Frameworks/arm64-iphonesimulator/* iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator
296+
Running ``make test`` generates a standalone version of the ``iOS/testbed``
297+
project, and runs the full test suite. It does this using ``iOS/testbed``
298+
itself - the folder is an executable module that can be used to create and run
299+
a clone of the testbed project.
314300

315-
To test on an x86-64 simulator, run::
301+
You can generate your own standalone testbed instance by running::
316302

317-
$ rm -rf iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/*
318-
$ cp -r iOS/Frameworks/x86_64-iphonesimulator/* iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator
303+
$ python iOS/testbed clone --framework iOS/Frameworks/arm64-iphonesimulator my-testbed
319304

320-
To test on a physical device::
305+
This invocation assumes that ``iOS/Frameworks/arm64-iphonesimulator`` is the
306+
path to the iOS simulator framework for your platform (ARM64 in this case);
307+
``my-testbed`` is the name of the folder for the new testbed clone.
321308

322-
$ rm -rf iOS/testbed/Python.xcframework/ios-arm64/*
323-
$ cp -r iOS/Frameworks/arm64-iphoneos/* iOS/testbed/Python.xcframework/ios-arm64
309+
You can then use the ``my-testbed`` folder to run the Python test suite,
310+
passing in any command line arguments you may require. For example, if you're
311+
trying to diagnose a failure in the ``os`` module, you might run::
324312

325-
Alternatively, you can configure your build to install directly into the
326-
testbed project. For a simulator, use::
313+
$ python my-testbed run -- test -W test_os
327314

328-
--enable-framework=$(pwd)/iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator
315+
This is the equivalent of running ``python -m test -W test_os`` on a desktop
316+
Python build. Any arguments after the ``--`` will be passed to testbed as if
317+
they were arguments to ``python -m`` on a desktop machine.
329318

330-
For a physical device, use::
319+
You can also open the testbed project in Xcode by running::
331320

332-
--enable-framework=$(pwd)/iOS/testbed/Python.xcframework/ios-arm64
321+
$ open my-testbed/iOSTestbed.xcodeproj
333322

323+
This will allow you to use the full Xcode suite of tools for debugging.
334324

335325
Testing on an iOS device
336326
^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp