|
1 | | -"""Tests for libtmux Pane object.""" |
| 1 | +"""Tests for deprecated libtmux Pane APIs. |
| 2 | +
|
| 3 | +These tests verify that deprecated methods raise DeprecatedError. |
| 4 | +""" |
2 | 5 |
|
3 | 6 | from __future__ import annotations |
4 | 7 |
|
5 | | -import logging |
6 | | -import shutil |
7 | 8 | import typing as t |
8 | 9 |
|
9 | | -if t.TYPE_CHECKING: |
10 | | - from libtmux.session import Session |
11 | | - |
12 | | -logger = logging.getLogger(__name__) |
13 | | - |
14 | | - |
15 | | -def test_resize_pane(session: Session) -> None: |
16 | | - """Test Pane.resize_pane().""" |
17 | | - window = session.attached_window |
18 | | - window.rename_window("test_resize_pane") |
19 | | - |
20 | | - pane1 = window.attached_pane |
21 | | - assert pane1 is not None |
22 | | - pane1_height = pane1["pane_height"] |
23 | | - window.split_window() |
| 10 | +import pytest |
24 | 11 |
|
25 | | - pane1.resize_pane(height=4) |
26 | | - assert pane1["pane_height"] != pane1_height |
27 | | - assert int(pane1["pane_height"]) == 4 |
| 12 | +from libtmux import exc |
28 | 13 |
|
29 | | - pane1.resize_pane(height=3) |
30 | | - assert int(pane1["pane_height"]) == 3 |
| 14 | +if t.TYPE_CHECKING: |
| 15 | + from libtmux.session import Session |
31 | 16 |
|
32 | 17 |
|
33 | | -def test_send_keys(session: Session) -> None: |
34 | | - """Verify Pane.send_keys().""" |
35 | | - pane = session.attached_window.attached_pane |
| 18 | +def test_resize_pane_raises_deprecated_error(session: Session) -> None: |
| 19 | + """Test Pane.resize_pane() raises DeprecatedError.""" |
| 20 | + window = session.active_window |
| 21 | + pane = window.active_pane |
36 | 22 | assert pane is not None |
37 | | - pane.send_keys("c-c", literal=True) |
38 | 23 |
|
39 | | - pane_contents = "\n".join(pane.cmd("capture-pane", "-p").stdout) |
40 | | - assert "c-c" in pane_contents |
| 24 | + with pytest.raises( |
| 25 | + exc.DeprecatedError, match=r"Pane\.resize_pane\(\) was deprecated" |
| 26 | + ): |
| 27 | + pane.resize_pane(height=4) |
41 | 28 |
|
42 | | - pane.send_keys("c-a", literal=False) |
43 | | - assert "c-a" not in pane_contents, "should not print to pane" |
44 | 29 |
|
| 30 | +def test_select_pane_raises_deprecated_error(session: Session) -> None: |
| 31 | + """Test Pane.select_pane() raises DeprecatedError.""" |
| 32 | + window = session.active_window |
| 33 | + pane = window.active_pane |
| 34 | + assert pane is not None |
45 | 35 |
|
46 | | -def test_set_height(session: Session) -> None: |
47 | | - """Verify Pane.set_height().""" |
48 | | - window = session.new_window(window_name="test_set_height") |
49 | | - window.split_window() |
50 | | - pane1 = window.attached_pane |
51 | | - assert pane1 is not None |
52 | | - pane1_height = pane1["pane_height"] |
53 | | - |
54 | | - pane1.set_height(4) |
55 | | - assert pane1["pane_height"] != pane1_height |
56 | | - assert int(pane1["pane_height"]) == 4 |
| 36 | + with pytest.raises( |
| 37 | + exc.DeprecatedError, match=r"Pane\.select_pane\(\) was deprecated" |
| 38 | + ): |
| 39 | + pane.select_pane() |
57 | 40 |
|
58 | 41 |
|
59 | | -def test_set_width(session: Session) -> None: |
60 | | - """Verify Pane.set_width().""" |
61 | | - window = session.new_window(window_name="test_set_width") |
62 | | - window.split_window() |
| 42 | +def test_split_window_raises_deprecated_error(session: Session) -> None: |
| 43 | + """Test Pane.split_window() raises DeprecatedError.""" |
| 44 | + window = session.active_window |
| 45 | + pane = window.active_pane |
| 46 | + assert pane is not None |
63 | 47 |
|
64 | | - window.select_layout("main-vertical") |
65 | | - pane1 = window.attached_pane |
66 | | - assert pane1 is not None |
67 | | - pane1_width = pane1["pane_width"] |
| 48 | + with pytest.raises( |
| 49 | + exc.DeprecatedError, match=r"Pane\.split_window\(\) was deprecated" |
| 50 | + ): |
| 51 | + pane.split_window() |
68 | 52 |
|
69 | | - pane1.set_width(10) |
70 | | - assert pane1["pane_width"] != pane1_width |
71 | | - assert int(pane1["pane_width"]) == 10 |
72 | 53 |
|
73 | | - pane1.reset() |
| 54 | +def test_pane_get_raises_deprecated_error(session: Session) -> None: |
| 55 | + """Test Pane.get() raises DeprecatedError.""" |
| 56 | + window = session.active_window |
| 57 | + pane = window.active_pane |
| 58 | + assert pane is not None |
74 | 59 |
|
| 60 | + with pytest.raises(exc.DeprecatedError, match=r"Pane\.get\(\) was deprecated"): |
| 61 | + pane.get("pane_id") |
75 | 62 |
|
76 | | -def test_capture_pane(session: Session) -> None: |
77 | | - """Verify Pane.capture_pane().""" |
78 | | - env = shutil.which("env") |
79 | | - assert env is not None, "Cannot find usable `env` in PATH." |
80 | 63 |
|
81 | | - session.new_window( |
82 | | - attach=True, |
83 | | - window_name="capture_pane", |
84 | | - window_shell=f"{env} PS1='$ ' sh", |
85 | | - ) |
86 | | - pane = session.attached_window.attached_pane |
| 64 | +def test_pane_getitem_raises_deprecated_error(session: Session) -> None: |
| 65 | + """Test Pane.__getitem__() raises DeprecatedError.""" |
| 66 | + window = session.active_window |
| 67 | + pane = window.active_pane |
87 | 68 | assert pane is not None |
88 | | - pane_contents = "\n".join(pane.capture_pane()) |
89 | | - assert pane_contents == "$" |
90 | | - pane.send_keys( |
91 | | - r'printf "\n%s\n" "Hello World !"', |
92 | | - literal=True, |
93 | | - suppress_history=False, |
94 | | - ) |
95 | | - pane_contents = "\n".join(pane.capture_pane()) |
96 | | - assert pane_contents == r'$ printf "\n%s\n" "Hello World !"{}'.format( |
97 | | - "\n\nHello World !\n$", |
98 | | - ) |
| 69 | + |
| 70 | + with pytest.raises(exc.DeprecatedError, match=r"Pane\[key\] lookup was deprecated"): |
| 71 | + _ = pane["pane_id"] |
0 commit comments