fix: python3 compatibility in shell hand tests (#56)
- 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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user