Skip to content

Commit 2d68c37

Browse files
committed
refactor(test_cli, get_{teamocil,tmuxinator}_dir): To pathlib
1 parent 53f03e8 commit 2d68c37

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/tmuxp/cli/import_config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,41 @@
1111
from .utils import prompt, prompt_choices, prompt_yes_no, tmuxp_echo
1212

1313

14-
def get_tmuxinator_dir() -> str:
14+
def get_tmuxinator_dir() -> pathlib.Path:
1515
"""
1616
Return tmuxinator configuration directory.
1717
1818
Checks for ``TMUXINATOR_CONFIG`` environmental variable.
1919
2020
Returns
2121
-------
22-
str :
22+
pathlib.Path :
2323
absolute path to tmuxinator config directory
2424
2525
See Also
2626
--------
2727
:meth:`tmuxp.workspace.importers.tmuxinator.import_tmuxinator`
2828
"""
2929
if "TMUXINATOR_CONFIG" in os.environ:
30-
return os.path.expanduser(os.environ["TMUXINATOR_CONFIG"])
30+
return pathlib.Path(os.environ["TMUXINATOR_CONFIG"]).expanduser()
3131

32-
return os.path.expanduser("~/.tmuxinator/")
32+
return pathlib.Path("~/.tmuxinator/").expanduser()
3333

3434

35-
def get_teamocil_dir() -> str:
35+
def get_teamocil_dir() -> pathlib.Path:
3636
"""
3737
Return teamocil configuration directory.
3838
3939
Returns
4040
-------
41-
str :
41+
pathlib.Path :
4242
absolute path to teamocil config directory
4343
4444
See Also
4545
--------
4646
:meth:`tmuxp.workspace.importers.teamocil.import_teamocil`
4747
"""
48-
return os.path.expanduser("~/.teamocil/")
48+
return pathlib.Path("~/.teamocil/").expanduser()
4949

5050

5151
def _resolve_path_no_overwrite(workspace_file: str) -> str:

tests/cli/test_cli.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import contextlib
3-
import os
43
import pathlib
54
import typing as t
65

@@ -27,7 +26,7 @@ def test_creates_config_dir_not_exists(tmp_path: pathlib.Path) -> None:
2726
"""cli.startup() creates config dir if not exists."""
2827

2928
cli.startup(tmp_path)
30-
assert os.path.exists(tmp_path)
29+
assert tmp_path.exists()
3130

3231

3332
@pytest.mark.parametrize(
@@ -56,26 +55,28 @@ def test_resolve_behavior(
5655
) -> None:
5756
expect = tmp_path
5857
monkeypatch.chdir(tmp_path)
59-
assert pathlib.Path("../").resolve() == pathlib.Path(os.path.dirname(expect))
58+
assert pathlib.Path("../").resolve() == expect.parent
6059
assert pathlib.Path().resolve() == expect
6160
assert pathlib.Path("./").resolve() == expect
6261
assert pathlib.Path(expect).resolve() == expect
6362

6463

6564
def test_get_tmuxinator_dir(monkeypatch: pytest.MonkeyPatch) -> None:
66-
assert get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")
65+
assert get_tmuxinator_dir() == pathlib.Path("~/.tmuxinator").expanduser()
6766

6867
monkeypatch.setenv("HOME", "/moo")
69-
assert get_tmuxinator_dir() == "/moo/.tmuxinator/"
70-
assert get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")
68+
assert get_tmuxinator_dir() == pathlib.Path("/moo/.tmuxinator/")
69+
assert str(get_tmuxinator_dir()) == "/moo/.tmuxinator"
70+
assert get_tmuxinator_dir() == pathlib.Path("~/.tmuxinator/").expanduser()
7171

7272

7373
def test_get_teamocil_dir(monkeypatch: pytest.MonkeyPatch) -> None:
74-
assert get_teamocil_dir() == os.path.expanduser("~/.teamocil/")
74+
assert get_teamocil_dir() == pathlib.Path("~/.teamocil/").expanduser()
7575

7676
monkeypatch.setenv("HOME", "/moo")
77-
assert get_teamocil_dir() == "/moo/.teamocil/"
78-
assert get_teamocil_dir() == os.path.expanduser("~/.teamocil/")
77+
assert get_teamocil_dir() == pathlib.Path("/moo/.teamocil/")
78+
assert str(get_teamocil_dir()) == "/moo/.teamocil"
79+
assert get_teamocil_dir() == pathlib.Path("~/.teamocil/").expanduser()
7980

8081

8182
def test_pass_config_dir_ClickPath(

0 commit comments

Comments
 (0)