qutebrowser profile manager
at main 3.9 kB view raw
1from os import chdir, environ 2from pathlib import Path 3 4from click.testing import CliRunner 5 6from qbpm.main import main 7 8from . import no_homedir_fixture # noqa: F401 9 10 11def run(*args: str): 12 return CliRunner().invoke(main, args) 13 14 15def test_profile_dir_option(tmp_path: Path): 16 (tmp_path / "config.py").touch() 17 result = run("-P", str(tmp_path), "new", "-C", str(tmp_path), "test") 18 assert result.exit_code == 0 19 assert result.output.strip() == str(tmp_path / "test") 20 assert tmp_path / "test" in list(tmp_path.iterdir()) 21 assert (tmp_path / "applications" / "qbpm" / "test.desktop").exists() 22 23 24def test_profile_dir_env(tmp_path: Path): 25 environ["QBPM_PROFILE_DIR"] = str(tmp_path) 26 (tmp_path / "config.py").touch() 27 result = run("new", "-C", str(tmp_path), "test") 28 assert result.exit_code == 0 29 assert result.output.strip() == str(tmp_path / "test") 30 assert tmp_path / "test" in list(tmp_path.iterdir()) 31 32 33def test_config_dir_option(tmp_path: Path): 34 environ["QBPM_PROFILE_DIR"] = str(tmp_path) 35 config = tmp_path / "config.py" 36 config.touch() 37 result = run("new", "-C", str(tmp_path), "test") 38 assert result.exit_code == 0 39 assert str(config) in (tmp_path / "test/config/config.py").read_text() 40 41 42def test_relative_config_dir(tmp_path: Path): 43 environ["QBPM_PROFILE_DIR"] = str(tmp_path) 44 config = tmp_path / "config.py" 45 config.touch() 46 chdir(tmp_path) 47 result = run("new", "-C", ".", "test") 48 assert result.exit_code == 0 49 assert str(config) in (tmp_path / "test/config/config.py").read_text() 50 51 52def test_from_session_path(tmp_path: Path): 53 environ["QBPM_PROFILE_DIR"] = str(tmp_path) 54 (tmp_path / "config.py").touch() 55 session = tmp_path / "test.yml" 56 session.write_text("windows:\n") 57 result = run("from-session", "-C", str(tmp_path), str(session)) 58 assert result.exit_code == 0 59 assert result.output.strip() == str(tmp_path / "test") 60 assert (tmp_path / "test/data/sessions/_autosave.yml").read_text() == ("windows:\n") 61 62 63def test_from_session_name(tmp_path: Path): 64 environ["QBPM_PROFILE_DIR"] = str(tmp_path) 65 (tmp_path / "config.py").touch() 66 environ["XDG_DATA_HOME"] = str(tmp_path) 67 (tmp_path / "qutebrowser" / "sessions").mkdir(parents=True) 68 (tmp_path / "qutebrowser" / "sessions" / "test.yml").write_text("windows:\n") 69 result = run("from-session", "-C", str(tmp_path), "test") 70 assert result.exit_code == 0 71 assert result.output.strip() == str(tmp_path / "test") 72 assert (tmp_path / "test/data/sessions/_autosave.yml").read_text() == ("windows:\n") 73 74 75def test_config_file(tmp_path: Path): 76 environ["QBPM_PROFILE_DIR"] = str(tmp_path) 77 (tmp_path / "config.py").touch() 78 config_file = tmp_path / "config.toml" 79 config_file.write_text("config_py_template = '# Custom template {profile_name}'") 80 result = run("-c", str(config_file), "new", "test") 81 assert result.exit_code == 0 82 profile_config = tmp_path / "test" / "config" / "config.py" 83 assert "# Custom template test" in profile_config.read_text() 84 85 86def test_bad_config_file(): 87 result = run("-c", "/nonexistent/config.toml", "list") 88 assert result.exit_code == 1 89 assert "not a file" in result.output 90 91 92def test_no_desktop_file(tmp_path: Path): 93 environ["QBPM_PROFILE_DIR"] = str(tmp_path) 94 (tmp_path / "config.py").touch() 95 run("-P", str(tmp_path), "new", "--no-desktop-file", "-C", str(tmp_path), "test") 96 assert not (tmp_path / "applications" / "qbpm" / "test.desktop").exists() 97 98 99def test_desktop_file_directory(tmp_path: Path): 100 environ["QBPM_PROFILE_DIR"] = str(tmp_path) 101 (tmp_path / "config.py").touch() 102 config_file = tmp_path / "config.toml" 103 config_file.write_text(f'''config_py_template = "" 104 desktop_file_directory="{tmp_path}"''') 105 run("-P", str(tmp_path), "new", "-C", str(tmp_path), "test") 106 assert not (tmp_path / "test.desktop").exists()