|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
5 | 5 | import logging
|
| 6 | +import os |
6 | 7 | import subprocess
|
| 8 | +import time |
7 | 9 | import typing as t
|
8 | 10 |
|
9 | 11 | import pytest
|
10 | 12 |
|
11 |
| -from libtmux._internal.waiter import expect |
12 |
| -from libtmux.common import ( |
13 |
| - has_gte_version, |
14 |
| - has_version, |
15 |
| -) |
| 13 | +from libtmux.common import has_gte_version, has_version |
16 | 14 | from libtmux.server import Server
|
17 |
| -from libtmux.session import Session |
18 | 15 |
|
19 | 16 | if t.TYPE_CHECKING:
|
20 |
| - pass |
| 17 | + from libtmux.session import Session |
21 | 18 |
|
22 | 19 | logger = logging.getLogger(__name__)
|
23 | 20 |
|
@@ -142,27 +139,28 @@ def test_new_session_shell(server: Server) -> None:
|
142 | 139 |
|
143 | 140 |
|
144 | 141 | def test_new_session_shell_env(server: Server) -> None:
|
145 |
| - """Test new_session() with environment variables.""" |
146 |
| - env = {"FOO": "BAR", "other": "value"} |
147 |
| - |
148 |
| - cmd = "sh -c 'echo $FOO'" |
149 |
| - |
| 142 | + """Verify ``Server.new_session`` creates valid session running w/ command (#553).""" |
| 143 | + cmd = "sleep 1m" |
| 144 | + env = dict(os.environ) |
150 | 145 | mysession = server.new_session(
|
151 | 146 | "test_new_session_env",
|
152 | 147 | window_command=cmd,
|
153 | 148 | environment=env,
|
154 | 149 | )
|
155 |
| - |
156 |
| - # Use waiter to wait for the command to complete |
| 150 | + time.sleep(0.1) |
157 | 151 | window = mysession.windows[0]
|
158 | 152 | pane = window.panes[0]
|
159 |
| - |
160 |
| - # Wait for the output from the command |
161 |
| - expect(pane).wait_for_text("BAR") |
162 |
| - |
163 | 153 | assert mysession.session_name == "test_new_session_env"
|
164 | 154 | assert server.has_session("test_new_session_env")
|
165 | 155 |
|
| 156 | + pane_start_command = pane.pane_start_command |
| 157 | + assert pane_start_command is not None |
| 158 | + |
| 159 | + if has_gte_version("3.2"): |
| 160 | + assert pane_start_command.replace('"', "") == cmd |
| 161 | + else: |
| 162 | + assert pane_start_command == cmd |
| 163 | + |
166 | 164 |
|
167 | 165 | @pytest.mark.skipif(has_version("3.2"), reason="Wrong width returned with 3.2")
|
168 | 166 | def test_new_session_width_height(server: Server) -> None:
|
|
0 commit comments