@@ -219,7 +219,21 @@ class tmux_cmd:
219219 Renamed from ``tmux`` to ``tmux_cmd``.
220220 """
221221
222- def __init__ (self , * args : t .Any ) -> None :
222+ def __init__ (
223+ self ,
224+ * args : t .Any ,
225+ cmd : list [str ] | None = None ,
226+ stdout : list [str ] | None = None ,
227+ stderr : list [str ] | None = None ,
228+ returncode : int | None = None ,
229+ ) -> None :
230+ if cmd is not None :
231+ self .cmd = cmd
232+ self .stdout = stdout or []
233+ self .stderr = stderr or []
234+ self .returncode = returncode
235+ return
236+
223237 tmux_bin = shutil .which ("tmux" )
224238 if not tmux_bin :
225239 raise exc .TmuxCommandNotFound
@@ -238,20 +252,20 @@ def __init__(self, *args: t.Any) -> None:
238252 text = True ,
239253 errors = "backslashreplace" ,
240254 )
241- stdout , stderr = self .process .communicate ()
255+ stdout_str , stderr_str = self .process .communicate ()
242256 returncode = self .process .returncode
243257 except Exception :
244258 logger .exception (f"Exception for { subprocess .list2cmdline (cmd )} " )
245259 raise
246260
247261 self .returncode = returncode
248262
249- stdout_split = stdout .split ("\n " )
263+ stdout_split = stdout_str .split ("\n " )
250264 # remove trailing newlines from stdout
251265 while stdout_split and stdout_split [- 1 ] == "" :
252266 stdout_split .pop ()
253267
254- stderr_split = stderr .split ("\n " )
268+ stderr_split = stderr_str .split ("\n " )
255269 self .stderr = list (filter (None , stderr_split )) # filter empty values
256270
257271 if "has-session" in cmd and len (self .stderr ) and not stdout_split :
0 commit comments