1
- import getpass
2
1
import logging
3
2
import os
4
3
import pathlib
4
+ import shutil
5
5
import typing as t
6
6
7
7
import pytest
8
8
9
9
from _pytest .doctest import DoctestItem
10
- from _pytest .fixtures import SubRequest
11
10
12
- from libtmux import exc
13
- from libtmux .common import which
14
- from libtmux .server import Server
15
- from libtmux .test import TEST_SESSION_PREFIX , get_test_session_name , namer
11
+ from libtmux .test import namer
16
12
from tests .fixtures import utils as test_utils
17
13
18
14
if t .TYPE_CHECKING :
22
18
USING_ZSH = "zsh" in os .getenv ("SHELL" , "" )
23
19
24
20
25
- @pytest .fixture (autouse = True , scope = "session" )
26
- def home_path (tmp_path_factory : pytest .TempPathFactory ):
27
- return tmp_path_factory .mktemp ("home" )
28
-
29
-
30
- @pytest .fixture (autouse = True , scope = "session" )
31
- def user_path (home_path : pathlib .Path ):
32
- p = home_path / getpass .getuser ()
33
- p .mkdir ()
34
- return p
35
-
36
-
37
21
@pytest .mark .skipif (USING_ZSH , reason = "Using ZSH" )
38
22
@pytest .fixture (autouse = USING_ZSH , scope = "session" )
39
23
def zshrc (user_path : pathlib .Path ):
@@ -47,8 +31,8 @@ def zshrc(user_path: pathlib.Path):
47
31
48
32
49
33
@pytest .fixture (autouse = True )
50
- def home_path_default (user_path : pathlib .Path ):
51
- os . environ [ "HOME" ] = str (user_path )
34
+ def home_path_default (monkeypatch : pytest . MonkeyPatch , user_path : pathlib .Path ) -> None :
35
+ monkeypatch . setenv ( "HOME" , str (user_path ) )
52
36
53
37
54
38
@pytest .fixture (scope = "function" )
@@ -70,77 +54,12 @@ def socket_name(request) -> str:
70
54
return "tmuxp_test%s" % next (namer )
71
55
72
56
73
- @pytest .fixture (scope = "function" )
74
- def server (
75
- request : SubRequest , monkeypatch : pytest .MonkeyPatch , socket_name : str
76
- ) -> Server :
77
- tmux = Server (socket_name = socket_name )
78
-
79
- def fin () -> None :
80
- tmux .kill_server ()
81
-
82
- request .addfinalizer (fin )
83
-
84
- return tmux
85
-
86
-
87
- @pytest .fixture (scope = "function" )
88
- def session (server ):
89
- session_name = "tmuxp"
90
-
91
- if not server .has_session (session_name ):
92
- server .cmd (
93
- "-f" ,
94
- "/dev/null" , # use a blank config to reduce side effects
95
- "new-session" ,
96
- "-d" , # detached
97
- "-s" ,
98
- session_name ,
99
- "/bin/sh" , # use /bin/sh as a shell to reduce side effects
100
- # normally, it'd be -c, but new-session is special
101
- )
102
-
103
- # find current sessions prefixed with tmuxp
104
- old_test_sessions = [
105
- s .get ("session_name" )
106
- for s in server ._sessions
107
- if s .get ("session_name" ).startswith (TEST_SESSION_PREFIX )
108
- ]
109
-
110
- TEST_SESSION_NAME = get_test_session_name (server = server )
111
-
112
- try :
113
- session = server .new_session (session_name = TEST_SESSION_NAME )
114
- except exc .LibTmuxException as e :
115
- raise e
116
-
117
- """
118
- Make sure that tmuxp can :ref:`test_builder_visually` and switches to
119
- the newly created session for that testcase.
120
- """
121
- session_id = session .get ("session_id" )
122
- assert session_id is not None
123
- try :
124
- server .switch_client (target_session = session_id )
125
- except exc .LibTmuxException :
126
- # server.attach_session(session.get('session_id'))
127
- pass
128
-
129
- for old_test_session in old_test_sessions :
130
- logger .debug ("Old test test session %s found. Killing it." % old_test_session )
131
- server .kill_session (old_test_session )
132
- assert TEST_SESSION_NAME == session .get ("session_name" )
133
- assert TEST_SESSION_NAME != "tmuxp"
134
-
135
- return session
136
-
137
-
138
57
@pytest .fixture (autouse = True )
139
58
def add_doctest_fixtures (
140
- request : SubRequest ,
59
+ request : pytest . FixtureRequest ,
141
60
doctest_namespace : t .Dict [str , t .Any ],
142
61
) -> None :
143
- if isinstance (request ._pyfuncitem , DoctestItem ) and which ("tmux" ):
62
+ if isinstance (request ._pyfuncitem , DoctestItem ) and shutil . which ("tmux" ):
144
63
doctest_namespace ["server" ] = request .getfixturevalue ("server" )
145
64
session : "Session" = request .getfixturevalue ("session" )
146
65
doctest_namespace ["session" ] = session
0 commit comments