Preserve deferred macOS desktop host and local publisher
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"publish_macos", Path(__file__).with_name("publish_macos.py"))
|
||||
publish = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(publish)
|
||||
|
||||
|
||||
class InstallTests(unittest.TestCase):
|
||||
def test_local_build_targets_only_the_host_architecture(self):
|
||||
for architecture in ("arm64", "x86_64"):
|
||||
with patch.object(publish.platform, "machine", return_value=architecture):
|
||||
environment = publish.build_environment()
|
||||
self.assertEqual(environment["FLUTTER_XCODE_ARCHS"], architecture)
|
||||
self.assertEqual(environment["FLUTTER_XCODE_ONLY_ACTIVE_ARCH"], "YES")
|
||||
|
||||
def test_universal_build_is_explicit(self):
|
||||
environment = publish.build_environment(universal=True)
|
||||
self.assertEqual(environment["FLUTTER_XCODE_ARCHS"], "arm64 x86_64")
|
||||
self.assertEqual(environment["FLUTTER_XCODE_ONLY_ACTIVE_ARCH"], "NO")
|
||||
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.root = Path(self.temp.name)
|
||||
self.source = self.root / "release/Pipelines.app"
|
||||
self.target = self.root / "installed/Pipelines.app"
|
||||
self.source.mkdir(parents=True)
|
||||
self.target.mkdir(parents=True)
|
||||
(self.source / "version").write_text("new")
|
||||
(self.target / "version").write_text("old")
|
||||
|
||||
@staticmethod
|
||||
def copy(command, **kwargs):
|
||||
shutil.copytree(command[1], command[2])
|
||||
|
||||
def test_replacement_keeps_previous_bundle(self):
|
||||
with patch.object(publish.subprocess, "run", side_effect=self.copy):
|
||||
publish.install(self.source, self.target)
|
||||
self.assertEqual((self.target / "version").read_text(), "new")
|
||||
self.assertEqual((self.target.with_name("Pipelines.app.previous") /
|
||||
"version").read_text(), "old")
|
||||
|
||||
def test_failed_copy_leaves_installed_app_untouched(self):
|
||||
with patch.object(publish.subprocess, "run",
|
||||
side_effect=subprocess.CalledProcessError(1, "ditto")):
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
publish.install(self.source, self.target)
|
||||
self.assertEqual((self.target / "version").read_text(), "old")
|
||||
|
||||
def test_failed_swap_restores_installed_app(self):
|
||||
rename = Path.rename
|
||||
|
||||
def fail_staging(path, target):
|
||||
if path.name.endswith(".next"):
|
||||
raise OSError("simulated rename failure")
|
||||
return rename(path, target)
|
||||
|
||||
with patch.object(publish.subprocess, "run", side_effect=self.copy), \
|
||||
patch.object(Path, "rename", fail_staging):
|
||||
with self.assertRaises(OSError):
|
||||
publish.install(self.source, self.target)
|
||||
self.assertEqual((self.target / "version").read_text(), "old")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user