test_images.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """Image-related tests for the EventStreamRuntime, which connects to the RuntimeClient running in the sandbox."""
  2. import time
  3. import pytest
  4. from conftest import _load_runtime
  5. from openhands.core.logger import openhands_logger as logger
  6. from openhands.events.action import CmdRunAction
  7. # ============================================================================================================================
  8. # Image-specific tests
  9. # ============================================================================================================================
  10. def test_bash_python_version(temp_dir, box_class, base_container_image):
  11. """Make sure Python is available in bash."""
  12. if base_container_image not in [
  13. 'python:3.11-bookworm',
  14. 'nikolaik/python-nodejs:python3.11-nodejs22',
  15. ]:
  16. pytest.skip('This test is only for python-related images')
  17. runtime = _load_runtime(
  18. temp_dir, box_class, base_container_image=base_container_image
  19. )
  20. action = CmdRunAction(command='which python')
  21. logger.info(action, extra={'msg_type': 'ACTION'})
  22. obs = runtime.run_action(action)
  23. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  24. assert obs.exit_code == 0
  25. action = CmdRunAction(command='python --version')
  26. logger.info(action, extra={'msg_type': 'ACTION'})
  27. obs = runtime.run_action(action)
  28. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  29. assert obs.exit_code == 0
  30. assert 'Python 3.11' in obs.content # Check for specific version
  31. action = CmdRunAction(command='pip --version')
  32. logger.info(action, extra={'msg_type': 'ACTION'})
  33. obs = runtime.run_action(action)
  34. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  35. assert obs.exit_code == 0
  36. assert 'pip' in obs.content # Check that pip is available
  37. runtime.close(rm_all_containers=False)
  38. time.sleep(1)
  39. def test_nodejs_22_version(temp_dir, box_class, base_container_image):
  40. """Make sure Node.js is available in bash."""
  41. if base_container_image not in [
  42. 'node:22-bookworm',
  43. 'nikolaik/python-nodejs:python3.11-nodejs22',
  44. ]:
  45. pytest.skip('This test is only for nodejs-related images')
  46. runtime = _load_runtime(
  47. temp_dir, box_class, base_container_image=base_container_image
  48. )
  49. action = CmdRunAction(command='node --version')
  50. logger.info(action, extra={'msg_type': 'ACTION'})
  51. obs = runtime.run_action(action)
  52. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  53. assert obs.exit_code == 0
  54. assert 'v22' in obs.content # Check for specific version
  55. runtime.close(rm_all_containers=False)
  56. time.sleep(1)
  57. def test_go_version(temp_dir, box_class, base_container_image):
  58. """Make sure Go is available in bash."""
  59. if base_container_image not in [
  60. 'golang:1.23-bookworm',
  61. ]:
  62. pytest.skip('This test is only for go-related images')
  63. runtime = _load_runtime(
  64. temp_dir, box_class, base_container_image=base_container_image
  65. )
  66. action = CmdRunAction(command='go version')
  67. logger.info(action, extra={'msg_type': 'ACTION'})
  68. obs = runtime.run_action(action)
  69. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  70. assert obs.exit_code == 0
  71. assert 'go1.23' in obs.content # Check for specific version
  72. runtime.close(rm_all_containers=False)
  73. time.sleep(1)