| 
9 | 9 | 
 
  | 
10 | 10 | import libtmux  | 
11 | 11 | from libtmux.common import has_gte_version, has_lt_version  | 
 | 12 | +from libtmux.session import Session  | 
12 | 13 | from libtmux.test import retry_until, temp_session  | 
13 | 14 | from libtmux.window import Window  | 
14 | 15 | from tmuxp import exc  | 
@@ -331,18 +332,95 @@ def f():  | 
331 | 332 |         assert w.name != "top"  | 
332 | 333 | 
 
  | 
333 | 334 | 
 
  | 
 | 335 | +@pytest.mark.skipif(  | 
 | 336 | +    has_lt_version("3.0"),  | 
 | 337 | +    reason="needs -e flag for new-window and split-window introduced in tmux 3.0",  | 
 | 338 | +)  | 
334 | 339 | def test_environment_variables(session):  | 
335 | 340 |     workspace = ConfigReader._from_file(  | 
336 | 341 |         test_utils.get_workspace_file("workspace/builder/environment_vars.yaml")  | 
337 | 342 |     )  | 
338 | 343 |     workspace = loader.expand(workspace)  | 
339 | 344 | 
 
  | 
 | 345 | +    builder = WorkspaceBuilder(sconf=workspace)  | 
 | 346 | +    builder.build(session)  | 
 | 347 | +    # Give slow shells some time to settle as otherwise tests might fail.  | 
 | 348 | +    time.sleep(0.3)  | 
 | 349 | + | 
 | 350 | +    assert session.getenv("FOO") == "SESSION"  | 
 | 351 | +    assert session.getenv("PATH") == "/tmp"  | 
 | 352 | + | 
 | 353 | +    no_overrides_win = session.windows[0]  | 
 | 354 | +    pane = no_overrides_win.panes[0]  | 
 | 355 | +    pane.send_keys("echo $FOO")  | 
 | 356 | +    assert pane.capture_pane()[1] == "SESSION"  | 
 | 357 | + | 
 | 358 | +    window_overrides_win = session.windows[1]  | 
 | 359 | +    pane = window_overrides_win.panes[0]  | 
 | 360 | +    pane.send_keys("echo $FOO")  | 
 | 361 | +    assert pane.capture_pane()[1] == "WINDOW"  | 
 | 362 | + | 
 | 363 | +    pane_overrides_win = session.windows[2]  | 
 | 364 | +    pane = pane_overrides_win.panes[0]  | 
 | 365 | +    pane.send_keys("echo $FOO")  | 
 | 366 | +    assert pane.capture_pane()[1] == "PANE"  | 
 | 367 | + | 
 | 368 | +    both_overrides_win = session.windows[3]  | 
 | 369 | +    pane = both_overrides_win.panes[0]  | 
 | 370 | +    pane.send_keys("echo $FOO")  | 
 | 371 | +    assert pane.capture_pane()[1] == "WINDOW"  | 
 | 372 | +    pane = both_overrides_win.panes[1]  | 
 | 373 | +    pane.send_keys("echo $FOO")  | 
 | 374 | +    assert pane.capture_pane()[1] == "PANE"  | 
 | 375 | + | 
 | 376 | + | 
 | 377 | +@pytest.mark.skipif(  | 
 | 378 | +    has_gte_version("3.0"),  | 
 | 379 | +    reason="warnings are not needed for tmux >= 3.0",  | 
 | 380 | +)  | 
 | 381 | +def test_environment_variables_logs(session: Session, caplog: pytest.LogCaptureFixture):  | 
 | 382 | +    workspace = ConfigReader._from_file(  | 
 | 383 | +        test_utils.get_workspace_file("workspace/builder/environment_vars.yaml")  | 
 | 384 | +    )  | 
 | 385 | +    workspace = loader.expand(workspace)  | 
 | 386 | + | 
340 | 387 |     builder = WorkspaceBuilder(sconf=workspace)  | 
341 | 388 |     builder.build(session)  | 
342 | 389 | 
 
  | 
343 |  | -    assert session.getenv("FOO") == "BAR"  | 
 | 390 | +    # environment on sessions should work as this is done using set-environment  | 
 | 391 | +    # on the session itself  | 
 | 392 | +    assert session.getenv("FOO") == "SESSION"  | 
344 | 393 |     assert session.getenv("PATH") == "/tmp"  | 
345 | 394 | 
 
  | 
 | 395 | +    assert (  | 
 | 396 | +        sum(  | 
 | 397 | +            1  | 
 | 398 | +            for record in caplog.records  | 
 | 399 | +            if "Cannot set environment for new windows." in record.msg  | 
 | 400 | +        )  | 
 | 401 | +        # From window_overrides and both_overrides, but not  | 
 | 402 | +        # both_overrides_in_first_pane.  | 
 | 403 | +        == 2  | 
 | 404 | +    ), "Warning on creating windows missing"  | 
 | 405 | +    assert (  | 
 | 406 | +        sum(  | 
 | 407 | +            1  | 
 | 408 | +            for record in caplog.records  | 
 | 409 | +            if "Cannot set environment for new panes." in record.msg  | 
 | 410 | +        )  | 
 | 411 | +        # From pane_overrides and both_overrides, but not both_overrides_in_first_pane.  | 
 | 412 | +        == 2  | 
 | 413 | +    ), "Warning on creating panes missing"  | 
 | 414 | +    assert (  | 
 | 415 | +        sum(  | 
 | 416 | +            1  | 
 | 417 | +            for record in caplog.records  | 
 | 418 | +            if 'Cannot set environment for new panes and windows.' in record.msg  | 
 | 419 | +        )  | 
 | 420 | +        # From both_overrides_in_first_pane.  | 
 | 421 | +        == 1  | 
 | 422 | +    )  | 
 | 423 | + | 
346 | 424 | 
 
  | 
347 | 425 | def test_automatic_rename_option(session):  | 
348 | 426 |     """With option automatic-rename: on."""  | 
 | 
0 commit comments