forked from Rockachopa/Timmy-time-dashboard
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 asyncio
|
||||||
|
import sys
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -91,8 +92,10 @@ async def test_run_python_expression():
|
|||||||
"""Running a python one-liner should succeed."""
|
"""Running a python one-liner should succeed."""
|
||||||
from infrastructure.hands.shell import ShellHand
|
from infrastructure.hands.shell import ShellHand
|
||||||
|
|
||||||
hand = ShellHand()
|
# Allow both 'python' and 'python3' (sys.executable basename)
|
||||||
result = await hand.run("python -c 'print(2 + 2)'")
|
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 result.success is True
|
||||||
assert "4" in result.stdout
|
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."""
|
"""A command that exits non-zero should return success=False."""
|
||||||
from infrastructure.hands.shell import ShellHand
|
from infrastructure.hands.shell import ShellHand
|
||||||
|
|
||||||
hand = ShellHand()
|
# Allow both 'python' and 'python3' (sys.executable basename)
|
||||||
result = await hand.run("python -c 'import sys; sys.exit(1)'")
|
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.success is False
|
||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user