Skip to content

Commit c90d326

Browse files
committed
chore(mypy): Typings for test_builder
1 parent 9893d18 commit c90d326

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

tests/workspace/test_builder.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def f_check_again():
149149
and CI. See https://github.com/tmux-python/tmuxp/issues/310.
150150
""".strip()
151151
)
152-
def test_suppress_history(session):
152+
def test_suppress_history(session: Session) -> None:
153153
workspace = ConfigReader._from_file(
154154
test_utils.get_workspace_file("workspace/builder/suppress_history.yaml")
155155
)
@@ -162,10 +162,10 @@ def test_suppress_history(session):
162162
inHistoryWindow = session.windows.get(window_name="inHistory")
163163
isMissingWindow = session.windows.get(window_name="isMissing")
164164

165-
def assertHistory(cmd, hist):
165+
def assertHistory(cmd: str, hist: str) -> bool:
166166
return "inHistory" in cmd and cmd.endswith(hist)
167167

168-
def assertIsMissing(cmd, hist):
168+
def assertIsMissing(cmd: str, hist: str) -> bool:
169169
return "isMissing" in cmd and not cmd.endswith(hist)
170170

171171
for w, window_name, assertCase in [
@@ -303,8 +303,8 @@ def test_window_options_after(session: Session) -> None:
303303
builder = WorkspaceBuilder(session_config=workspace, server=session.server)
304304
builder.build(session=session)
305305

306-
def assert_last_line(p, s):
307-
def f():
306+
def assert_last_line(p: Pane, s: str) -> bool:
307+
def f() -> bool:
308308
pane_out = p.cmd("capture-pane", "-p", "-J").stdout
309309
while not pane_out[-1].strip(): # delete trailing lines tmux 1.8
310310
pane_out.pop()
@@ -400,7 +400,9 @@ def test_environment_variables(session: Session) -> None:
400400
has_gte_version("3.0"),
401401
reason="warnings are not needed for tmux >= 3.0",
402402
)
403-
def test_environment_variables_logs(session: Session, caplog: pytest.LogCaptureFixture):
403+
def test_environment_variables_logs(
404+
session: Session, caplog: pytest.LogCaptureFixture
405+
) -> None:
404406
workspace = ConfigReader._from_file(
405407
test_utils.get_workspace_file("workspace/builder/environment_vars.yaml")
406408
)
@@ -468,7 +470,7 @@ def test_automatic_rename_option(
468470
assert w.name != "renamed_window"
469471

470472
def check_window_name_mismatch() -> bool:
471-
return w.name != portable_command
473+
return bool(w.name != portable_command)
472474

473475
assert retry_until(check_window_name_mismatch, 5, interval=0.25)
474476

@@ -670,7 +672,7 @@ def test_pane_order(session: Session) -> None:
670672
# at 0 since python list.
671673
pane_path = pane_paths[p_index - pane_base_index]
672674

673-
def f(pane_path: str, p: Pane):
675+
def f(pane_path: str, p: Pane) -> bool:
674676
p.refresh()
675677
return p.pane_current_path == pane_path
676678

@@ -713,6 +715,7 @@ def test_before_load_throw_error_if_retcode_error(server: Server) -> None:
713715

714716
with temp_session(server) as sess:
715717
session_name = sess.name
718+
assert session_name is not None
716719

717720
with pytest.raises(exc.BeforeLoadScriptError):
718721
builder.build(session=sess)
@@ -736,7 +739,9 @@ def test_before_load_throw_error_if_file_not_exists(server: Server) -> None:
736739

737740
with temp_session(server) as session:
738741
session_name = session.name
739-
temp_session_exists = server.has_session(session.name)
742+
743+
assert session_name is not None
744+
temp_session_exists = server.has_session(session_name)
740745
assert temp_session_exists
741746
with pytest.raises((exc.BeforeLoadScriptNotExists, OSError)) as excinfo:
742747
builder.build(session=session)
@@ -985,6 +990,8 @@ def test_find_current_active_pane(
985990
# Assign an active pane to the session
986991
second_session = server.sessions[1]
987992
first_pane_on_second_session_id = second_session.windows[0].panes[0].pane_id
993+
994+
assert first_pane_on_second_session_id is not None
988995
monkeypatch.setenv("TMUX_PANE", first_pane_on_second_session_id)
989996

990997
builder = WorkspaceBuilder(session_config=workspace, server=server)
@@ -1134,7 +1141,7 @@ def test_load_workspace_enter(
11341141
pane = session.attached_pane
11351142
assert isinstance(pane, Pane)
11361143

1137-
def fn():
1144+
def fn() -> bool:
11381145
captured_pane = "\n".join(pane.capture_pane())
11391146

11401147
if should_see:
@@ -1320,11 +1327,11 @@ def test_layout_main_horizontal(session: Session) -> None:
13201327
assert len(window.panes) == 3
13211328
main_horizontal_pane, *panes = window.panes
13221329

1323-
def height(p):
1324-
return int(p.pane_height)
1330+
def height(p: Pane) -> int:
1331+
return int(p.pane_height) if p.pane_height is not None else 0
13251332

1326-
def width(p):
1327-
return int(p.pane_width)
1333+
def width(p: Pane) -> int:
1334+
return int(p.pane_width) if p.pane_width is not None else 0
13281335

13291336
main_horizontal_pane_height = height(main_horizontal_pane)
13301337
pane_heights = [height(pane) for pane in panes]
@@ -1337,7 +1344,7 @@ def width(p):
13371344
), "The bottom row should be uniform height"
13381345
assert width(main_horizontal_pane) > width(panes[0])
13391346

1340-
def is_almost_equal(x, y):
1347+
def is_almost_equal(x: int, y: int) -> bool:
13411348
return abs(x - y) <= 1
13421349

13431350
assert is_almost_equal(height(panes[0]), height(panes[1]))

0 commit comments

Comments
 (0)