forked from Significant-Gravitas/AutoGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoke_test.py
63 lines (51 loc) · 2.22 KB
/
smoke_test.py
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
import os
import subprocess
import sys
import unittest
from autogpt.commands.file_operations import delete_file, read_file
env_vars = {"MEMORY_BACKEND": "no_memory", "TEMPERATURE": "0"}
class TestCommands(unittest.TestCase):
def test_write_file(self):
# Test case to check if the write_file command can successfully write 'Hello World' to a file
# named 'hello_world.txt'.
# Read the current ai_settings.yaml file and store its content.
ai_settings = None
if os.path.exists("ai_settings.yaml"):
with open("ai_settings.yaml", "r") as f:
ai_settings = f.read()
os.remove("ai_settings.yaml")
try:
if os.path.exists("hello_world.txt"):
# Clean up any existing 'hello_world.txt' file before testing.
delete_file("hello_world.txt")
# Prepare input data for the test.
input_data = """write_file-GPT
an AI designed to use the write_file command to write 'Hello World' into a file named "hello_world.txt" and then use the task_complete command to complete the task.
Use the write_file command to write 'Hello World' into a file named "hello_world.txt".
Use the task_complete command to complete the task.
Do not use any other commands.
y -5
EOF"""
command = f"{sys.executable} -m autogpt"
# Execute the script with the input data.
process = subprocess.Popen(
command,
stdin=subprocess.PIPE,
shell=True,
env={**os.environ, **env_vars},
)
process.communicate(input_data.encode())
# Read the content of the 'hello_world.txt' file created during the test.
content = read_file("hello_world.txt")
finally:
if ai_settings:
# Restore the original ai_settings.yaml file.
with open("ai_settings.yaml", "w") as f:
f.write(ai_settings)
# Check if the content of the 'hello_world.txt' file is equal to 'Hello World'.
self.assertEqual(
content, "Hello World", f"Expected 'Hello World', got {content}"
)
# Run the test case.
if __name__ == "__main__":
unittest.main()