aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/test_ai_config.py
blob: e3c31d5dc9bd3055ad55a5ce0aef47b13b988322 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from autogpt.config.ai_config import AIConfig

"""
Test cases for the AIConfig class, which handles loads the AI configuration
settings from a YAML file.
"""


def test_goals_are_always_lists_of_strings(tmp_path):
    """Test if the goals attribute is always a list of strings."""

    yaml_content = """
ai_goals:
- Goal 1: Make a sandwich
- Goal 2, Eat the sandwich
- Goal 3 - Go to sleep
- "Goal 4: Wake up"
ai_name: McFamished
ai_role: A hungry AI
api_budget: 0.0
"""
    ai_settings_file = tmp_path / "ai_settings.yaml"
    ai_settings_file.write_text(yaml_content)

    ai_config = AIConfig.load(ai_settings_file)

    assert len(ai_config.ai_goals) == 4
    assert ai_config.ai_goals[0] == "Goal 1: Make a sandwich"
    assert ai_config.ai_goals[1] == "Goal 2, Eat the sandwich"
    assert ai_config.ai_goals[2] == "Goal 3 - Go to sleep"
    assert ai_config.ai_goals[3] == "Goal 4: Wake up"

    ai_settings_file.write_text("")
    ai_config.save(ai_settings_file)

    yaml_content2 = """ai_goals:
- 'Goal 1: Make a sandwich'
- Goal 2, Eat the sandwich
- Goal 3 - Go to sleep
- 'Goal 4: Wake up'
ai_name: McFamished
ai_role: A hungry AI
api_budget: 0.0
"""
    assert ai_settings_file.read_text() == yaml_content2


def test_ai_config_file_not_exists(workspace):
    """Test if file does not exist."""

    ai_settings_file = workspace.get_path("ai_settings.yaml")

    ai_config = AIConfig.load(str(ai_settings_file))
    assert ai_config.ai_name == ""
    assert ai_config.ai_role == ""
    assert ai_config.ai_goals == []
    assert ai_config.api_budget == 0.0
    assert ai_config.prompt_generator is None
    assert ai_config.command_registry is None


def test_ai_config_file_is_empty(workspace):
    """Test if file does not exist."""

    ai_settings_file = workspace.get_path("ai_settings.yaml")
    ai_settings_file.write_text("")

    ai_config = AIConfig.load(str(ai_settings_file))
    assert ai_config.ai_name == ""
    assert ai_config.ai_role == ""
    assert ai_config.ai_goals == []
    assert ai_config.api_budget == 0.0
    assert ai_config.prompt_generator is None
    assert ai_config.command_registry is None