|
1 | 1 | import argparse |
2 | 2 | import configparser |
| 3 | +import subprocess |
3 | 4 | from pathlib import Path |
4 | 5 |
|
5 | 6 | import pytest |
@@ -463,6 +464,54 @@ def test_write_load_script_uses_user_pixi_when_configured_for_path_lookup( |
463 | 464 | ) |
464 | 465 | assert 'command -v pixi' in script_text |
465 | 466 | assert 'Set PIXI to a pixi executable path' in script_text |
| 467 | + assert '"${PIXI}" shell-hook --as-is -s bash -m' in script_text |
| 468 | + assert '"${PIXI}" run --as-is -m' in script_text |
| 469 | + |
| 470 | + |
| 471 | +def test_load_script_fails_before_calling_pixi_when_env_missing( |
| 472 | + tmp_path: Path, monkeypatch: pytest.MonkeyPatch |
| 473 | +): |
| 474 | + monkeypatch.chdir(tmp_path) |
| 475 | + |
| 476 | + marker = tmp_path / 'pixi-called.txt' |
| 477 | + pixi_exe = tmp_path / 'bin' / 'pixi' |
| 478 | + pixi_exe.parent.mkdir(parents=True, exist_ok=True) |
| 479 | + pixi_exe.write_text( |
| 480 | + f'#!/bin/sh\nprintf called > {marker}\nexit 99\n', |
| 481 | + encoding='utf-8', |
| 482 | + ) |
| 483 | + pixi_exe.chmod(0o755) |
| 484 | + |
| 485 | + compute_prefix = tmp_path / 'compute' |
| 486 | + compute_prefix.mkdir() |
| 487 | + |
| 488 | + script_path = deploy_run._write_load_script( |
| 489 | + prefix=str(compute_prefix), |
| 490 | + login_env=None, |
| 491 | + pixi_exe=str(pixi_exe), |
| 492 | + branch_path=str(tmp_path), |
| 493 | + load_script_pixi_exe=_explicit_load_script_pixi(str(pixi_exe)), |
| 494 | + software='e3sm-unified', |
| 495 | + software_version='1.0.0', |
| 496 | + runtime_version_cmd=None, |
| 497 | + machine=None, |
| 498 | + compute_pixi_mpi='nompi', |
| 499 | + toolchain_compiler=None, |
| 500 | + toolchain_mpi=None, |
| 501 | + spack_library_view=None, |
| 502 | + spack_activation='', |
| 503 | + ) |
| 504 | + |
| 505 | + result = subprocess.run( |
| 506 | + ['bash', '-lc', f'source {script_path!s}'], |
| 507 | + text=True, |
| 508 | + capture_output=True, |
| 509 | + ) |
| 510 | + |
| 511 | + assert result.returncode == 1 |
| 512 | + assert 'deployed pixi environment not found' in result.stderr |
| 513 | + assert str(compute_prefix / '.pixi' / 'envs' / 'default') in result.stderr |
| 514 | + assert not marker.exists() |
466 | 515 |
|
467 | 516 |
|
468 | 517 | def test_write_load_script_without_login_env_skips_compute_detection( |
|
0 commit comments