Skip to main content

Librairie pour générer des tests unitaires à partir de scripts Python en utilisant OpenAI.

Project description

BorgTestGenerator

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.

Installation

Installation from pip ( with venv )

This section provides instructions for installing the librarie package from pip using a virtual environment (venv).

  1. Create a virtual environment:

    python3 -m venv venv
    
  2. Activate the virtual environment:

    • On Linux or macOS:
      source venv/bin/activate
      
    • On Windows:
      .\venv\Scripts\activate
      
  3. Update pip from pip:

    python3 -m pip install --upgrade pip
    
  4. Install the package from pip:

    python3 -m pip install -U BorgTestGenerator
    

Usage of BorgTestGenerator python library

To use the Assistant class from the BorgTestGenerator module in your code, you need to follow these steps:

  1. Import the Assistant class from the BorgTestGenerator module in your Python file. Make sure the BorgTestGenerator module is installed in your Python environment using the pip install BorgTestGenerator command.

    from BorgTestGenerator.assistant import Assistant
    
  2. 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()
    
  3. 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
    )
    

How To Use AssistantBackupManager

Pour utiliser la classe AssistantBackupManager du module BorgTestGenerator.assistant, suivez les étapes ci-dessous :

  1. Importer la classe AssistantBackupManager :

    from BorgTestGenerator.assistant import AssistantBackupManager
    
  2. Créer une instance de la classe AssistantBackupManager :

    assistant_backup_manager = AssistantBackupManager()
    
  3. 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.

How to use unittestwriter in your code

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:

  1. Import: The UnitTestWriter class is imported from the BorgTestGenerator.agents.unittestwriter module.
  2. Instance: An instance of UnitTestWriter is created with the code_language parameter set to "python".
  3. User input: The set_user_input method is used to set a task description in French.
  4. File addition: The add_upload method adds the paths of the Python files for which tests should be generated.
  5. Vector store name: The define_vector_store_name method defines the name of the vector store used.
  6. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

BorgTestGenerator-0.3.10.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

BorgTestGenerator-0.3.10-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file BorgTestGenerator-0.3.10.tar.gz.

File metadata

  • Download URL: BorgTestGenerator-0.3.10.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for BorgTestGenerator-0.3.10.tar.gz
Algorithm Hash digest
SHA256 8cdf50ea73f5e45a969829593ba3c9891643714f3d874e49f3c8162289de2b75
MD5 82d7b789fee194c39724771b29985f4d
BLAKE2b-256 38a1854a43d1f499d7fd76a2414242536f9ed2f4ee8b15ce7c83ec22ad74ea14

See more details on using hashes here.

File details

Details for the file BorgTestGenerator-0.3.10-py3-none-any.whl.

File metadata

File hashes

Hashes for BorgTestGenerator-0.3.10-py3-none-any.whl
Algorithm Hash digest
SHA256 6259dca704ae10f6867e7ca7b5d055326b1486b422f7ba4f27ec771df2d8d156
MD5 f663ca996a7e63ccdf3411bc844fdd2c
BLAKE2b-256 25a71f2bb13c822ff0b6ceeeb1a1a70de9ba7600af12e683464f122834575edf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page