Skip to content

Commit

Permalink
fixed some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nalbion committed Oct 3, 2023
1 parent d6a677c commit f446c0f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
3 changes: 1 addition & 2 deletions pilot/helpers/agents/test_Developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ def setup_method(self):
@patch('helpers.AgentConvo.save_development_step')
@patch('helpers.AgentConvo.create_gpt_chat_completion',
return_value={'text': '{"command": "python --version", "timeout": 10}'})
@patch('helpers.cli.styled_text', return_value='no')
@patch('helpers.cli.execute_command', return_value=('', 'DONE'))
def test_install_technology(self, mock_execute_command, mock_styled_text,
def test_install_technology(self, mock_execute_command,
mock_completion, mock_save, mock_get_saved_step):
# Given
self.developer.convo_os_specific_tech = AgentConvo(self.developer)
Expand Down
11 changes: 9 additions & 2 deletions pilot/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from database.database import save_user_app


def get_parent_folder(folder_name):
current_path = Path(os.path.abspath(__file__)) # get the path of the current script

Expand All @@ -11,7 +12,14 @@ def get_parent_folder(folder_name):
return current_path.parent


def setup_workspace(args):
def setup_workspace(args) -> str:
"""
Creates & returns the path to the project workspace.
Also creates a 'tests' folder inside the workspace.
:param args: may contain 'workspace' or 'root' keys
"""
# `args['workspace']` can be used to work with an existing workspace at the specified path.
# `args['root']` is used by VS Code for (nearly) the same purpose, but `args['name']` is appended to it.
workspace = args.get('workspace')
if workspace:
try:
Expand All @@ -23,7 +31,6 @@ def setup_workspace(args):
return args['workspace']

root = args.get('root') or get_parent_folder('pilot')
create_directory(root, 'workspace')
project_path = create_directory(os.path.join(root, 'workspace'), args.get('name', 'default_project_name'))
create_directory(project_path, 'tests')
return project_path
Expand Down
32 changes: 18 additions & 14 deletions pilot/utils/test_llm_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_DEVELOPMENT_PLAN(self):
}
'''.strip(), DEVELOPMENT_PLAN['definitions']))


class TestLlmConnection:
def setup_method(self):
builtins.print, ipc_client_instance = get_custom_print({})
Expand All @@ -121,9 +122,12 @@ def test_stream_gpt_completion(self, mock_post, monkeypatch):

mock_post.return_value = mock_response

# When
with patch('utils.llm_connection.requests.post', return_value=mock_response):
response = stream_gpt_completion({}, '')
# When
response = stream_gpt_completion({
'model': 'gpt-4',
'messages': [],
}, '', project)

# Then
assert response == {'text': '{\n "foo": "bar",\n "prompt": "Hello",\n "choices": []\n}'}
Expand Down Expand Up @@ -174,7 +178,7 @@ def test_chat_completion_Architect(self, endpoint, model, monkeypatch):
function_calls = ARCHITECTURE

# When
response = create_gpt_chat_completion(convo.messages, '', function_calls=function_calls)
response = create_gpt_chat_completion(convo.messages, '', project, function_calls=function_calls)

# Then
assert convo.messages[0]['content'].startswith('You are an experienced software architect')
Expand Down Expand Up @@ -225,19 +229,19 @@ def test_chat_completion_TechLead(self, endpoint, model, monkeypatch):
# Retry on bad LLM responses
mock_questionary = MockQuestionary(['', '', 'no'])

# with patch('utils.llm_connection.questionary', mock_questionary):
# When
with patch('utils.llm_connection.questionary', mock_questionary):
response = create_gpt_chat_completion(convo.messages, '', function_calls=function_calls)
response = create_gpt_chat_completion(convo.messages, '', project, function_calls=function_calls)

# Then
assert convo.messages[0]['content'].startswith('You are a tech lead in a software development agency')
assert convo.messages[1]['content'].startswith('You are working in a software development agency and a project manager and software architect approach you')

assert response is not None
response = parse_agent_response(response, function_calls)
assert_non_empty_string(response[0]['description'])
assert_non_empty_string(response[0]['programmatic_goal'])
assert_non_empty_string(response[0]['user_review_goal'])
# Then
assert convo.messages[0]['content'].startswith('You are a tech lead in a software development agency')
assert convo.messages[1]['content'].startswith('You are working in a software development agency and a project manager and software architect approach you')

assert response is not None
response = parse_agent_response(response, function_calls)
assert_non_empty_string(response[0]['description'])
assert_non_empty_string(response[0]['programmatic_goal'])
assert_non_empty_string(response[0]['user_review_goal'])


# def test_break_down_development_task(self):
Expand Down

0 comments on commit f446c0f

Please sign in to comment.