|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +from qbpm.config import ( |
| 4 | + DEFAULT_CONFIG_FILE, |
| 5 | + Config, |
| 6 | + find_config, |
| 7 | + find_qutebrowser_config_dir, |
| 8 | +) |
| 9 | + |
| 10 | +from . import no_homedir_fixture # noqa: F401 |
| 11 | + |
| 12 | + |
| 13 | +def test_no_config(): |
| 14 | + assert find_config(None) == Config.load(DEFAULT_CONFIG_FILE) |
| 15 | + |
| 16 | + |
| 17 | +def test_empty_config(tmp_path: Path): |
| 18 | + file = tmp_path / "config.toml" |
| 19 | + file.touch() |
| 20 | + assert find_config(file) == Config() |
| 21 | + |
| 22 | + |
| 23 | +def test_default_config_location(tmp_path: Path): |
| 24 | + (tmp_path / "qbpm").mkdir() |
| 25 | + (tmp_path / "qbpm" / "config.toml").touch() |
| 26 | + assert find_config(None) == Config() |
| 27 | + |
| 28 | + |
| 29 | +def test_minimal_config(tmp_path: Path): |
| 30 | + file = tmp_path / "config.toml" |
| 31 | + file.write_text("""config_py_template = 'template'""") |
| 32 | + assert find_config(file) == Config(config_py_template="template") |
| 33 | + |
| 34 | + |
| 35 | +def test_full_config(tmp_path: Path): |
| 36 | + file = tmp_path / "config.toml" |
| 37 | + file.write_text(""" |
| 38 | +config_py_template = \""" |
| 39 | +config.load_autoconfig() |
| 40 | +\""" |
| 41 | +qutebrowser_config_directory = "~/.config/qutebrowser" |
| 42 | +profile_directory = "profile" |
| 43 | +generate_desktop_file = false |
| 44 | +desktop_file_directory = "desktop" |
| 45 | +menu = "~/bin/my-dmenu" |
| 46 | +menu_prompt = "qbpm" |
| 47 | + """) |
| 48 | + assert find_config(file) == Config( |
| 49 | + config_py_template="config.load_autoconfig()\n", |
| 50 | + qutebrowser_config_directory=Path("~/.config/qutebrowser").expanduser(), |
| 51 | + profile_directory=Path("profile"), |
| 52 | + desktop_file_directory=Path("desktop"), |
| 53 | + generate_desktop_file=False, |
| 54 | + menu="~/bin/my-dmenu", |
| 55 | + menu_prompt="qbpm", |
| 56 | + ) |
| 57 | + |
| 58 | + |
| 59 | +def test_find_qb_config(tmp_path: Path): |
| 60 | + qb_dir = tmp_path / "qb" |
| 61 | + qb_conf_dir = qb_dir / "config" |
| 62 | + qb_conf_dir.mkdir(parents=True) |
| 63 | + (qb_conf_dir / "config.py").touch() |
| 64 | + assert find_qutebrowser_config_dir(qb_dir) == qb_conf_dir |
| 65 | + assert find_qutebrowser_config_dir(qb_dir / "config") == qb_conf_dir |
| 66 | + |
| 67 | + |
| 68 | +def test_find_qb_config_default(tmp_path: Path): |
| 69 | + (tmp_path / "config.py").touch() |
| 70 | + assert find_qutebrowser_config_dir(None) == tmp_path |
| 71 | + |
| 72 | + |
| 73 | +def test_find_qutebrowser_none(tmp_path: Path): |
| 74 | + assert find_qutebrowser_config_dir(None) is None |
| 75 | + assert find_qutebrowser_config_dir(tmp_path / "config") is None |
0 commit comments