restoring other tests

This commit is contained in:
Nicholas Albion
2023-10-04 18:15:55 +11:00
parent 009e05d54d
commit a1304d0d54
4 changed files with 79 additions and 82 deletions

View File

@@ -16,8 +16,7 @@ jobs:
matrix:
# 3.10 - 04 Oct 2021
# 3.11 - 24 Oct 2022
python-version: ['3.9']
# python-version: ['3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4

View File

@@ -226,7 +226,6 @@ class Project:
# TODO END
data['path'], data['full_path'] = self.get_full_file_path(data['path'], data['name'])
update_file(data['full_path'], data['content'])
(File.insert(app=self.app, path=data['path'], name=data['name'], full_path=data['full_path'])

View File

@@ -1,6 +1,6 @@
import re
import os
from unittest.mock import patch, Mock, MagicMock
from unittest.mock import patch, MagicMock
from dotenv import load_dotenv
load_dotenv()
@@ -40,80 +40,80 @@ class TestCodeMonkey:
self.developer = Developer(self.project)
self.codeMonkey = CodeMonkey(self.project, developer=self.developer)
# @patch('helpers.AgentConvo.get_saved_development_step', return_value=None)
# @patch('helpers.AgentConvo.save_development_step', new_callable=MagicMock)
# @patch('os.get_terminal_size', mock_terminal_size)
# @patch.object(File, 'insert')
# def test_implement_code_changes(self, mock_get_dev, mock_save_dev, mock_file_insert):
# # Given
# code_changes_description = "Write the word 'Washington' to a .txt file"
#
# if SEND_TO_LLM:
# convo = AgentConvo(self.codeMonkey)
# else:
# convo = MagicMock()
# mock_responses = [
# # [],
# [{
# 'content': 'Washington',
# 'description': "A new .txt file with the word 'Washington' in it.",
# 'name': 'washington.txt',
# 'path': 'washington.txt'
# }]
# ]
# convo.send_message.side_effect = mock_responses
#
# if WRITE_TO_FILE:
# self.codeMonkey.implement_code_changes(convo, 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)
#
# # Then
# mock_save_file.assert_called_once()
# called_data = mock_save_file.call_args[0][0]
# assert re.match(r'\w+\.txt$', called_data['name'])
# assert (called_data['path'] == '/' or called_data['path'] == called_data['name'])
# assert called_data['content'] == 'Washington'
#
# @patch('helpers.AgentConvo.get_saved_development_step', return_value=None)
# @patch('helpers.AgentConvo.save_development_step', new_callable=MagicMock)
# @patch('os.get_terminal_size', mock_terminal_size)
# @patch.object(File, 'insert')
# def test_implement_code_changes_with_read(self, mock_get_dev, mock_save_dev, mock_file_insert):
# # Given
# 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')
#
# if SEND_TO_LLM:
# convo = AgentConvo(self.codeMonkey)
# else:
# convo = MagicMock()
# mock_responses = [
# # ['file_to_read.txt', 'output.txt'],
# [{
# 'content': 'Hello World!\n',
# 'description': 'This file is the output file. The content of file_to_read.txt is copied into this file.',
# 'name': 'output.txt',
# 'path': 'output.txt'
# }]
# ]
# convo.send_message.side_effect = mock_responses
#
# if WRITE_TO_FILE:
# self.codeMonkey.implement_code_changes(convo, code_changes_description)
# else:
# with patch.object(Project, 'save_file') as mock_save_file:
# # When
# self.codeMonkey.implement_code_changes(convo, code_changes_description)
#
# # Then
# clear_directory(workspace)
# mock_save_file.assert_called_once()
# called_data = mock_save_file.call_args[0][0]
# assert called_data['name'] == 'output.txt'
# assert (called_data['path'] == '/' or called_data['path'] == called_data['name'])
# assert called_data['content'] == 'Hello World!\n'
@patch('helpers.AgentConvo.get_saved_development_step', return_value=None)
@patch('helpers.AgentConvo.save_development_step', new_callable=MagicMock)
@patch('os.get_terminal_size', mock_terminal_size)
@patch.object(File, 'insert')
def test_implement_code_changes(self, mock_get_dev, mock_save_dev, mock_file_insert):
# Given
code_changes_description = "Write the word 'Washington' to a .txt file"
if SEND_TO_LLM:
convo = AgentConvo(self.codeMonkey)
else:
convo = MagicMock()
mock_responses = [
# [],
[{
'content': 'Washington',
'description': "A new .txt file with the word 'Washington' in it.",
'name': 'washington.txt',
'path': 'washington.txt'
}]
]
convo.send_message.side_effect = mock_responses
if WRITE_TO_FILE:
self.codeMonkey.implement_code_changes(convo, 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)
# Then
mock_save_file.assert_called_once()
called_data = mock_save_file.call_args[0][0]
assert re.match(r'\w+\.txt$', called_data['name'])
assert (called_data['path'] == '/' or called_data['path'] == called_data['name'])
assert called_data['content'] == 'Washington'
@patch('helpers.AgentConvo.get_saved_development_step', return_value=None)
@patch('helpers.AgentConvo.save_development_step', new_callable=MagicMock)
@patch('os.get_terminal_size', mock_terminal_size)
@patch.object(File, 'insert')
def test_implement_code_changes_with_read(self, mock_get_dev, mock_save_dev, mock_file_insert):
# Given
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')
if SEND_TO_LLM:
convo = AgentConvo(self.codeMonkey)
else:
convo = MagicMock()
mock_responses = [
# ['file_to_read.txt', 'output.txt'],
[{
'content': 'Hello World!\n',
'description': 'This file is the output file. The content of file_to_read.txt is copied into this file.',
'name': 'output.txt',
'path': 'output.txt'
}]
]
convo.send_message.side_effect = mock_responses
if WRITE_TO_FILE:
self.codeMonkey.implement_code_changes(convo, code_changes_description)
else:
with patch.object(Project, 'save_file') as mock_save_file:
# When
self.codeMonkey.implement_code_changes(convo, code_changes_description)
# Then
clear_directory(workspace)
mock_save_file.assert_called_once()
called_data = mock_save_file.call_args[0][0]
assert called_data['name'] == 'output.txt'
assert (called_data['path'] == '/' or called_data['path'] == called_data['name'])
assert called_data['content'] == 'Hello World!\n'

View File

@@ -12,7 +12,6 @@ prompt-toolkit==3.0.39
psycopg2-binary==2.9.6
python-dotenv==1.0.0
python-editor==1.0.4
pytest-mock==3.11.1
questionary==1.10.0
readchar==4.0.5
regex==2023.6.3