-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_aishell.py
62 lines (48 loc) · 2.38 KB
/
test_aishell.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
from unittest import TestCase
from ai_shell.aishell import AiShell
from ai_shell.shell import Shell
from ai_shell.models import CommandPlan
from ai_shell.util import ensure_empty_directory
import os
class Test(TestCase):
def setUp(self):
ensure_empty_directory("build/test-output")
def test_execute_goal(self):
filename = "build/test-output/output.txt"
self.assertFalse(os.path.isfile(filename))
aishell = AiShell(
f"Write the text 'Hello World' into the file '{filename}'",
user_input_source=lambda: "")
# first command should be something like "echo 'Hello World' > build/test-output/output.txt"
self.assertTrue(aishell.run_once())
self.assertTrue("Hello World" in aishell.iterations[-1].command_plan.command)
self.assertTrue(os.path.isfile(filename))
with open(filename, "r") as file:
self.assertEqual('Hello World', file.read().strip())
self.assertTrue("output.txt" in aishell.iterations[-1].command_plan.check_command)
#next call the ai confirms that the job is done.
self.assertFalse(aishell.run_once())
def test_user_command(self):
filename = "build/test-output/output.txt"
self.assertFalse(os.path.isfile(filename))
user_input_iterator = iter([
f"Instead of 'Original Goal', write the text 'Hello World' into the file '{filename}'.",
"", "", ""])
aishell = AiShell(
f"Write the text 'Original goal' into the file '{filename}'",
user_input_source=lambda: next(user_input_iterator))
self.assertEqual(
[True, True, False],
[ aishell.run_once(), aishell.run_once(), aishell.run_once()])
self.assertTrue(os.path.isfile(filename))
with open(filename, "r") as file:
self.assertEqual('Hello World', file.read().strip())
def test_check_commands_availability(self):
"""Should be moved to test for shell only."""
shell = Shell()
shell.check_commands_availability([CommandPlan(
used_commands = ["ls", "cat", "this-command-does-not-exist"],
command="irrelevant", directory=".", plan="any plan", check_command = "does not matter"
)])
self.assertEqual({"ls", "cat"}, shell.available_commands)
self.assertEqual({"this-command-does-not-exist"}, shell.unavailable_commands)