The implementation of the "test" command.
(context: argparse.Namespace, host: str | None = None)
| 776 | |
| 777 | |
| 778 | def test(context: argparse.Namespace, host: str | None = None) -> None: # noqa: PT028 |
| 779 | """The implementation of the "test" command.""" |
| 780 | if host is None: |
| 781 | host = context.host |
| 782 | |
| 783 | if context.clean: |
| 784 | clean(context, "test") |
| 785 | |
| 786 | with group(f"Test {'XCframework' if host in {'all', 'hosts'} else host}"): |
| 787 | timestamp = str(time.time_ns())[:-6] |
| 788 | testbed_dir = ( |
| 789 | CROSS_BUILD_DIR / f"{context.platform}-testbed.{timestamp}" |
| 790 | ) |
| 791 | if host in {"all", "hosts"}: |
| 792 | framework_path = ( |
| 793 | CROSS_BUILD_DIR / context.platform / "Python.xcframework" |
| 794 | ) |
| 795 | else: |
| 796 | build_arch = platform.machine() |
| 797 | host_arch = host.split("-")[0] |
| 798 | |
| 799 | if not host.endswith("-simulator"): |
| 800 | print("Skipping test suite non-simulator build.") |
| 801 | return |
| 802 | elif build_arch != host_arch: |
| 803 | print( |
| 804 | f"Skipping test suite for an {host_arch} build " |
| 805 | f"on an {build_arch} machine." |
| 806 | ) |
| 807 | return |
| 808 | else: |
| 809 | framework_path = ( |
| 810 | CROSS_BUILD_DIR |
| 811 | / host |
| 812 | / f"Platforms/Apple/{context.platform}" |
| 813 | / f"Frameworks/{apple_multiarch(host)}" |
| 814 | ) |
| 815 | |
| 816 | run([ |
| 817 | sys.executable, |
| 818 | "Platforms/Apple/testbed", |
| 819 | "clone", |
| 820 | "--platform", |
| 821 | context.platform, |
| 822 | "--framework", |
| 823 | framework_path, |
| 824 | testbed_dir, |
| 825 | ]) |
| 826 | |
| 827 | run( |
| 828 | [ |
| 829 | sys.executable, |
| 830 | testbed_dir, |
| 831 | "run", |
| 832 | "--verbose", |
| 833 | ] |
| 834 | + ( |
| 835 | ["--simulator", str(context.simulator)] |