test_macos_deployment_target.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """Tests for macOS runtime wheel deployment-target validation."""
  2. from __future__ import annotations
  3. import runpy
  4. from pathlib import Path
  5. from types import SimpleNamespace
  6. import pytest
  7. ROOT = Path(__file__).resolve().parents[3]
  8. SCRIPT = ROOT / "scripts" / "check-macos-deployment-target.py"
  9. checker = SimpleNamespace(**runpy.run_path(str(SCRIPT)))
  10. def test_otool_parser_uses_the_newest_macho_slice() -> None:
  11. output = """
  12. Load command 8
  13. cmd LC_VERSION_MIN_MACOSX
  14. cmdsize 16
  15. version 10.7
  16. sdk 11.1
  17. Load command 9
  18. cmd LC_BUILD_VERSION
  19. minos 11.0
  20. Load command 10
  21. cmd LC_BUILD_VERSION
  22. minos 13.5
  23. """
  24. assert checker.parse_otool_deployment_target(output) == (13, 5)
  25. def test_otool_parser_requires_a_deployment_target() -> None:
  26. with pytest.raises(ValueError, match="contains no macOS deployment target"):
  27. checker.parse_otool_deployment_target("Load command 0\n")
  28. def test_otool_parser_ignores_unrelated_version_fields() -> None:
  29. output = """
  30. Load command 1
  31. cmd LC_ID_DYLIB
  32. cmdsize 48
  33. current version 14.1.0
  34. compatibility version 1.0.0
  35. """
  36. with pytest.raises(ValueError, match="contains no macOS deployment target"):
  37. checker.parse_otool_deployment_target(output)
  38. def test_wheel_tag_rejects_a_newer_executable_target() -> None:
  39. checker.ensure_compatible(Path("runtime"), (13, 5), "macosx_14_0_arm64")
  40. checker.ensure_compatible(Path("runtime-x64"), (10, 7), "macosx_14_0_x86_64")
  41. with pytest.raises(RuntimeError, match="requires macOS 14.1"):
  42. checker.ensure_compatible(Path("spawn-helper"), (14, 1), "macosx_14_0_arm64")
  43. def test_wheel_tag_accepts_only_supported_macos_architectures() -> None:
  44. assert checker.claimed_version("macosx_14_0_arm64") == (14, 0)
  45. assert checker.claimed_version("macosx_14_0_x86_64") == (14, 0)
  46. with pytest.raises(ValueError, match="unsupported macOS wheel platform tag"):
  47. checker.claimed_version("macosx_14_0_universal2")