test_agent.py 966 B

123456789101112131415161718192021222324252627282930
  1. import asyncio
  2. import os
  3. import subprocess
  4. import pytest
  5. from opendevin.core.main import main
  6. # skip if
  7. @pytest.mark.skipif(
  8. os.getenv('AGENT') == 'CodeActAgent'
  9. and os.getenv('SANDBOX_TYPE').lower() == 'exec',
  10. reason='CodeActAgent does not support exec sandbox since exec sandbox is NOT stateful',
  11. )
  12. def test_write_simple_script():
  13. task = "Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point."
  14. asyncio.run(main(task))
  15. # Verify the script file exists
  16. script_path = os.path.join(os.getenv('WORKSPACE_BASE'), 'hello.sh')
  17. assert os.path.exists(script_path), 'The file "hello.sh" does not exist'
  18. # Run the script and capture the output
  19. result = subprocess.run(['bash', script_path], capture_output=True, text=True)
  20. # Verify the output from the script
  21. assert (
  22. result.stdout.strip() == 'hello'
  23. ), f'Expected output "hello", but got "{result.stdout.strip()}"'