diff --git a/CHANGES b/CHANGES index 79c8901caf..5902f33aee 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,13 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force +### Breaking change + +- libtmux 0.16 -> 0.17 (#850) + + This includes the API overhaul from + [libtmux#426](https://github.com/tmux-python/libtmux/pull/426). + ### Developmental - Tests: Stabilization fix for automatic rename test (#853) diff --git a/docs/api.md b/docs/api.md index 7897b05bc8..7e1ac090a0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -23,10 +23,6 @@ If you need an internal API stabilized please [file an issue](https://github.com .. automethod:: tmuxp.util.oh_my_zsh_auto_title ``` -```{eval-rst} -.. automethod:: tmuxp.util.raise_if_tmux_not_running -``` - ```{eval-rst} .. automethod:: tmuxp.util.get_current_pane ``` diff --git a/docs/quickstart.md b/docs/quickstart.md index 3542312b8f..3b41fe9606 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -145,10 +145,10 @@ AL - [Abstraction Layer][abstraction layer] | {ref}`tmuxp python api ` | {term}`tmux(1)` equivalent | | ------------------------------------- | -------------------------- | | {meth}`libtmux.Server.new_session` | `$ tmux new-session` | -| {meth}`libtmux.Server.list_sessions` | `$ tmux list-sessions` | -| {meth}`libtmux.Session.list_windows` | `$ tmux list-windows` | +| {meth}`libtmux.Server.sessions` | `$ tmux list-sessions` | +| {meth}`libtmux.Session.windows` | `$ tmux list-windows` | | {meth}`libtmux.Session.new_window` | `$ tmux new-window` | -| {meth}`libtmux.Window.list_panes` | `$ tmux list-panes` | +| {meth}`libtmux.Window.panes` | `$ tmux list-panes` | | {meth}`libtmux.Window.split_window` | `$ tmux split-window` | | {meth}`libtmux.Pane.send_keys` | `$ tmux send-keys` | diff --git a/poetry.lock b/poetry.lock index 990bb14f84..4409e9c089 100644 --- a/poetry.lock +++ b/poetry.lock @@ -313,7 +313,7 @@ i18n = ["Babel (>=2.7)"] [[package]] name = "libtmux" -version = "0.16.1" +version = "0.17.0a1" description = "Typed scripting library / ORM / API wrapper for tmux" category = "main" optional = false @@ -999,7 +999,7 @@ test = [] [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "90bd0d1dce1124ed4749e25537a2b3265e492010c91d37750e221cae82236496" +content-hash = "702c7aa0fbb74d088c5f3cb283aed15d8318927f0c2709bc8b9d41382a2237af" [metadata.files] aafigure = [ @@ -1164,8 +1164,8 @@ jinja2 = [ {file = "Jinja2-3.1.2.tar.gz", hash = "sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852"}, ] libtmux = [ - {file = "libtmux-0.16.1-py3-none-any.whl", hash = "sha256:dd00c46f2ff828df9f24be17e499b80c8f8f9165b766ba589c5acf98a5cfdef7"}, - {file = "libtmux-0.16.1.tar.gz", hash = "sha256:4b5b74e70e0edf2e7a5c1a841fffcd78e1f203205ced9c9b0dd325a6d903d0ed"}, + {file = "libtmux-0.17.0a1-py3-none-any.whl", hash = "sha256:854cb922d0f960b1e6bcebe4f92eb47a3098d9310b3621722cc63a3df21946cf"}, + {file = "libtmux-0.17.0a1.tar.gz", hash = "sha256:aa4744e102f1fc181cc1493e79595464076f3ebf963e6dac060295b8c5bf0cd2"}, ] livereload = [ {file = "livereload-2.6.3.tar.gz", hash = "sha256:776f2f865e59fde56490a56bcc6773b6917366bce0c267c60ee8aaf1a0959869"}, diff --git a/pyproject.toml b/pyproject.toml index 5cd251205b..1f3edf2a3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ tmuxp = 'tmuxp:cli.cli' [tool.poetry.dependencies] python = "^3.7" -libtmux = "~0.16.1" +libtmux = "0.17.0a1" colorama = ">=0.3.9" PyYAML = "^6.0" diff --git a/src/tmuxp/cli/freeze.py b/src/tmuxp/cli/freeze.py index 62422c3f14..2383a435ba 100644 --- a/src/tmuxp/cli/freeze.py +++ b/src/tmuxp/cli/freeze.py @@ -32,7 +32,7 @@ class CLIFreezeNamespace(argparse.Namespace): def session_completion(ctx, params, incomplete): server = Server() - choices = [session.name for session in server.list_sessions()] + choices = [session.name for session in server.sessions] return sorted(str(c) for c in choices if str(c).startswith(incomplete)) @@ -100,7 +100,7 @@ def command_freeze( try: if args.session_name: - session = server.find_where({"session_name": args.session_name}) + session = server.sessions.get(session_name=args.session_name, default=None) else: session = util.get_session(server) diff --git a/src/tmuxp/cli/shell.py b/src/tmuxp/cli/shell.py index f9cf6521e7..9be9b86308 100644 --- a/src/tmuxp/cli/shell.py +++ b/src/tmuxp/cli/shell.py @@ -142,7 +142,7 @@ def command_shell( """ server = Server(socket_name=args.socket_name, socket_path=args.socket_path) - util.raise_if_tmux_not_running(server=server) + server.raise_if_dead() current_pane = util.get_current_pane(server=server) diff --git a/src/tmuxp/util.py b/src/tmuxp/util.py index 61c20669a7..b70a61ea00 100644 --- a/src/tmuxp/util.py +++ b/src/tmuxp/util.py @@ -11,7 +11,6 @@ import sys from libtmux._compat import console_to_str -from libtmux.exc import LibTmuxException from . import exc @@ -75,49 +74,31 @@ def oh_my_zsh_auto_title(): ) -def raise_if_tmux_not_running(server): - """Raise exception if not running. More descriptive error if no server found.""" - try: - server.sessions - except LibTmuxException as e: - if any( - needle in str(e) - for needle in ["No such file or directory", "no server running on"] - ): - raise LibTmuxException( - "no tmux session found. Start a tmux session and try again. \n" - "Original error: " + str(e) - ) - else: - raise e - - def get_current_pane(server): """Return Pane if one found in env""" if os.getenv("TMUX_PANE") is not None: try: - return [ - p - for p in server._list_panes() - if p.get("pane_id") == os.getenv("TMUX_PANE") - ][0] + return [p for p in server.panes if p.pane_id == os.getenv("TMUX_PANE")][0] except IndexError: pass def get_session(server, session_name=None, current_pane=None): - if session_name: - session = server.find_where({"session_name": session_name}) - elif current_pane is not None: - session = server.find_where({"session_id": current_pane["session_id"]}) - else: - current_pane = get_current_pane(server) - if current_pane: - session = server.find_where({"session_id": current_pane["session_id"]}) + try: + if session_name: + session = server.sessions.get(session_name=session_name) + elif current_pane is not None: + session = server.sessions.get(session_id=current_pane.session_id) else: - session = server.list_sessions()[0] - - if not session: + current_pane = get_current_pane(server) + if current_pane: + session = server.sessions.get(session_id=current_pane.session_id) + else: + session = server.sessions[0] + except Exception: + session = None + + if session is None: if session_name: raise exc.TmuxpException("Session not found: %s" % session_name) else: @@ -127,14 +108,23 @@ def get_session(server, session_name=None, current_pane=None): def get_window(session, window_name=None, current_pane=None): - if window_name: - window = session.find_where({"window_name": window_name}) - if not window: + try: + if window_name: + window = session.windows.get(window_name=window_name) + elif current_pane is not None: + window = session.windows.get(window_id=current_pane.window_id) + else: + window = session.windows[0] + except Exception: + window = None + + if window is None: + if window_name: raise exc.TmuxpException("Window not found: %s" % window_name) - elif current_pane is not None: - window = session.find_where({"window_id": current_pane["window_id"]}) - else: - window = session.list_windows()[0] + if current_pane: + raise exc.TmuxpException("Window not found: %s" % current_pane) + else: + raise exc.TmuxpException("Window not found") return window @@ -142,11 +132,17 @@ def get_window(session, window_name=None, current_pane=None): def get_pane(window, current_pane=None): try: if current_pane is not None: - pane = window.find_where({"pane_id": current_pane["pane_id"]}) # NOQA: F841 + pane = window.panes.get(pane_id=current_pane.pane_id) # NOQA: F841 else: pane = window.attached_pane # NOQA: F841 except exc.TmuxpException as e: print(e) return + if pane is None: + if current_pane: + raise exc.TmuxpException("Pane not found: %s" % current_pane) + else: + raise exc.TmuxpException("Pane not found") + return pane diff --git a/src/tmuxp/workspace/builder.py b/src/tmuxp/workspace/builder.py index 5df4d2e415..0c5d986b87 100644 --- a/src/tmuxp/workspace/builder.py +++ b/src/tmuxp/workspace/builder.py @@ -71,7 +71,7 @@ class WorkspaceBuilder: >>> new_session.name == 'sample workspace' True - >>> len(new_session._windows) + >>> len(new_session.windows) 3 >>> sorted([window.name for window in new_session.windows]) @@ -79,7 +79,7 @@ class WorkspaceBuilder: **Existing session:** - >>> len(session._windows) + >>> len(session.windows) 1 >>> builder.build(session=session) @@ -89,7 +89,7 @@ class WorkspaceBuilder: >>> session.name == 'sample workspace' False - >>> len(session._windows) + >>> len(session.windows) 3 >>> sorted([window.name for window in session.windows]) @@ -174,7 +174,10 @@ def session_exists(self, session_name=None): if not exists: return exists - self.session = self.server.find_where({"session_name": session_name}) + try: + self.session = self.server.sessions.filter(session_name=session_name)[0] + except IndexError: + return False return True def build(self, session=None, append=False): @@ -203,12 +206,17 @@ def build(self, session=None, append=False): ) if self.server.has_session(self.sconf["session_name"]): - self.session = self.server.find_where( - {"session_name": self.sconf["session_name"]} - ) - raise TmuxSessionExists( - "Session name %s is already running." % self.sconf["session_name"] - ) + try: + self.session = self.server.sessions.filter( + session_name=self.sconf["session_name"] + )[0] + + raise TmuxSessionExists( + "Session name %s is already running." + % self.sconf["session_name"] + ) + except IndexError: + pass else: new_session_kwargs = {} if "start_directory" in self.sconf: @@ -226,7 +234,7 @@ def build(self, session=None, append=False): self.session = session self.server = session.server - self.server._list_sessions() + self.server.sessions assert self.server.has_session(session.name) assert session.id @@ -378,7 +386,6 @@ def iter_create_windows(self, session, append=False): session.attached_window.kill_window() assert isinstance(w, Window) - session.server._update_windows() if "options" in wconf and isinstance(wconf["options"], dict): for key, val in wconf["options"].items(): w.set_window_option(key, val) @@ -386,8 +393,6 @@ def iter_create_windows(self, session, append=False): if "focus" in wconf and wconf["focus"]: w.select_window() - session.server._update_windows() - yield w, wconf def iter_create_panes(self, w, wconf): @@ -421,7 +426,6 @@ def iter_create_panes(self, w, wconf): else: def get_pane_start_directory(): - if "start_directory" in pconf: return pconf["start_directory"] elif "start_directory" in wconf: @@ -430,7 +434,6 @@ def get_pane_start_directory(): return None def get_pane_shell(): - if "shell" in pconf: return pconf["shell"] elif "window_shell" in wconf: @@ -486,7 +489,8 @@ def get_pane_shell(): time.sleep(sleep_after) if "focus" in pconf and pconf["focus"]: - w.select_pane(p["pane_id"]) + assert p.pane_id is not None + w.select_pane(p.pane_id) w.server._update_panes() @@ -519,8 +523,8 @@ def find_current_attached_session(self): return next( ( s - for s in self.server.list_sessions() - if s["session_id"] == current_active_pane["session_id"] + for s in self.server.sessions + if s.session_id == current_active_pane.session_id ), None, ) diff --git a/src/tmuxp/workspace/freezer.py b/src/tmuxp/workspace/freezer.py index 4580cd2c78..aed0bf4438 100644 --- a/src/tmuxp/workspace/freezer.py +++ b/src/tmuxp/workspace/freezer.py @@ -53,36 +53,36 @@ def freeze(session): dict tmuxp compatible workspace """ - sconf = {"session_name": session["session_name"], "windows": []} + sconf = {"session_name": session.session_name, "windows": []} for w in session.windows: wconf = { "options": w.show_window_options(), "window_name": w.name, - "layout": w.layout, + "layout": w.window_layout, "panes": [], } - if w.get("window_active", "0") == "1": + if getattr(w, "window_active", "0") == "1": wconf["focus"] = "true" # If all panes have same path, set 'start_directory' instead # of using 'cd' shell commands. def pane_has_same_path(p): - return w.panes[0].current_path == p.current_path + return w.panes[0].pane_current_path == p.pane_current_path if all(pane_has_same_path(p) for p in w.panes): - wconf["start_directory"] = w.panes[0].current_path + wconf["start_directory"] = w.panes[0].pane_current_path for p in w.panes: pconf = {"shell_command": []} if "start_directory" not in wconf: - pconf["shell_command"].append("cd " + p.current_path) + pconf["shell_command"].append("cd " + p.pane_current_path) - if p.get("pane_active", "0") == "1": + if getattr(p, "pane_active", "0") == "1": pconf["focus"] = "true" - current_cmd = p.current_command + current_cmd = p.pane_current_command def filter_interpretters_and_shells(): return current_cmd.startswith("-") or any( diff --git a/tests/test_cli.py b/tests/test_cli.py index beb90d98fc..ff8ce8cdef 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,6 +4,7 @@ import json import os import pathlib +import subprocess import typing as t import pytest @@ -12,7 +13,6 @@ import libtmux from libtmux.common import has_lt_version -from libtmux.exc import LibTmuxException from libtmux.server import Server from libtmux.session import Session from tmuxp import cli, exc @@ -195,7 +195,7 @@ def test_load_symlinked_workspace( assert session.name == "samplesimple" assert pane is not None - assert pane.current_path == str(realtemp) + assert pane.pane_current_path == str(realtemp) if t.TYPE_CHECKING: @@ -584,7 +584,7 @@ def test_shell( [], {}, {}, - LibTmuxException, + subprocess.CalledProcessError, r".*DoesNotExist.*", ), ( @@ -622,7 +622,9 @@ def test_shell_target_missing( inputs: t.List[t.Any], env: t.Dict[t.Any, t.Any], template_ctx: t.Dict[str, str], - exception: t.Union[t.Type[exc.TmuxpException], t.Type[LibTmuxException]], + exception: t.Union[ + t.Type[exc.TmuxpException], t.Type[subprocess.CalledProcessError] + ], message: str, socket_name: str, server: "Server", @@ -976,10 +978,9 @@ def test_freeze( server.new_session(session_name="myfrozensession") # Assign an active pane to the session - second_session = server.list_sessions()[1] - first_pane_on_second_session_id = second_session.list_windows()[0].list_panes()[0][ - "pane_id" - ] + second_session = server.sessions[1] + first_pane_on_second_session_id = second_session.windows[0].panes[0].pane_id + assert first_pane_on_second_session_id monkeypatch.setenv("TMUX_PANE", first_pane_on_second_session_id) monkeypatch.chdir(tmp_path) @@ -1362,17 +1363,18 @@ def test_load_append_windows_to_current_session( builder = WorkspaceBuilder(sconf=sconfig, server=server) builder.build() - assert len(server.list_sessions()) == 1 - assert len(server._list_windows()) == 3 + assert len(server.sessions) == 1 + assert len(server.windows) == 3 # Assign an active pane to the session - monkeypatch.setenv("TMUX_PANE", server._list_panes()[0]["pane_id"]) + assert server.panes[0].pane_id + monkeypatch.setenv("TMUX_PANE", server.panes[0].pane_id) builder = WorkspaceBuilder(sconf=sconfig, server=server) _load_append_windows_to_current_session(builder) - assert len(server.list_sessions()) == 1 - assert len(server._list_windows()) == 6 + assert len(server.sessions) == 1 + assert len(server.windows) == 6 def test_debug_info_cli( diff --git a/tests/test_util.py b/tests/test_util.py index 64acadf94f..008af37ead 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -54,9 +54,7 @@ def test_get_session_should_default_to_local_attached_session(server, monkeypatc second_session = server.new_session(session_name="mysecondsession") # Assign an active pane to the session - first_pane_on_second_session_id = second_session.list_windows()[0].list_panes()[0][ - "pane_id" - ] + first_pane_on_second_session_id = second_session.windows[0].panes[0].pane_id monkeypatch.setenv("TMUX_PANE", first_pane_on_second_session_id) assert get_session(server) == second_session diff --git a/tests/workspace/test_builder.py b/tests/workspace/test_builder.py index 90ee02e18b..7bca4ae477 100644 --- a/tests/workspace/test_builder.py +++ b/tests/workspace/test_builder.py @@ -32,16 +32,16 @@ def test_split_windows(session): builder = WorkspaceBuilder(sconf=workspace) - window_count = len(session._windows) # current window count - assert len(session._windows) == window_count + window_count = len(session.windows) # current window count + assert len(session.windows) == window_count for w, wconf in builder.iter_create_windows(session): for p in builder.iter_create_panes(w, wconf): w.select_layout("tiled") # fix glitch with pane size p = p - assert len(session._windows) == window_count + assert len(session.windows) == window_count assert isinstance(w, Window) - assert len(session._windows) == window_count + assert len(session.windows) == window_count window_count += 1 @@ -52,16 +52,16 @@ def test_split_windows_three_pane(session): builder = WorkspaceBuilder(sconf=workspace) - window_count = len(session._windows) # current window count - assert len(session._windows) == window_count + window_count = len(session.windows) # current window count + assert len(session.windows) == window_count for w, wconf in builder.iter_create_windows(session): for p in builder.iter_create_panes(w, wconf): w.select_layout("tiled") # fix glitch with pane size p = p - assert len(session._windows) == window_count + assert len(session.windows) == window_count assert isinstance(w, Window) - assert len(session._windows) == window_count + assert len(session.windows) == window_count window_count += 1 w.set_window_option("main-pane-height", 50) w.select_layout(wconf["layout"]) @@ -108,17 +108,16 @@ def f(): nonlocal p p = w.attached_pane p.server._update_panes() - return p.current_path == pane_path + return p.pane_current_path == pane_path assert retry_until(f) - assert p.current_path == pane_path + assert p.pane_current_path == pane_path proc = session.cmd("show-option", "-gv", "base-index") base_index = int(proc.stdout[0]) - session.server._update_windows() - window3 = session.find_where({"window_index": str(base_index + 2)}) + window3 = session.windows.get(window_index=str(base_index + 2)) assert isinstance(window3, Window) p = None @@ -128,11 +127,11 @@ def f(): nonlocal p p = window3.attached_pane p.server._update_panes() - return p.current_path == pane_path + return p.pane_current_path == pane_path assert retry_until(f) - assert p.current_path == pane_path + assert p.pane_current_path == pane_path @pytest.mark.skip( @@ -151,8 +150,8 @@ def test_suppress_history(session): builder = WorkspaceBuilder(sconf=workspace) builder.build(session=session) - inHistoryWindow = session.find_where({"window_name": "inHistory"}) - isMissingWindow = session.find_where({"window_name": "isMissing"}) + inHistoryWindow = session.windows.get(window_name="inHistory") + isMissingWindow = session.windows.get(window_name="isMissing") def assertHistory(cmd, hist): return "inHistory" in cmd and cmd.endswith(hist) @@ -255,19 +254,19 @@ def test_window_options(session): builder = WorkspaceBuilder(sconf=workspace) - window_count = len(session._windows) # current window count - assert len(session._windows) == window_count + window_count = len(session.windows) # current window count + assert len(session.windows) == window_count for w, wconf in builder.iter_create_windows(session): for p in builder.iter_create_panes(w, wconf): w.select_layout("tiled") # fix glitch with pane size p = p - assert len(session._windows) == window_count + assert len(session.windows) == window_count assert isinstance(w, Window) assert w.show_window_option("main-pane-height") == 5 if has_gte_version("2.3"): assert w.show_window_option("pane-border-format") == " #P " - assert len(session._windows) == window_count + assert len(session.windows) == window_count window_count += 1 w.select_layout(wconf["layout"]) @@ -324,8 +323,7 @@ def test_window_shell(session): assert wconf["window_shell"] == "top" def f(): - session.server._update_windows() - return w["window_name"] != "top" + return w.window_name != "top" retry_until(f) @@ -445,17 +443,16 @@ def test_automatic_rename_option( assert w.name != "renamed_window" def check_window_name_mismatch() -> bool: - w.server._update_windows() return w.name != portable_command assert retry_until(check_window_name_mismatch, 5, interval=0.25) def check_window_name_match() -> bool: - w.server._update_windows() assert w.show_window_option("automatic-rename") == "on" - - print(f"w.name: {w.name} and portable_command: {portable_command}") - return w.name == "zsh" or w.name == portable_command + return ( + w.name == pathlib.Path(os.getenv("SHELL", "bash")).name + or w.name == portable_command + ) assert retry_until( check_window_name_match, 4, interval=0.05 @@ -477,17 +474,17 @@ def test_blank_pane_count(session): assert session == builder.session - window1 = session.find_where({"window_name": "Blank pane test"}) - assert len(window1._panes) == 3 + window1 = session.windows.get(window_name="Blank pane test") + assert len(window1.panes) == 3 - window2 = session.find_where({"window_name": "More blank panes"}) - assert len(window2._panes) == 3 + window2 = session.windows.get(window_name="More blank panes") + assert len(window2.panes) == 3 - window3 = session.find_where({"window_name": "Empty string (return)"}) - assert len(window3._panes) == 3 + window3 = session.windows.get(window_name="Empty string (return)") + assert len(window3.panes) == 3 - window4 = session.find_where({"window_name": "Blank with options"}) - assert len(window4._panes) == 2 + window4 = session.windows.get(window_name="Blank with options") + assert len(window4.panes) == 2 def test_start_directory(session, tmp_path: pathlib.Path): @@ -514,7 +511,7 @@ def test_start_directory(session, tmp_path: pathlib.Path): def f(): p.server._update_panes() - pane_path = p.current_path + pane_path = p.pane_current_path return path in pane_path or pane_path == path # handle case with OS X adding /private/ to /tmp/ paths @@ -565,7 +562,7 @@ def test_start_directory_relative(session, tmp_path: pathlib.Path): def f(): p.server._update_panes() # Handle case where directories resolve to /private/ in OSX - pane_path = p.current_path + pane_path = p.pane_current_path return path in pane_path or pane_path == path assert retry_until(f) @@ -616,22 +613,22 @@ def test_pane_order(session): builder = WorkspaceBuilder(sconf=workspace) - window_count = len(session._windows) # current window count - assert len(session._windows) == window_count + window_count = len(session.windows) # current window count + assert len(session.windows) == window_count for w, wconf in builder.iter_create_windows(session): for p in builder.iter_create_panes(w, wconf): w.select_layout("tiled") # fix glitch with pane size - assert len(session._windows) == window_count + assert len(session.windows) == window_count assert isinstance(w, Window) - assert len(session._windows) == window_count + assert len(session.windows) == window_count window_count += 1 for w in session.windows: pane_base_index = w.show_window_option("pane-base-index", g=True) - for p_index, p in enumerate(w.list_panes(), start=pane_base_index): + for p_index, p in enumerate(w.panes, start=pane_base_index): assert int(p_index) == int(p.index) # pane-base-index start at base-index, pane_paths always start @@ -640,7 +637,7 @@ def test_pane_order(session): def f(): p.server._update_panes() - return p.current_path == pane_path + return p.pane_current_path == pane_path assert retry_until(f) @@ -659,8 +656,8 @@ def test_window_index(session): builder = WorkspaceBuilder(sconf=workspace) for window, _ in builder.iter_create_windows(session): - expected_index = name_index_map[window["window_name"]] - assert int(window["window_index"]) == expected_index + expected_index = name_index_map[window.window_name] + assert int(window.window_index) == expected_index def test_before_load_throw_error_if_retcode_error(server): @@ -866,7 +863,7 @@ def test_load_configs_same_session(server): builder.build() assert len(server.sessions) == 1 - assert len(server.sessions[0]._windows) == 3 + assert len(server.sessions[0].windows) == 3 workspace = ConfigReader._from_file( path=test_utils.get_workspace_file("workspace/builder/two_windows.yaml") @@ -875,7 +872,7 @@ def test_load_configs_same_session(server): builder = WorkspaceBuilder(sconf=workspace, server=server) builder.build() assert len(server.sessions) == 2 - assert len(server.sessions[1]._windows) == 2 + assert len(server.sessions[1].windows) == 2 workspace = ConfigReader._from_file( path=test_utils.get_workspace_file("workspace/builder/two_windows.yaml") @@ -885,7 +882,7 @@ def test_load_configs_same_session(server): builder.build(server.sessions[1], True) assert len(server.sessions) == 2 - assert len(server.sessions[1]._windows) == 4 + assert len(server.sessions[1].windows) == 4 def test_load_configs_separate_sessions(server): @@ -897,7 +894,7 @@ def test_load_configs_separate_sessions(server): builder.build() assert len(server.sessions) == 1 - assert len(server.sessions[0]._windows) == 3 + assert len(server.sessions[0].windows) == 3 workspace = ConfigReader._from_file( path=test_utils.get_workspace_file("workspace/builder/two_windows.yaml") @@ -907,8 +904,8 @@ def test_load_configs_separate_sessions(server): builder.build() assert len(server.sessions) == 2 - assert len(server.sessions[0]._windows) == 3 - assert len(server.sessions[1]._windows) == 2 + assert len(server.sessions[0].windows) == 3 + assert len(server.sessions[1].windows) == 2 def test_find_current_active_pane(server, monkeypatch): @@ -926,13 +923,11 @@ def test_find_current_active_pane(server, monkeypatch): builder = WorkspaceBuilder(sconf=workspace, server=server) builder.build() - assert len(server.list_sessions()) == 2 + assert len(server.sessions) == 2 # Assign an active pane to the session - second_session = server.list_sessions()[1] - first_pane_on_second_session_id = second_session.list_windows()[0].list_panes()[0][ - "pane_id" - ] + second_session = server.sessions[1] + first_pane_on_second_session_id = second_session.windows[0].panes[0].pane_id monkeypatch.setenv("TMUX_PANE", first_pane_on_second_session_id) builder = WorkspaceBuilder(sconf=workspace, server=server) @@ -1233,7 +1228,7 @@ def test_first_pane_start_directory(session, tmp_path: pathlib.Path): def f(): p.server._update_panes() - pane_path = p.current_path + pane_path = p.pane_current_path return path in pane_path or pane_path == path # handle case with OS X adding /private/ to /tmp/ paths @@ -1257,10 +1252,10 @@ def test_layout_main_horizontal(session): main_horizontal_pane, *panes = window.panes def height(p): - return int(p._info["pane_height"]) + return int(p.pane_height) def width(p): - return int(p._info["pane_width"]) + return int(p.pane_width) main_horizontal_pane_height = height(main_horizontal_pane) pane_heights = [height(pane) for pane in panes] @@ -1358,4 +1353,4 @@ def test_issue_800_default_size_many_windows( return builder.build() - assert len(server.list_sessions()) == 1 + assert len(server.sessions) == 1