main
1"""Tests for the Firefox profile Raffi launcher helper."""
2
3from __future__ import annotations
4
5import os
6import subprocess
7import tempfile
8import unittest
9from pathlib import Path
10
11SCRIPT = Path(__file__).parents[1] / "scripts" / "firefox-profile-raffi"
12
13
14class FirefoxProfileRaffiTests(unittest.TestCase):
15 def test_launches_the_requested_profile_with_an_isolated_instance(self) -> None:
16 with tempfile.TemporaryDirectory() as temporary_directory:
17 temporary_path = Path(temporary_directory)
18 profile = temporary_path / ".mozilla" / "firefox" / "default"
19 profile.mkdir(parents=True)
20 bin_directory = temporary_path / "bin"
21 bin_directory.mkdir()
22 arguments_file = temporary_path / "firefox-arguments"
23 firefox = bin_directory / "firefox"
24 firefox.write_text(
25 f'#!/bin/sh\nprintf "%s\\n" "$@" > "{arguments_file}"\n', encoding="utf-8"
26 )
27 firefox.chmod(0o755)
28
29 subprocess.run(
30 [str(SCRIPT), "work"],
31 check=True,
32 env={
33 **os.environ,
34 "HOME": str(temporary_path),
35 "PATH": f"{bin_directory}:{os.environ['PATH']}",
36 },
37 )
38
39 self.assertEqual(
40 arguments_file.read_text(encoding="utf-8").splitlines(),
41 ["-no-remote", "-profile", str(profile)],
42 )
43
44
45if __name__ == "__main__":
46 unittest.main()