|
| 1 | +"""Tests for example workspace YAML files.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import functools |
| 6 | +import typing as t |
| 7 | + |
| 8 | +from libtmux.pane import Pane |
| 9 | +from libtmux.session import Session |
| 10 | +from libtmux.test.retry import retry_until |
| 11 | + |
| 12 | +from tests.constants import EXAMPLE_PATH |
| 13 | +from tmuxp._internal.config_reader import ConfigReader |
| 14 | +from tmuxp.workspace import loader |
| 15 | +from tmuxp.workspace.builder import WorkspaceBuilder |
| 16 | + |
| 17 | + |
| 18 | +def test_synchronize_shorthand(session: Session) -> None: |
| 19 | + """Test synchronize-shorthand.yaml builds and sets synchronize-panes.""" |
| 20 | + config = ConfigReader._from_file(EXAMPLE_PATH / "synchronize-shorthand.yaml") |
| 21 | + config = loader.expand(config) |
| 22 | + builder = WorkspaceBuilder(session_config=config, server=session.server) |
| 23 | + builder.build(session=session) |
| 24 | + |
| 25 | + windows = session.windows |
| 26 | + assert len(windows) == 3 |
| 27 | + |
| 28 | + synced_before = windows[0] |
| 29 | + synced_after = windows[1] |
| 30 | + not_synced = windows[2] |
| 31 | + |
| 32 | + assert synced_before.show_option("synchronize-panes") is True |
| 33 | + assert synced_after.show_option("synchronize-panes") is True |
| 34 | + assert not_synced.show_option("synchronize-panes") is not True |
| 35 | + |
| 36 | + |
| 37 | +def test_lifecycle_hooks(session: Session) -> None: |
| 38 | + """Test lifecycle-hooks.yaml loads without error.""" |
| 39 | + config = ConfigReader._from_file(EXAMPLE_PATH / "lifecycle-hooks.yaml") |
| 40 | + config = loader.expand(config) |
| 41 | + builder = WorkspaceBuilder(session_config=config, server=session.server) |
| 42 | + builder.build(session=session) |
| 43 | + |
| 44 | + assert len(session.windows) >= 1 |
| 45 | + |
| 46 | + |
| 47 | +def test_config_templating(session: Session) -> None: |
| 48 | + """Test config-templating.yaml renders templates and builds.""" |
| 49 | + config = ConfigReader._from_file( |
| 50 | + EXAMPLE_PATH / "config-templating.yaml", |
| 51 | + template_context={"project": "myapp"}, |
| 52 | + ) |
| 53 | + config = loader.expand(config) |
| 54 | + |
| 55 | + assert config["session_name"] == "myapp" |
| 56 | + assert config["windows"][0]["window_name"] == "myapp-main" |
| 57 | + |
| 58 | + builder = WorkspaceBuilder(session_config=config, server=session.server) |
| 59 | + builder.build(session=session) |
| 60 | + |
| 61 | + assert len(session.windows) >= 1 |
| 62 | + |
| 63 | + |
| 64 | +def test_pane_titles(session: Session) -> None: |
| 65 | + """Test pane-titles.yaml builds with pane title options.""" |
| 66 | + config = ConfigReader._from_file(EXAMPLE_PATH / "pane-titles.yaml") |
| 67 | + config = loader.expand(config) |
| 68 | + builder = WorkspaceBuilder(session_config=config, server=session.server) |
| 69 | + builder.build(session=session) |
| 70 | + |
| 71 | + window = session.windows[0] |
| 72 | + assert window.show_option("pane-border-status") == "top" |
| 73 | + assert window.show_option("pane-border-format") == "#{pane_index}: #{pane_title}" |
| 74 | + |
| 75 | + panes = window.panes |
| 76 | + assert len(panes) == 3 |
| 77 | + |
| 78 | + def check_title(p: Pane, expected: str) -> bool: |
| 79 | + p.refresh() |
| 80 | + return p.pane_title == expected |
| 81 | + |
| 82 | + assert retry_until( |
| 83 | + functools.partial(check_title, panes[0], "editor"), |
| 84 | + ), f"Expected title 'editor', got '{panes[0].pane_title}'" |
| 85 | + assert retry_until( |
| 86 | + functools.partial(check_title, panes[1], "runner"), |
| 87 | + ), f"Expected title 'runner', got '{panes[1].pane_title}'" |
0 commit comments