|
1 | 1 | #!/usr/bin/env python3 |
2 | | -"""Exercise Debug bundle replacement with real directories on the same volume.""" |
| 2 | +"""Exercise Debug bundle replacement and launch verification.""" |
| 3 | +from contextlib import redirect_stdout |
| 4 | +from io import StringIO |
3 | 5 | from pathlib import Path |
4 | 6 | import tempfile |
5 | 7 | import unittest |
@@ -58,6 +60,37 @@ def test_concurrent_first_install_is_preserved(self): |
58 | 60 | self.assertTrue((self.destination / "old").is_file()) |
59 | 61 | self.assertTrue((self.staged / "new").is_file()) |
60 | 62 |
|
| 63 | + def test_finder_extension_may_be_discovered_only_after_launch(self): |
| 64 | + app = installer.APP |
| 65 | + finder = app / installer.FINDER |
| 66 | + commands = [] |
| 67 | + |
| 68 | + def run(*args): |
| 69 | + commands.append(args) |
| 70 | + |
| 71 | + def registrations(): |
| 72 | + self.assertIn(("/usr/bin/open", "-a", app), commands) |
| 73 | + return [(finder, "+")] |
| 74 | + |
| 75 | + with patch.object(installer, "run", side_effect=run), \ |
| 76 | + patch.object(installer, "process_ids", side_effect=[{100}, {200}]), \ |
| 77 | + patch.object(installer, "finder_registrations", side_effect=registrations), \ |
| 78 | + redirect_stdout(StringIO()) as status: |
| 79 | + installer.launch_installed(set(), "+") |
| 80 | + |
| 81 | + self.assertEqual(commands, [(installer.LSREGISTER, "-f", app), ("/usr/bin/open", "-a", app)]) |
| 82 | + self.assertIn(f"Finder extension registered at {finder}", status.getvalue()) |
| 83 | + self.assertIn("Finder extension process reloaded.", status.getvalue()) |
| 84 | + |
| 85 | + def test_launch_does_not_accept_another_finder_registration(self): |
| 86 | + finder = installer.APP / installer.FINDER |
| 87 | + other = self.destination / installer.FINDER |
| 88 | + with patch.object(installer, "run"), patch.object(installer, "process_ids", return_value={100}), \ |
| 89 | + patch.object(installer, "wait_for", side_effect=lambda check, _: check()), \ |
| 90 | + patch.object(installer, "finder_registrations", return_value=[(finder, "+"), (other, "=")]), \ |
| 91 | + redirect_stdout(StringIO()), self.assertRaisesRegex(installer.InstallError, "Expected one Finder extension"): |
| 92 | + installer.launch_installed(set(), "+") |
| 93 | + |
61 | 94 |
|
62 | 95 | if __name__ == "__main__": |
63 | 96 | unittest.main() |
0 commit comments