|
9 | 9 | from libtmux import exc
|
10 | 10 | from libtmux._internal.query_list import ObjectDoesNotExist
|
11 | 11 | from libtmux.common import has_gte_version, has_lt_version
|
| 12 | +from libtmux.constants import ResizeAdjustmentDirection |
12 | 13 | from libtmux.pane import Pane
|
13 | 14 | from libtmux.server import Server
|
14 | 15 | from libtmux.session import Session
|
@@ -397,3 +398,86 @@ def test_split_window_with_environment_logs_warning_for_old_tmux(
|
397 | 398 | assert any(
|
398 | 399 | "Cannot set up environment" in record.msg for record in caplog.records
|
399 | 400 | ), "Warning missing"
|
| 401 | + |
| 402 | + |
| 403 | +@pytest.mark.skipif( |
| 404 | + has_lt_version("2.9"), |
| 405 | + reason="resize-window only exists in tmux 2.9+", |
| 406 | +) |
| 407 | +def test_resize( |
| 408 | + session: Session, |
| 409 | +) -> None: |
| 410 | + """Verify resizing window.""" |
| 411 | + session.cmd("detach-client", "-s") |
| 412 | + |
| 413 | + window = session.attached_window |
| 414 | + window_height_adjustment = 10 |
| 415 | + window_width_adjustment = 10 |
| 416 | + |
| 417 | + assert window.window_height is not None |
| 418 | + assert window.window_width is not None |
| 419 | + |
| 420 | + # |
| 421 | + # Manual resizing |
| 422 | + # |
| 423 | + |
| 424 | + # Manual: Height |
| 425 | + window_height_before = int(window.window_height) |
| 426 | + window.resize( |
| 427 | + height=10, |
| 428 | + adjustment=window_height_adjustment, |
| 429 | + ) |
| 430 | + assert int(window.window_height) == 10 |
| 431 | + |
| 432 | + # Manual: Width |
| 433 | + window.resize( |
| 434 | + width=10, |
| 435 | + adjustment=window_width_adjustment, |
| 436 | + ) |
| 437 | + assert int(window.window_width) == 10 |
| 438 | + |
| 439 | + # |
| 440 | + # Adjustments |
| 441 | + # |
| 442 | + |
| 443 | + # Adjustment: Down |
| 444 | + window_height_before = int(window.window_height) |
| 445 | + window.resize( |
| 446 | + adjustment_direction=ResizeAdjustmentDirection.Down, |
| 447 | + adjustment=window_height_adjustment * 2, |
| 448 | + ) |
| 449 | + assert window_height_before + (window_height_adjustment * 2) == int( |
| 450 | + window.window_height |
| 451 | + ) |
| 452 | + |
| 453 | + # Adjustment: Up |
| 454 | + window_height_before = int(window.window_height) |
| 455 | + window.resize( |
| 456 | + adjustment_direction=ResizeAdjustmentDirection.Up, |
| 457 | + adjustment=window_height_adjustment, |
| 458 | + ) |
| 459 | + assert window_height_before - window_height_adjustment == int(window.window_height) |
| 460 | + |
| 461 | + # |
| 462 | + # Shrink and expand |
| 463 | + # |
| 464 | + window.resize(height=50) |
| 465 | + |
| 466 | + # Shrink |
| 467 | + window_height_before = int(window.window_height) |
| 468 | + window.resize( |
| 469 | + shrink=True, |
| 470 | + ) |
| 471 | + window_height_shrunk = int(window.window_height) |
| 472 | + assert window_height_before > window_height_shrunk |
| 473 | + |
| 474 | + assert window |
| 475 | + |
| 476 | + # Expand |
| 477 | + window.resize(height=2) |
| 478 | + window_height_before = int(window.window_height) |
| 479 | + window.resize( |
| 480 | + expand=True, |
| 481 | + ) |
| 482 | + window_height_expanded = int(window.window_height) |
| 483 | + assert window_height_before < window_height_expanded |
0 commit comments