|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import os |
5 | 6 | import re |
6 | 7 | import shlex |
7 | 8 | import shutil |
8 | 9 | import subprocess |
| 10 | +import sys |
9 | 11 | from pathlib import Path |
10 | 12 |
|
11 | 13 | import pytest |
|
15 | 17 | from tests.conftest import requires_bash |
16 | 18 | from tests.parity_helpers import ( |
17 | 19 | HAS_POWERSHELL, |
| 20 | + _bash_posix_path, |
18 | 21 | bash_cmd, |
19 | 22 | break_wrap_layer, |
20 | 23 | clean_env, |
|
23 | 26 | install_scripts, |
24 | 27 | json_stdout, |
25 | 28 | make_repo, |
| 29 | + make_yaml_less_venv, |
26 | 30 | normalize_repo_paths, |
27 | 31 | normalize_script_names, |
28 | 32 | ps_cmd, |
@@ -242,6 +246,56 @@ def test_bash_requires_python_only_for_unicode_names( |
242 | 246 | assert "Error: Python 3 is required to create a Unicode feature name" in unicode_result.stderr |
243 | 247 |
|
244 | 248 |
|
| 249 | +@requires_bash |
| 250 | +def test_bash_unicode_uses_configured_python_without_pyyaml_in_spaced_path( |
| 251 | + repo: Path, tmp_path: Path |
| 252 | +) -> None: |
| 253 | + no_yaml_exe = make_yaml_less_venv(tmp_path / "tool env") |
| 254 | + shim_dir = tmp_path / "bin" |
| 255 | + shim_dir.mkdir() |
| 256 | + for name in ("python3", "python", "py"): |
| 257 | + shim = shim_dir / name |
| 258 | + shim.write_text("#!/bin/sh\nexit 1\n", encoding="utf-8", newline="\n") |
| 259 | + shim.chmod(0o755) |
| 260 | + env = clean_env() |
| 261 | + env["SPECKIT_PYTHON_EXECUTABLE"] = _bash_posix_path(no_yaml_exe) |
| 262 | + env["PATH"] = f"{shim_dir}{os.pathsep}{env['PATH']}" |
| 263 | + |
| 264 | + result = run(bash_cmd(repo, SCRIPT, "--json", "--dry-run", "添加用户"), repo, env) |
| 265 | + |
| 266 | + assert result.returncode == 0, result.stderr |
| 267 | + assert json_stdout(result)["BRANCH_NAME"] == "001-添加用户" |
| 268 | + |
| 269 | + |
| 270 | +@requires_bash |
| 271 | +def test_bash_unicode_uses_py_launcher_with_separate_version_arg( |
| 272 | + repo: Path, tmp_path: Path |
| 273 | +) -> None: |
| 274 | + shim_dir = tmp_path / "bin" |
| 275 | + shim_dir.mkdir() |
| 276 | + for name in ("python3", "python"): |
| 277 | + shim = shim_dir / name |
| 278 | + shim.write_text("#!/bin/sh\nexit 1\n", encoding="utf-8", newline="\n") |
| 279 | + shim.chmod(0o755) |
| 280 | + launcher = shim_dir / "py" |
| 281 | + launcher.write_text( |
| 282 | + "#!/bin/sh\n" |
| 283 | + '[ "$1" = "-3" ] || exit 1\n' |
| 284 | + "shift\n" |
| 285 | + f'exec {shlex.quote(_bash_posix_path(Path(sys.executable)))} "$@"\n', |
| 286 | + encoding="utf-8", |
| 287 | + newline="\n", |
| 288 | + ) |
| 289 | + launcher.chmod(0o755) |
| 290 | + env = clean_env() |
| 291 | + env["PATH"] = f"{shim_dir}{os.pathsep}{env['PATH']}" |
| 292 | + |
| 293 | + result = run(bash_cmd(repo, SCRIPT, "--json", "--dry-run", "添加用户"), repo, env) |
| 294 | + |
| 295 | + assert result.returncode == 0, result.stderr |
| 296 | + assert json_stdout(result)["BRANCH_NAME"] == "001-添加用户" |
| 297 | + |
| 298 | + |
245 | 299 | def _run_all_variants_allow_existing( |
246 | 300 | repo: Path, *, number: str, short_name: str |
247 | 301 | ): |
|
0 commit comments