Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zvonimir Sabljic committed Dec 6, 2023
1 parent d252c51 commit a074b60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
10 changes: 6 additions & 4 deletions pilot/helpers/agents/test_CodeMonkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def setup_method(self):
@patch.object(File, 'insert')
def test_implement_code_changes(self, mock_get_dev, mock_save_dev, mock_file_insert):
# Given
task_description = "High level description of the task"
code_changes_description = "Write the word 'Washington' to a .txt file"
self.project.get_all_coded_files = lambda: []

Expand All @@ -65,12 +66,12 @@ def test_implement_code_changes(self, mock_get_dev, mock_save_dev, mock_file_ins
convo.send_message.side_effect = mock_responses

if WRITE_TO_FILE:
self.codeMonkey.implement_code_changes(convo, code_changes_description, {})
self.codeMonkey.implement_code_changes(convo, task_description, code_changes_description, {})
else:
# don't write the file, just
with patch.object(Project, 'save_file') as mock_save_file:
# When
self.codeMonkey.implement_code_changes(convo, code_changes_description, {})
self.codeMonkey.implement_code_changes(convo, task_description, code_changes_description, {})

# Then
mock_save_file.assert_called_once()
Expand All @@ -85,6 +86,7 @@ def test_implement_code_changes(self, mock_get_dev, mock_save_dev, mock_file_ins
@patch.object(File, 'insert')
def test_implement_code_changes_with_read(self, mock_get_dev, mock_save_dev, mock_file_insert):
# Given
task_description = "High level description of the task"
code_changes_description = "Read the file called file_to_read.txt and write its content to a file called output.txt"
workspace = self.project.root_path
update_file(os.path.join(workspace, 'file_to_read.txt'), 'Hello World!\n')
Expand All @@ -106,11 +108,11 @@ def test_implement_code_changes_with_read(self, mock_get_dev, mock_save_dev, moc
convo.send_message.side_effect = mock_responses

if WRITE_TO_FILE:
self.codeMonkey.implement_code_changes(convo, code_changes_description, {})
self.codeMonkey.implement_code_changes(convo, task_description, code_changes_description, {})
else:
with patch.object(Project, 'save_file') as mock_save_file:
# When
self.codeMonkey.implement_code_changes(convo, code_changes_description, {})
self.codeMonkey.implement_code_changes(convo, task_description, code_changes_description, {})

# Then
clear_directory(workspace)
Expand Down
13 changes: 5 additions & 8 deletions pilot/helpers/agents/test_Developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_implement_task(self, mock_completion, mock_save, mock_get_saved_step):

# Then we parse the response correctly and send list of steps to execute_task()
assert developer.execute_task.call_count == 1
assert developer.execute_task.call_args[0][1] == [{'command': 'ls -al'}]
assert developer.execute_task.call_args[0][2] == [{'command': 'ls -al'}]

@patch('helpers.AgentConvo.get_saved_development_step')
@patch('helpers.AgentConvo.save_development_step')
Expand Down Expand Up @@ -132,7 +132,7 @@ def test_code_changes_command_test(self, mock_get_saved_step, mock_save, mock_ch
result = self.developer.test_code_changes(monkey, convo)

# Then
assert result == {'success': True, 'cli_response': 'stdout:\n```\n\n```'}
assert result == {'success': True}

@patch('helpers.AgentConvo.get_saved_development_step')
@patch('helpers.AgentConvo.save_development_step')
Expand All @@ -150,7 +150,7 @@ def test_code_changes_manual_test_continue(self, mock_get_saved_step, mock_save,
result = self.developer.test_code_changes(monkey, convo)

# Then
assert result == {'success': True, 'user_input': 'continue'}
assert result == {'success': True}

@pytest.mark.skip("endless loop in questionary")
@patch('helpers.AgentConvo.get_saved_development_step')
Expand Down Expand Up @@ -234,8 +234,5 @@ def generate_response(*args, **kwargs):
result = self.developer.test_code_changes(monkey, convo)

# Then
assert result == {'success': True, 'cli_response': 'stdout:\n```\n\n```'}
assert mock_requests_post.call_count == 3
assert "The JSON is invalid at $.type - 'command' is not one of " \
"['command_test', 'manual_test', 'no_test']" in json_received[1][3]
assert mock_execute.call_count == 1
assert result == {'success': True}
assert mock_requests_post.call_count == 0

0 comments on commit a074b60

Please sign in to comment.