You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_agent_setup_with_use_docker_settings.py 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from autogen import UserProxyAgent
  2. import pytest
  3. from conftest import skip_openai
  4. import os
  5. from autogen.code_utils import (
  6. is_docker_running,
  7. in_docker_container,
  8. )
  9. try:
  10. import openai
  11. except ImportError:
  12. skip = True
  13. else:
  14. skip = False or skip_openai
  15. def docker_running():
  16. return is_docker_running() or in_docker_container()
  17. @pytest.mark.skipif(skip, reason="openai not installed")
  18. def test_agent_setup_with_code_execution_off():
  19. user_proxy = UserProxyAgent(
  20. name="test_agent",
  21. human_input_mode="NEVER",
  22. code_execution_config=False,
  23. )
  24. assert user_proxy._code_execution_config is False
  25. @pytest.mark.skipif(skip, reason="openai not installed")
  26. def test_agent_setup_with_use_docker_false():
  27. user_proxy = UserProxyAgent(
  28. name="test_agent",
  29. human_input_mode="NEVER",
  30. code_execution_config={"use_docker": False},
  31. )
  32. assert user_proxy._code_execution_config["use_docker"] is False
  33. @pytest.mark.skipif(skip, reason="openai not installed")
  34. def test_agent_setup_with_env_variable_false_and_docker_running(monkeypatch):
  35. monkeypatch.setenv("AUTOGEN_USE_DOCKER", "False")
  36. user_proxy = UserProxyAgent(
  37. name="test_agent",
  38. human_input_mode="NEVER",
  39. )
  40. assert user_proxy._code_execution_config["use_docker"] is False
  41. @pytest.mark.skipif(skip or (not docker_running()), reason="openai not installed OR docker not running")
  42. def test_agent_setup_with_default_and_docker_running(monkeypatch):
  43. monkeypatch.delenv("AUTOGEN_USE_DOCKER", raising=False)
  44. assert os.getenv("AUTOGEN_USE_DOCKER") is None
  45. user_proxy = UserProxyAgent(
  46. name="test_agent",
  47. human_input_mode="NEVER",
  48. )
  49. assert os.getenv("AUTOGEN_USE_DOCKER") is None
  50. assert user_proxy._code_execution_config["use_docker"] is True
  51. @pytest.mark.skipif(skip or (docker_running()), reason="openai not installed OR docker running")
  52. def test_raises_error_agent_setup_with_default_and_docker_not_running(monkeypatch):
  53. monkeypatch.delenv("AUTOGEN_USE_DOCKER", raising=False)
  54. with pytest.raises(RuntimeError):
  55. UserProxyAgent(
  56. name="test_agent",
  57. human_input_mode="NEVER",
  58. )
  59. @pytest.mark.skipif(skip or (docker_running()), reason="openai not installed OR docker running")
  60. def test_raises_error_agent_setup_with_env_variable_true_and_docker_not_running(monkeypatch):
  61. monkeypatch.setenv("AUTOGEN_USE_DOCKER", "True")
  62. with pytest.raises(RuntimeError):
  63. UserProxyAgent(
  64. name="test_agent",
  65. human_input_mode="NEVER",
  66. )
  67. @pytest.mark.skipif(skip or (not docker_running()), reason="openai not installed OR docker not running")
  68. def test_agent_setup_with_env_variable_true_and_docker_running(monkeypatch):
  69. monkeypatch.setenv("AUTOGEN_USE_DOCKER", "True")
  70. user_proxy = UserProxyAgent(
  71. name="test_agent",
  72. human_input_mode="NEVER",
  73. )
  74. assert user_proxy._code_execution_config["use_docker"] is True