Skip to content

Commit a544eb6

Browse files
committed
patch qbpm.paths to prevent tests touching $HOME
they didn't before either, this is just more complete
1 parent bf8b65b commit a544eb6

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

tests/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
6+
@pytest.fixture(autouse=True)
7+
def no_homedir_fixture(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
8+
monkeypatch.setattr("qbpm.paths.default_qbpm_config_dir", lambda: tmp_path)
9+
monkeypatch.setattr("qbpm.paths.default_qbpm_application_dir", lambda: tmp_path)
10+
monkeypatch.setattr("qbpm.paths.default_profile_dir", lambda: tmp_path)

tests/test_choose.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from qbpm.choose import choose_profile, find_menu
55

6+
from . import no_homedir_fixture # noqa: F401
7+
68

79
def write_script(parent_dir: Path, name: str = "menu", contents: str = "") -> Path:
810
parent_dir.mkdir(exist_ok=True)

tests/test_main.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
from qbpm.main import main
77

8-
no_desktop = "--no-desktop-file"
8+
from . import no_homedir_fixture # noqa: F401
9+
10+
11+
def run(*args: str):
12+
return CliRunner().invoke(main, args)
913

1014

1115
def test_profile_dir_option(tmp_path: Path):
1216
(tmp_path / "config.py").touch()
13-
runner = CliRunner()
14-
result = runner.invoke(
15-
main, ["-P", str(tmp_path), "new", "-C", str(tmp_path), no_desktop, "test"]
16-
)
17+
result = run("-P", str(tmp_path), "new", "-C", str(tmp_path), "test")
1718
assert result.exit_code == 0
1819
assert result.output.strip() == str(tmp_path / "test")
1920
assert tmp_path / "test" in list(tmp_path.iterdir())
@@ -22,8 +23,7 @@ def test_profile_dir_option(tmp_path: Path):
2223
def test_profile_dir_env(tmp_path: Path):
2324
environ["QBPM_PROFILE_DIR"] = str(tmp_path)
2425
(tmp_path / "config.py").touch()
25-
runner = CliRunner()
26-
result = runner.invoke(main, ["new", "-C", str(tmp_path), no_desktop, "test"])
26+
result = run("new", "-C", str(tmp_path), "test")
2727
assert result.exit_code == 0
2828
assert result.output.strip() == str(tmp_path / "test")
2929
assert tmp_path / "test" in list(tmp_path.iterdir())
@@ -33,8 +33,7 @@ def test_config_dir_option(tmp_path: Path):
3333
environ["QBPM_PROFILE_DIR"] = str(tmp_path)
3434
config = tmp_path / "config.py"
3535
config.touch()
36-
runner = CliRunner()
37-
result = runner.invoke(main, ["new", "-C", str(tmp_path), no_desktop, "test"])
36+
result = run("new", "-C", str(tmp_path), "test")
3837
assert result.exit_code == 0
3938
assert str(config) in (tmp_path / "test/config/config.py").read_text()
4039

@@ -44,8 +43,7 @@ def test_relative_config_dir(tmp_path: Path):
4443
config = tmp_path / "config.py"
4544
config.touch()
4645
chdir(tmp_path)
47-
runner = CliRunner()
48-
result = runner.invoke(main, ["new", "-C", ".", no_desktop, "test"])
46+
result = run("new", "-C", ".", "test")
4947
assert result.exit_code == 0
5048
assert str(config) in (tmp_path / "test/config/config.py").read_text()
5149

@@ -55,10 +53,7 @@ def test_from_session(tmp_path: Path):
5553
(tmp_path / "config.py").touch()
5654
session = tmp_path / "test.yml"
5755
session.write_text("windows:\n")
58-
runner = CliRunner()
59-
result = runner.invoke(
60-
main, ["from-session", "-C", str(tmp_path), no_desktop, str(session)]
61-
)
56+
result = run("from-session", "-C", str(tmp_path), str(session))
6257
assert result.exit_code == 0
6358
assert result.output.strip() == str(tmp_path / "test")
6459
assert (tmp_path / "test/data/sessions/_autosave.yml").read_text() == ("windows:\n")

tests/test_profiles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from qbpm import profiles
44
from qbpm.profiles import Profile
55

6+
from . import no_homedir_fixture # noqa: F401
7+
68

79
def check_is_empty(path: Path):
810
assert len(list(path.iterdir())) == 0

0 commit comments

Comments
 (0)