fix: python3 compatibility in shell hand tests (#56)
Some checks failed
Tests / lint (pull_request) Successful in 2s
Tests / test (pull_request) Failing after 55s

- Use sys.executable instead of hardcoded "python" in tests
- Fixes test_run_python_expression and test_run_nonzero_exit
- Passes allowed_prefixes for both python and python3
This commit is contained in:
2026-03-14 19:22:21 -04:00
parent b01c1cb582
commit 2ffee7c8fa

View File

@@ -10,6 +10,7 @@ Covers:
"""
import asyncio
import sys
import pytest
@@ -91,8 +92,10 @@ async def test_run_python_expression():
"""Running a python one-liner should succeed."""
from infrastructure.hands.shell import ShellHand
hand = ShellHand()
result = await hand.run("python -c 'print(2 + 2)'")
# Allow both 'python' and 'python3' (sys.executable basename)
allowed = ("python", "python3")
hand = ShellHand(allowed_prefixes=allowed)
result = await hand.run(f"{sys.executable} -c 'print(2 + 2)'")
assert result.success is True
assert "4" in result.stdout
@@ -118,8 +121,10 @@ async def test_run_nonzero_exit():
"""A command that exits non-zero should return success=False."""
from infrastructure.hands.shell import ShellHand
hand = ShellHand()
result = await hand.run("python -c 'import sys; sys.exit(1)'")
# Allow both 'python' and 'python3' (sys.executable basename)
allowed = ("python", "python3")
hand = ShellHand(allowed_prefixes=allowed)
result = await hand.run(f"{sys.executable} -c 'import sys; sys.exit(1)'")
assert result.success is False
assert result.exit_code == 1