Skip to content

Commit 38c3dcc

Browse files
committed
tests: Use home default directory
1 parent f180a74 commit 38c3dcc

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import getpass
12
import logging
23
import os
4+
import pathlib
35

46
import pytest
57

@@ -10,6 +12,23 @@
1012
logger = logging.getLogger(__name__)
1113

1214

15+
@pytest.fixture(autouse=True, scope="session")
16+
def home_path(tmp_path_factory: pytest.TempPathFactory):
17+
return tmp_path_factory.mktemp("home")
18+
19+
20+
@pytest.fixture(autouse=True, scope="session")
21+
def user_path(home_path: pathlib.Path):
22+
p = home_path / getpass.getuser()
23+
p.mkdir()
24+
return p
25+
26+
27+
@pytest.fixture(autouse=True)
28+
def home_path_default(user_path: pathlib.Path):
29+
os.environ["HOME"] = str(user_path)
30+
31+
1332
@pytest.fixture(scope="function")
1433
def monkeypatch_plugin_test_packages(monkeypatch):
1534
paths = [

tests/test_config.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from tmuxp import config, exc
1111

1212
from . import EXAMPLE_PATH
13-
from .fixtures import config as fixtures
1413

1514
TMUXP_DIR = pathlib.Path(__file__).parent / ".tmuxp"
1615

@@ -32,6 +31,8 @@ def load_config(path: Union[str, pathlib.Path]) -> str:
3231

3332

3433
def test_export_json(tmp_path: pathlib.Path):
34+
from .fixtures import config as fixtures
35+
3536
json_config_file = tmp_path / "config.json"
3637

3738
configparser = kaptan.Kaptan()
@@ -47,6 +48,8 @@ def test_export_json(tmp_path: pathlib.Path):
4748

4849

4950
def test_export_yaml(tmp_path: pathlib.Path):
51+
from .fixtures import config as fixtures
52+
5053
yaml_config_file = tmp_path / "config.yaml"
5154

5255
configparser = kaptan.Kaptan()
@@ -92,17 +95,18 @@ def test_scan_config(tmp_path: pathlib.Path):
9295

9396
def test_config_expand1():
9497
"""Expand shell commands from string to list."""
98+
from .fixtures import config as fixtures
99+
95100
test_config = config.expand(fixtures.expand1.before_config)
96101
assert test_config == fixtures.expand1.after_config
97102

98103

99104
def test_config_expand2():
100105
"""Expand shell commands from string to list."""
106+
from .fixtures import config as fixtures
101107

102108
unexpanded_dict = load_yaml(fixtures.expand2.unexpanded_yaml)
103-
104109
expanded_dict = load_yaml(fixtures.expand2.expanded_yaml)
105-
106110
assert config.expand(unexpanded_dict) == expanded_dict
107111

108112

@@ -220,6 +224,8 @@ def test_inheritance_config():
220224

221225
def test_shell_command_before():
222226
"""Config inheritance for the nested 'start_command'."""
227+
from .fixtures import config as fixtures
228+
223229
test_config = fixtures.shell_command_before.config_unexpanded
224230
test_config = config.expand(test_config)
225231

@@ -230,6 +236,8 @@ def test_shell_command_before():
230236

231237

232238
def test_in_session_scope():
239+
from .fixtures import config as fixtures
240+
233241
sconfig = load_yaml(fixtures.shell_command_before_session.before)
234242

235243
config.validate_schema(sconfig)
@@ -241,6 +249,8 @@ def test_in_session_scope():
241249

242250

243251
def test_trickle_relative_start_directory():
252+
from .fixtures import config as fixtures
253+
244254
test_config = config.trickle(fixtures.trickle.before)
245255
assert test_config == fixtures.trickle.expected
246256

@@ -290,6 +300,7 @@ def test_expands_blank_panes():
290300
'shell_command': ['']
291301
292302
"""
303+
from .fixtures import config as fixtures
293304

294305
yaml_config_file = EXAMPLE_PATH / "blank-panes.yaml"
295306
test_config = load_config(yaml_config_file)

0 commit comments

Comments
 (0)