Skip to content

Commit ea07928

Browse files
committed
tests(refactor): Use namespace imports for exception classes
why: Follow project import conventions from CLAUDE.md which require namespace imports instead of direct class imports. what: - Change from `from libtmux.exc import X` to `from libtmux import exc` - Update all usages to use `exc.X` pattern (e.g., exc.DeprecatedError) - Reformat long lines to comply with 88 character limit
1 parent babc0e8 commit ea07928

File tree

9 files changed

+175
-139
lines changed

9 files changed

+175
-139
lines changed

tests/legacy_api/test_common.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import pytest
1414

1515
import libtmux
16+
from libtmux import exc
1617
from libtmux._compat import LooseVersion
1718
from libtmux.common import (
1819
TMUX_MAX_VERSION,
@@ -28,7 +29,6 @@
2829
session_check_name,
2930
tmux_cmd,
3031
)
31-
from libtmux.exc import BadSessionName, LibTmuxException, TmuxCommandNotFound
3232

3333
if t.TYPE_CHECKING:
3434
from libtmux.session import Session
@@ -104,7 +104,7 @@ def mock_tmux_cmd(*args: t.Any, **kwargs: t.Any) -> Hi:
104104
return Hi()
105105

106106
monkeypatch.setattr(libtmux.common, "tmux_cmd", mock_tmux_cmd)
107-
with pytest.raises(LibTmuxException) as exc_info:
107+
with pytest.raises(exc.LibTmuxException) as exc_info:
108108
get_version()
109109
exc_info.match("does not meet the minimum tmux version requirement")
110110

@@ -139,11 +139,11 @@ def mock_get_version() -> LooseVersion:
139139
return LooseVersion("1.7")
140140

141141
monkeypatch.setattr(libtmux.common, "get_version", mock_get_version)
142-
with pytest.raises(LibTmuxException) as excinfo:
142+
with pytest.raises(exc.LibTmuxException) as excinfo:
143143
has_minimum_version()
144144
excinfo.match(r"libtmux only supports")
145145

146-
with pytest.raises(LibTmuxException) as excinfo:
146+
with pytest.raises(exc.LibTmuxException) as excinfo:
147147
has_minimum_version()
148148

149149
excinfo.match(r"libtmux only supports")
@@ -195,7 +195,7 @@ def test_has_lte_version() -> None:
195195
def test_tmux_cmd_raises_on_not_found(monkeypatch: pytest.MonkeyPatch) -> None:
196196
"""Verify raises if tmux command not found."""
197197
monkeypatch.setenv("PATH", "")
198-
with pytest.raises(TmuxCommandNotFound):
198+
with pytest.raises(exc.TmuxCommandNotFound):
199199
tmux_cmd("-V")
200200

201201

@@ -230,7 +230,7 @@ def test_session_check_name(
230230
) -> None:
231231
"""Verify session_check_name()."""
232232
if raises:
233-
with pytest.raises(BadSessionName) as exc_info:
233+
with pytest.raises(exc.BadSessionName) as exc_info:
234234
session_check_name(session_name)
235235
if exc_msg_regex is not None:
236236
assert exc_info.match(exc_msg_regex)

tests/legacy_api/test_pane.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pytest
1111

12-
from libtmux.exc import DeprecatedError
12+
from libtmux import exc
1313

1414
if t.TYPE_CHECKING:
1515
from libtmux.session import Session
@@ -21,7 +21,9 @@ def test_resize_pane_raises_deprecated_error(session: Session) -> None:
2121
pane = window.active_pane
2222
assert pane is not None
2323

24-
with pytest.raises(DeprecatedError, match=r"Pane\.resize_pane\(\) was deprecated"):
24+
with pytest.raises(
25+
exc.DeprecatedError, match=r"Pane\.resize_pane\(\) was deprecated"
26+
):
2527
pane.resize_pane(height=4)
2628

2729

@@ -31,7 +33,9 @@ def test_select_pane_raises_deprecated_error(session: Session) -> None:
3133
pane = window.active_pane
3234
assert pane is not None
3335

34-
with pytest.raises(DeprecatedError, match=r"Pane\.select_pane\(\) was deprecated"):
36+
with pytest.raises(
37+
exc.DeprecatedError, match=r"Pane\.select_pane\(\) was deprecated"
38+
):
3539
pane.select_pane()
3640

3741

@@ -41,7 +45,9 @@ def test_split_window_raises_deprecated_error(session: Session) -> None:
4145
pane = window.active_pane
4246
assert pane is not None
4347

44-
with pytest.raises(DeprecatedError, match=r"Pane\.split_window\(\) was deprecated"):
48+
with pytest.raises(
49+
exc.DeprecatedError, match=r"Pane\.split_window\(\) was deprecated"
50+
):
4551
pane.split_window()
4652

4753

@@ -51,7 +57,7 @@ def test_pane_get_raises_deprecated_error(session: Session) -> None:
5157
pane = window.active_pane
5258
assert pane is not None
5359

54-
with pytest.raises(DeprecatedError, match=r"Pane\.get\(\) was deprecated"):
60+
with pytest.raises(exc.DeprecatedError, match=r"Pane\.get\(\) was deprecated"):
5561
pane.get("pane_id")
5662

5763

@@ -61,5 +67,5 @@ def test_pane_getitem_raises_deprecated_error(session: Session) -> None:
6167
pane = window.active_pane
6268
assert pane is not None
6369

64-
with pytest.raises(DeprecatedError, match=r"Pane\[key\] lookup was deprecated"):
70+
with pytest.raises(exc.DeprecatedError, match=r"Pane\[key\] lookup was deprecated"):
6571
_ = pane["pane_id"]

tests/legacy_api/test_server.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,101 @@
11
"""Tests for deprecated libtmux Server APIs.
22
3-
These tests verify that deprecated methods raise DeprecatedError.
3+
These tests verify that deprecated methods raise exc.DeprecatedError.
44
"""
55

66
from __future__ import annotations
77

88
import pytest
99

10-
from libtmux.exc import DeprecatedError
10+
from libtmux import exc
1111
from libtmux.server import Server
1212

1313

1414
def test_kill_server_raises_deprecated_error(server: Server) -> None:
15-
"""Test Server.kill_server() raises DeprecatedError."""
15+
"""Test Server.kill_server() raises exc.DeprecatedError."""
1616
with pytest.raises(
17-
DeprecatedError, match=r"Server\.kill_server\(\) was deprecated"
17+
exc.DeprecatedError, match=r"Server\.kill_server\(\) was deprecated"
1818
):
1919
server.kill_server()
2020

2121

2222
def test_server_get_by_id_raises_deprecated_error(server: Server) -> None:
23-
"""Test Server.get_by_id() raises DeprecatedError."""
24-
with pytest.raises(DeprecatedError, match=r"Server\.get_by_id\(\) was deprecated"):
23+
"""Test Server.get_by_id() raises exc.DeprecatedError."""
24+
with pytest.raises(
25+
exc.DeprecatedError, match=r"Server\.get_by_id\(\) was deprecated"
26+
):
2527
server.get_by_id("$0")
2628

2729

2830
def test_server_where_raises_deprecated_error(server: Server) -> None:
29-
"""Test Server.where() raises DeprecatedError."""
30-
with pytest.raises(DeprecatedError, match=r"Server\.where\(\) was deprecated"):
31+
"""Test Server.where() raises exc.DeprecatedError."""
32+
with pytest.raises(exc.DeprecatedError, match=r"Server\.where\(\) was deprecated"):
3133
server.where({"session_name": "test"})
3234

3335

3436
def test_server_find_where_raises_deprecated_error(server: Server) -> None:
35-
"""Test Server.find_where() raises DeprecatedError."""
36-
with pytest.raises(DeprecatedError, match=r"Server\.find_where\(\) was deprecated"):
37+
"""Test Server.find_where() raises exc.DeprecatedError."""
38+
with pytest.raises(
39+
exc.DeprecatedError, match=r"Server\.find_where\(\) was deprecated"
40+
):
3741
server.find_where({"session_name": "test"})
3842

3943

4044
def test_server_list_sessions_raises_deprecated_error(server: Server) -> None:
41-
"""Test Server.list_sessions() raises DeprecatedError."""
45+
"""Test Server.list_sessions() raises exc.DeprecatedError."""
4246
with pytest.raises(
43-
DeprecatedError, match=r"Server\.list_sessions\(\) was deprecated"
47+
exc.DeprecatedError, match=r"Server\.list_sessions\(\) was deprecated"
4448
):
4549
server.list_sessions()
4650

4751

4852
def test_server_children_raises_deprecated_error(server: Server) -> None:
49-
"""Test Server.children raises DeprecatedError."""
50-
with pytest.raises(DeprecatedError, match=r"Server\.children was deprecated"):
53+
"""Test Server.children raises exc.DeprecatedError."""
54+
with pytest.raises(exc.DeprecatedError, match=r"Server\.children was deprecated"):
5155
_ = server.children
5256

5357

5458
def test_server__sessions_raises_deprecated_error(server: Server) -> None:
55-
"""Test Server._sessions raises DeprecatedError."""
56-
with pytest.raises(DeprecatedError, match=r"Server\._sessions was deprecated"):
59+
"""Test Server._sessions raises exc.DeprecatedError."""
60+
with pytest.raises(exc.DeprecatedError, match=r"Server\._sessions was deprecated"):
5761
_ = server._sessions
5862

5963

6064
def test_server__list_sessions_raises_deprecated_error(server: Server) -> None:
61-
"""Test Server._list_sessions() raises DeprecatedError."""
65+
"""Test Server._list_sessions() raises exc.DeprecatedError."""
6266
with pytest.raises(
63-
DeprecatedError, match=r"Server\._list_sessions\(\) was deprecated"
67+
exc.DeprecatedError, match=r"Server\._list_sessions\(\) was deprecated"
6468
):
6569
server._list_sessions()
6670

6771

6872
def test_server__list_windows_raises_deprecated_error(server: Server) -> None:
69-
"""Test Server._list_windows() raises DeprecatedError."""
73+
"""Test Server._list_windows() raises exc.DeprecatedError."""
7074
with pytest.raises(
71-
DeprecatedError, match=r"Server\._list_windows\(\) was deprecated"
75+
exc.DeprecatedError, match=r"Server\._list_windows\(\) was deprecated"
7276
):
7377
server._list_windows()
7478

7579

7680
def test_server__update_windows_raises_deprecated_error(server: Server) -> None:
77-
"""Test Server._update_windows() raises DeprecatedError."""
81+
"""Test Server._update_windows() raises exc.DeprecatedError."""
7882
with pytest.raises(
79-
DeprecatedError, match=r"Server\._update_windows\(\) was deprecated"
83+
exc.DeprecatedError, match=r"Server\._update_windows\(\) was deprecated"
8084
):
8185
server._update_windows()
8286

8387

8488
def test_server__list_panes_raises_deprecated_error(server: Server) -> None:
85-
"""Test Server._list_panes() raises DeprecatedError."""
89+
"""Test Server._list_panes() raises exc.DeprecatedError."""
8690
with pytest.raises(
87-
DeprecatedError, match=r"Server\._list_panes\(\) was deprecated"
91+
exc.DeprecatedError, match=r"Server\._list_panes\(\) was deprecated"
8892
):
8993
server._list_panes()
9094

9195

9296
def test_server__update_panes_raises_deprecated_error(server: Server) -> None:
93-
"""Test Server._update_panes() raises DeprecatedError."""
97+
"""Test Server._update_panes() raises exc.DeprecatedError."""
9498
with pytest.raises(
95-
DeprecatedError, match=r"Server\._update_panes\(\) was deprecated"
99+
exc.DeprecatedError, match=r"Server\._update_panes\(\) was deprecated"
96100
):
97101
server._update_panes()

tests/legacy_api/test_session.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Tests for deprecated libtmux Session APIs.
22
3-
These tests verify that deprecated methods raise DeprecatedError.
3+
These tests verify that deprecated methods raise exc.DeprecatedError.
44
"""
55

66
from __future__ import annotations
@@ -9,42 +9,44 @@
99

1010
import pytest
1111

12-
from libtmux.exc import DeprecatedError
12+
from libtmux import exc
1313

1414
if t.TYPE_CHECKING:
1515
from libtmux.server import Server
1616
from libtmux.session import Session
1717

1818

1919
def test_attached_window_raises_deprecated_error(session: Session) -> None:
20-
"""Test Session.attached_window raises DeprecatedError."""
20+
"""Test Session.attached_window raises exc.DeprecatedError."""
2121
with pytest.raises(
22-
DeprecatedError, match=r"Session\.attached_window was deprecated"
22+
exc.DeprecatedError, match=r"Session\.attached_window was deprecated"
2323
):
2424
_ = session.attached_window
2525

2626

2727
def test_attached_pane_raises_deprecated_error(session: Session) -> None:
28-
"""Test Session.attached_pane raises DeprecatedError."""
29-
with pytest.raises(DeprecatedError, match=r"Session\.attached_pane was deprecated"):
28+
"""Test Session.attached_pane raises exc.DeprecatedError."""
29+
with pytest.raises(
30+
exc.DeprecatedError, match=r"Session\.attached_pane was deprecated"
31+
):
3032
_ = session.attached_pane
3133

3234

3335
def test_attach_session_raises_deprecated_error(session: Session) -> None:
34-
"""Test Session.attach_session() raises DeprecatedError."""
36+
"""Test Session.attach_session() raises exc.DeprecatedError."""
3537
with pytest.raises(
36-
DeprecatedError, match=r"Session\.attach_session\(\) was deprecated"
38+
exc.DeprecatedError, match=r"Session\.attach_session\(\) was deprecated"
3739
):
3840
session.attach_session()
3941

4042

4143
def test_kill_session_raises_deprecated_error(server: Server) -> None:
42-
"""Test Session.kill_session() raises DeprecatedError."""
44+
"""Test Session.kill_session() raises exc.DeprecatedError."""
4345
# Create a new session to kill (so we don't kill our test session)
4446
new_session = server.new_session(session_name="test_kill_session", detach=True)
4547

4648
with pytest.raises(
47-
DeprecatedError, match=r"Session\.kill_session\(\) was deprecated"
49+
exc.DeprecatedError, match=r"Session\.kill_session\(\) was deprecated"
4850
):
4951
new_session.kill_session()
5052

@@ -53,60 +55,64 @@ def test_kill_session_raises_deprecated_error(server: Server) -> None:
5355

5456

5557
def test_session_get_raises_deprecated_error(session: Session) -> None:
56-
"""Test Session.get() raises DeprecatedError."""
57-
with pytest.raises(DeprecatedError, match=r"Session\.get\(\) was deprecated"):
58+
"""Test Session.get() raises exc.DeprecatedError."""
59+
with pytest.raises(exc.DeprecatedError, match=r"Session\.get\(\) was deprecated"):
5860
session.get("session_name")
5961

6062

6163
def test_session_getitem_raises_deprecated_error(session: Session) -> None:
62-
"""Test Session.__getitem__() raises DeprecatedError."""
63-
with pytest.raises(DeprecatedError, match=r"Session\[key\] lookup was deprecated"):
64+
"""Test Session.__getitem__() raises exc.DeprecatedError."""
65+
with pytest.raises(
66+
exc.DeprecatedError, match=r"Session\[key\] lookup was deprecated"
67+
):
6468
_ = session["session_name"]
6569

6670

6771
def test_session_get_by_id_raises_deprecated_error(session: Session) -> None:
68-
"""Test Session.get_by_id() raises DeprecatedError."""
69-
with pytest.raises(DeprecatedError, match=r"Session\.get_by_id\(\) was deprecated"):
72+
"""Test Session.get_by_id() raises exc.DeprecatedError."""
73+
with pytest.raises(
74+
exc.DeprecatedError, match=r"Session\.get_by_id\(\) was deprecated"
75+
):
7076
session.get_by_id("@0")
7177

7278

7379
def test_session_where_raises_deprecated_error(session: Session) -> None:
74-
"""Test Session.where() raises DeprecatedError."""
75-
with pytest.raises(DeprecatedError, match=r"Session\.where\(\) was deprecated"):
80+
"""Test Session.where() raises exc.DeprecatedError."""
81+
with pytest.raises(exc.DeprecatedError, match=r"Session\.where\(\) was deprecated"):
7682
session.where({"window_name": "test"})
7783

7884

7985
def test_session_find_where_raises_deprecated_error(session: Session) -> None:
80-
"""Test Session.find_where() raises DeprecatedError."""
86+
"""Test Session.find_where() raises exc.DeprecatedError."""
8187
with pytest.raises(
82-
DeprecatedError, match=r"Session\.find_where\(\) was deprecated"
88+
exc.DeprecatedError, match=r"Session\.find_where\(\) was deprecated"
8389
):
8490
session.find_where({"window_name": "test"})
8591

8692

8793
def test_session_list_windows_raises_deprecated_error(session: Session) -> None:
88-
"""Test Session.list_windows() raises DeprecatedError."""
94+
"""Test Session.list_windows() raises exc.DeprecatedError."""
8995
with pytest.raises(
90-
DeprecatedError, match=r"Session\.list_windows\(\) was deprecated"
96+
exc.DeprecatedError, match=r"Session\.list_windows\(\) was deprecated"
9197
):
9298
session.list_windows()
9399

94100

95101
def test_session_children_raises_deprecated_error(session: Session) -> None:
96-
"""Test Session.children raises DeprecatedError."""
97-
with pytest.raises(DeprecatedError, match=r"Session\.children was deprecated"):
102+
"""Test Session.children raises exc.DeprecatedError."""
103+
with pytest.raises(exc.DeprecatedError, match=r"Session\.children was deprecated"):
98104
_ = session.children
99105

100106

101107
def test_session__windows_raises_deprecated_error(session: Session) -> None:
102-
"""Test Session._windows raises DeprecatedError."""
103-
with pytest.raises(DeprecatedError, match=r"Session\._windows was deprecated"):
108+
"""Test Session._windows raises exc.DeprecatedError."""
109+
with pytest.raises(exc.DeprecatedError, match=r"Session\._windows was deprecated"):
104110
_ = session._windows
105111

106112

107113
def test_session__list_windows_raises_deprecated_error(session: Session) -> None:
108-
"""Test Session._list_windows() raises DeprecatedError."""
114+
"""Test Session._list_windows() raises exc.DeprecatedError."""
109115
with pytest.raises(
110-
DeprecatedError, match=r"Session\._list_windows\(\) was deprecated"
116+
exc.DeprecatedError, match=r"Session\._list_windows\(\) was deprecated"
111117
):
112118
session._list_windows()

0 commit comments

Comments
 (0)