test_package_macos_worker.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """Validate the macOS packaging metadata without requiring a macOS host."""
  2. import importlib.util
  3. import plistlib
  4. import tempfile
  5. import unittest
  6. from pathlib import Path
  7. spec = importlib.util.spec_from_file_location("macos_package", Path(__file__).with_name("package-macos-worker.py"))
  8. module = importlib.util.module_from_spec(spec)
  9. spec.loader.exec_module(module)
  10. class PackagingTests(unittest.TestCase):
  11. def test_bundle(self):
  12. with tempfile.TemporaryDirectory() as root:
  13. root = Path(root)
  14. binary = root / "worker"
  15. binary.write_bytes(b"test-worker")
  16. target = root / "Worker.app"
  17. executable = module.package_worker(binary, target)
  18. self.assertEqual(executable.read_bytes(), binary.read_bytes())
  19. self.assertTrue(executable.stat().st_mode & 0o100)
  20. data = plistlib.loads((target / "Contents/Info.plist").read_bytes())
  21. self.assertEqual(data["LSMinimumSystemVersion"], "11.0")
  22. self.assertTrue(data["LSUIElement"])
  23. self.assertTrue(data["NSAppTransportSecurity"]["NSAllowsLocalNetworking"])
  24. with self.assertRaises(ValueError):
  25. module.package_worker(binary, target)
  26. with self.assertRaises(ValueError):
  27. module.package_worker(root / "missing", root / "Missing.app")
  28. if __name__ == "__main__":
  29. unittest.main()