2024-04-05 10:26:06 +08:00
|
|
|
import os
|
2024-04-15 05:34:26 -07:00
|
|
|
import sys
|
2024-04-05 10:26:06 +08:00
|
|
|
|
2024-01-18 19:03:49 +02:00
|
|
|
import pytest
|
|
|
|
|
2024-04-05 10:26:06 +08:00
|
|
|
from autogen import UserProxyAgent
|
2024-01-18 19:03:49 +02:00
|
|
|
from autogen.code_utils import (
|
|
|
|
in_docker_container,
|
2024-04-05 10:26:06 +08:00
|
|
|
is_docker_running,
|
2024-01-18 19:03:49 +02:00
|
|
|
)
|
|
|
|
|
2024-04-15 05:34:26 -07:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
from conftest import reason, skip_openai
|
2024-01-18 19:03:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
def docker_running():
|
|
|
|
return is_docker_running() or in_docker_container()
|
|
|
|
|
|
|
|
|
2024-04-15 05:34:26 -07:00
|
|
|
@pytest.mark.skipif(skip_openai, reason=reason)
|
2024-01-18 19:03:49 +02:00
|
|
|
def test_agent_setup_with_code_execution_off():
|
|
|
|
user_proxy = UserProxyAgent(
|
|
|
|
name="test_agent",
|
|
|
|
human_input_mode="NEVER",
|
|
|
|
code_execution_config=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert user_proxy._code_execution_config is False
|
|
|
|
|
|
|
|
|
2024-04-15 05:34:26 -07:00
|
|
|
@pytest.mark.skipif(skip_openai, reason=reason)
|
2024-01-18 19:03:49 +02:00
|
|
|
def test_agent_setup_with_use_docker_false():
|
|
|
|
user_proxy = UserProxyAgent(
|
|
|
|
name="test_agent",
|
|
|
|
human_input_mode="NEVER",
|
|
|
|
code_execution_config={"use_docker": False},
|
|
|
|
)
|
|
|
|
|
|
|
|
assert user_proxy._code_execution_config["use_docker"] is False
|
|
|
|
|
|
|
|
|
2024-04-15 05:34:26 -07:00
|
|
|
@pytest.mark.skipif(skip_openai, reason=reason)
|
2024-03-13 23:57:43 +01:00
|
|
|
def test_agent_setup_with_env_variable_false_and_docker_running(monkeypatch):
|
|
|
|
monkeypatch.setenv("AUTOGEN_USE_DOCKER", "False")
|
2024-01-18 19:03:49 +02:00
|
|
|
|
|
|
|
user_proxy = UserProxyAgent(
|
|
|
|
name="test_agent",
|
|
|
|
human_input_mode="NEVER",
|
|
|
|
)
|
|
|
|
|
|
|
|
assert user_proxy._code_execution_config["use_docker"] is False
|
|
|
|
|
|
|
|
|
2024-04-15 05:34:26 -07:00
|
|
|
@pytest.mark.skipif(skip_openai or (not docker_running()), reason=reason + " OR docker not running")
|
2024-03-13 23:57:43 +01:00
|
|
|
def test_agent_setup_with_default_and_docker_running(monkeypatch):
|
|
|
|
monkeypatch.delenv("AUTOGEN_USE_DOCKER", raising=False)
|
|
|
|
|
|
|
|
assert os.getenv("AUTOGEN_USE_DOCKER") is None
|
|
|
|
|
2024-01-18 19:03:49 +02:00
|
|
|
user_proxy = UserProxyAgent(
|
|
|
|
name="test_agent",
|
|
|
|
human_input_mode="NEVER",
|
|
|
|
)
|
|
|
|
|
2024-03-13 23:57:43 +01:00
|
|
|
assert os.getenv("AUTOGEN_USE_DOCKER") is None
|
|
|
|
|
2024-01-18 19:03:49 +02:00
|
|
|
assert user_proxy._code_execution_config["use_docker"] is True
|
|
|
|
|
|
|
|
|
2024-04-15 05:34:26 -07:00
|
|
|
@pytest.mark.skipif(skip_openai or (docker_running()), reason=reason + " OR docker running")
|
2024-03-13 23:57:43 +01:00
|
|
|
def test_raises_error_agent_setup_with_default_and_docker_not_running(monkeypatch):
|
|
|
|
monkeypatch.delenv("AUTOGEN_USE_DOCKER", raising=False)
|
2024-01-18 19:03:49 +02:00
|
|
|
with pytest.raises(RuntimeError):
|
|
|
|
UserProxyAgent(
|
|
|
|
name="test_agent",
|
|
|
|
human_input_mode="NEVER",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-15 05:34:26 -07:00
|
|
|
@pytest.mark.skipif(skip_openai or (docker_running()), reason=" OR docker running")
|
2024-03-13 23:57:43 +01:00
|
|
|
def test_raises_error_agent_setup_with_env_variable_true_and_docker_not_running(monkeypatch):
|
|
|
|
monkeypatch.setenv("AUTOGEN_USE_DOCKER", "True")
|
2024-01-18 19:03:49 +02:00
|
|
|
|
|
|
|
with pytest.raises(RuntimeError):
|
|
|
|
UserProxyAgent(
|
|
|
|
name="test_agent",
|
|
|
|
human_input_mode="NEVER",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-15 05:34:26 -07:00
|
|
|
@pytest.mark.skipif(skip_openai or (not docker_running()), reason=" OR docker not running")
|
2024-03-13 23:57:43 +01:00
|
|
|
def test_agent_setup_with_env_variable_true_and_docker_running(monkeypatch):
|
|
|
|
monkeypatch.setenv("AUTOGEN_USE_DOCKER", "True")
|
2024-01-18 19:03:49 +02:00
|
|
|
|
|
|
|
user_proxy = UserProxyAgent(
|
|
|
|
name="test_agent",
|
|
|
|
human_input_mode="NEVER",
|
|
|
|
)
|
|
|
|
|
|
|
|
assert user_proxy._code_execution_config["use_docker"] is True
|