|
| 1 | +import getpass |
1 | 2 | import logging
|
2 | 3 | import os
|
| 4 | +import pathlib |
3 | 5 | import shutil
|
4 | 6 | import typing as t
|
5 | 7 |
|
|
17 | 19 | from libtmux.session import Session
|
18 | 20 |
|
19 | 21 | logger = logging.getLogger(__name__)
|
| 22 | +USING_ZSH = "zsh" in os.getenv("SHELL", "") |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture(autouse=True, scope="session") |
| 26 | +def home_path(tmp_path_factory: pytest.TempPathFactory) -> pathlib.Path: |
| 27 | + return tmp_path_factory.mktemp("home") |
| 28 | + |
| 29 | + |
| 30 | +@pytest.fixture(autouse=True, scope="session") |
| 31 | +def user_path(home_path: pathlib.Path) -> pathlib.Path: |
| 32 | + p = home_path / getpass.getuser() |
| 33 | + p.mkdir() |
| 34 | + return p |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.skipif(USING_ZSH, reason="Using ZSH") |
| 38 | +@pytest.fixture(autouse=USING_ZSH, scope="session") |
| 39 | +def zshrc(user_path: pathlib.Path) -> pathlib.Path: |
| 40 | + """This quiets ZSH default message. |
| 41 | +
|
| 42 | + Needs a startup file .zshenv, .zprofile, .zshrc, .zlogin. |
| 43 | + """ |
| 44 | + p = user_path / ".zshrc" |
| 45 | + p.touch() |
| 46 | + return p |
| 47 | + |
| 48 | + |
| 49 | +@pytest.fixture(scope="function") |
| 50 | +def config_file(user_path: pathlib.Path) -> pathlib.Path: |
| 51 | + """Set default tmux configuration (base indexes for windows, panes) |
| 52 | +
|
| 53 | + We need this for tests to work across tmux versions in our CI matrix. |
| 54 | + """ |
| 55 | + c = user_path / ".tmux.conf" |
| 56 | + c.write_text( |
| 57 | + """ |
| 58 | +set -g base-index 1 |
| 59 | + """, |
| 60 | + encoding="utf-8", |
| 61 | + ) |
| 62 | + return c |
20 | 63 |
|
21 | 64 |
|
22 | 65 | @pytest.fixture(autouse=True)
|
@@ -48,9 +91,10 @@ def clear_env(monkeypatch: MonkeyPatch) -> None:
|
48 | 91 |
|
49 | 92 |
|
50 | 93 | @pytest.fixture(scope="function")
|
51 |
| -def server(request: SubRequest, monkeypatch: MonkeyPatch) -> Server: |
52 |
| - |
53 |
| - t = Server() |
| 94 | +def server( |
| 95 | + request: SubRequest, monkeypatch: MonkeyPatch, config_file: pathlib.Path |
| 96 | +) -> Server: |
| 97 | + t = Server(config_file=str(config_file.absolute())) |
54 | 98 | t.socket_name = "libtmux_test%s" % next(namer)
|
55 | 99 |
|
56 | 100 | def fin() -> None:
|
|
0 commit comments