OpenAI assistants automations to generate python3 unittest files
BorgTestGenerator is a Python library that generates unit test files from Python scripts using the OpenAI API.
This section provides instructions for installing the librarie package from pip using a virtual environment (venv).
-
Create a virtual environment:
python3 -m venv venv
-
Activate the virtual environment:
- On Linux or macOS:
source venv/bin/activate
- On Windows:
.\venv\Scripts\activate
- On Linux or macOS:
-
Update pip from pip:
python3 -m pip install --upgrade pip
-
Install the package from pip:
python3 -m pip install -U BorgTestGenerator
To use the Assistant
class from the BorgTestGenerator
module in your code, you need to follow these steps:
-
Import the
Assistant
class from theBorgTestGenerator
module in your Python file. Make sure theBorgTestGenerator
module is installed in your Python environment using thepip install BorgTestGenerator
command.from BorgTestGenerator.assistant import Assistant
-
Create an instance of the
Assistant
class using the constructor. You can provide additional arguments to the constructor based on your application's needs.assistant = Assistant()
-
Set the user input that describes the task to be performed using the
set_user_input
method.assistant.create_assistant( name="Test Assistant", instructions="This is a test assistant.", model="gpt-4o", tool_code_interpreter=True, tool_file_search=True )
Pour utiliser la classe AssistantBackupManager
du module BorgTestGenerator.assistant
, suivez les étapes ci-dessous :
-
Importer la classe
AssistantBackupManager
:from BorgTestGenerator.assistant import AssistantBackupManager
-
Créer une instance de la classe
AssistantBackupManager
:assistant_backup_manager = AssistantBackupManager()
-
Définir l'entrée utilisateur qui décrit la tâche à effectuer :
assistant_backup_manager.backup()
Ces étapes permettent de configurer et d'utiliser le AssistantBackupManager
pour gérer les sauvegardes de manière automatisée.
The following example shows how to use the UnitTestWriter
class from the BorgTestGenerator.agents.unittestwriter
module to generate unit test files for Python scripts.
# Import the UnitTestWriter class from the BorgTestGenerator.agents.unittestwriter module
from BorgTestGenerator.agents.unittestwriter import UnitTestWriter
# Create an instance of the UnitTestWriter class with the code language specified as Python
testWriter = UnitTestWriter(code_language="python")
# Set the user input that describes the task to be performed
testWriter.set_user_input("Write the code for the test file corresponding to this Python script")
# Add the Python files for which unit tests should be generated
testWriter.add_upload(["/path/to/file1.py", "/path/to/file2.py"])
# Define the vector store name
testWriter.define_vector_store_name("test_vector_store")
# Generate the unit test files
testWriter.generate()
In this example:
- Import: The
UnitTestWriter
class is imported from theBorgTestGenerator.agents.unittestwriter
module. - Instance: An instance of
UnitTestWriter
is created with thecode_language
parameter set to"python"
. - User input: The
set_user_input
method is used to set a task description in French. - File addition: The
add_upload
method adds the paths of the Python files for which tests should be generated. - Vector store name: The
define_vector_store_name
method defines the name of the vector store used. - Generation: The
generate
method triggers the generation of the unit test files.
This example demonstrates how to automate the generation of unit tests for Python scripts using the UnitTestWriter
class.