|
1 |
| -import getpass |
2 |
| -import logging |
3 |
| -import os |
4 |
| -import pathlib |
5 |
| - |
6 |
| -import pytest |
7 |
| - |
8 |
| -from libtmux import exc |
9 |
| -from libtmux.server import Server |
10 |
| -from libtmux.test import TEST_SESSION_PREFIX, get_test_session_name, namer |
11 |
| - |
12 |
| -logger = logging.getLogger(__name__) |
13 |
| -USING_ZSH = "zsh" in os.getenv("SHELL", "") |
14 |
| - |
15 |
| - |
16 |
| -@pytest.fixture(autouse=True, scope="session") |
17 |
| -def home_path(tmp_path_factory: pytest.TempPathFactory): |
18 |
| - return tmp_path_factory.mktemp("home") |
19 |
| - |
20 |
| - |
21 |
| -@pytest.fixture(autouse=True, scope="session") |
22 |
| -def user_path(home_path: pathlib.Path): |
23 |
| - p = home_path / getpass.getuser() |
24 |
| - p.mkdir() |
25 |
| - return p |
26 |
| - |
27 |
| - |
28 |
| -@pytest.mark.skipif(USING_ZSH, reason="Using ZSH") |
29 |
| -@pytest.fixture(autouse=USING_ZSH, scope="session") |
30 |
| -def zshrc(user_path: pathlib.Path): |
31 |
| - """This quiets ZSH default message. |
32 |
| -
|
33 |
| - Needs a startup file .zshenv, .zprofile, .zshrc, .zlogin. |
34 |
| - """ |
35 |
| - p = user_path / ".zshrc" |
36 |
| - p.touch() |
37 |
| - return p |
38 |
| - |
39 |
| - |
40 |
| -@pytest.fixture(autouse=True) |
41 |
| -def home_path_default(user_path: pathlib.Path): |
42 |
| - os.environ["HOME"] = str(user_path) |
43 |
| - |
44 |
| - |
45 |
| -@pytest.fixture(scope="function") |
46 |
| -def monkeypatch_plugin_test_packages(monkeypatch): |
47 |
| - paths = [ |
48 |
| - "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_bwb/", |
49 |
| - "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_bs/", |
50 |
| - "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_r/", |
51 |
| - "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_owc/", |
52 |
| - "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_awf/", |
53 |
| - "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_fail/", |
54 |
| - ] |
55 |
| - for path in paths: |
56 |
| - monkeypatch.syspath_prepend(os.path.abspath(os.path.relpath(path))) |
57 |
| - |
58 |
| - |
59 |
| -@pytest.fixture(scope="function") |
60 |
| -def socket_name(request): |
61 |
| - return "tmuxp_test%s" % next(namer) |
62 |
| - |
63 |
| - |
64 |
| -@pytest.fixture(scope="function") |
65 |
| -def server(request, socket_name): |
66 |
| - t = Server() |
67 |
| - t.socket_name = socket_name |
68 |
| - |
69 |
| - def fin(): |
70 |
| - t.kill_server() |
71 |
| - |
72 |
| - request.addfinalizer(fin) |
73 |
| - |
74 |
| - return t |
75 |
| - |
76 |
| - |
77 |
| -@pytest.fixture(scope="function") |
78 |
| -def session(server): |
79 |
| - session_name = "tmuxp" |
80 |
| - |
81 |
| - if not server.has_session(session_name): |
82 |
| - server.cmd( |
83 |
| - "-f", |
84 |
| - "/dev/null", # use a blank config to reduce side effects |
85 |
| - "new-session", |
86 |
| - "-d", # detached |
87 |
| - "-s", |
88 |
| - session_name, |
89 |
| - "/bin/sh", # use /bin/sh as a shell to reduce side effects |
90 |
| - # normally, it'd be -c, but new-session is special |
91 |
| - ) |
92 |
| - |
93 |
| - # find current sessions prefixed with tmuxp |
94 |
| - old_test_sessions = [ |
95 |
| - s.get("session_name") |
96 |
| - for s in server._sessions |
97 |
| - if s.get("session_name").startswith(TEST_SESSION_PREFIX) |
98 |
| - ] |
99 |
| - |
100 |
| - TEST_SESSION_NAME = get_test_session_name(server=server) |
101 |
| - |
102 |
| - try: |
103 |
| - session = server.new_session(session_name=TEST_SESSION_NAME) |
104 |
| - except exc.LibTmuxException as e: |
105 |
| - raise e |
106 |
| - |
107 |
| - """ |
108 |
| - Make sure that tmuxp can :ref:`test_builder_visually` and switches to |
109 |
| - the newly created session for that testcase. |
110 |
| - """ |
111 |
| - try: |
112 |
| - server.switch_client(session.get("session_id")) |
113 |
| - except exc.LibTmuxException: |
114 |
| - # server.attach_session(session.get('session_id')) |
115 |
| - pass |
116 |
| - |
117 |
| - for old_test_session in old_test_sessions: |
118 |
| - logger.debug("Old test test session %s found. Killing it." % old_test_session) |
119 |
| - server.kill_session(old_test_session) |
120 |
| - assert TEST_SESSION_NAME == session.get("session_name") |
121 |
| - assert TEST_SESSION_NAME != "tmuxp" |
122 |
| - |
123 |
| - return session |
| 1 | +from tmuxp.conftest import * # noqa F40 |
0 commit comments