AITestGen
Python Library to generate unit tests using OpenAI API
Installation
Create a virtual enviroment (Optional)
python -m venv venv
source venv/bin/activate # venv/Scripts/activate on Windows
Install package (require python ^3.11 version)
pip install aitestgen
Add OpenAI API Key (Required)
export OPENAI_API_KEY=<my_api_key> # or add variable in your .env file
Example
Create a python file and add the following code:
from aitestgen.autotest import autotest
@autotest()
def sum(num1: float, num2: float) -> float:
"""This function is responsible for calculating the sum of two numbers"""
return num1 + num2
@autotest()
def mul(num1: float, num2: float) -> float:
"""This function is responsible for calculating the multiplication of two numbers"""
return num1 * num2
Important:
To improve results, add type annotations and documentation to the function.
Generate tests:
Run the following command (change the filename)
aitestgen generate --inputfile src/operations.py
And then you will get the following result in a .py file created in a tests folder:
Result
# Function: mul - test1:
def test_mul_positive_numbers():
assert mul(5.5, 2) == 11.0
# Function: mul - test2:
def test_mul_negative_numbers():
assert mul(-3, 4) == -12.0
# Function: mul - test3:
def test_mul_zero():
assert mul(0, 10) == 0.0
# Function: sum - test1:
def test_sum_positive_numbers():
assert sum(3.5, 2.5) == 6.0
# Function: sum - test2:
def test_sum_negative_numbers():
assert sum(-3.5, -2.5) == -6.0
# Function: sum - test3:
def test_sum_mixed_numbers():
assert sum(3.5, -2.5) == 1.0
Metadata
Release files for aitestgen 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aitestgen-0.0.2.tar.gz | 3.3 kB | Without provenance | Details for aitestgen-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aitestgen-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for aitestgen-0.0.2-py3-none-any.whl |
Total release size: 8.1 kB
Release files / aitestgen-0.0.2.tar.gz
| Download URL | aitestgen-0.0.2.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1fa4ebf5200cf0233cbe34d8e1ad717e0d20f621f8d58bc8dcfed0d361f3314
|
|
BLAKE2b-256 checksum How to use checksums |
12412ae8085435e22e8d35b682774f1c46589af8ae05eca71760880d310814f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.6 Linux/6.5.0-10-generic
|
Release files / aitestgen-0.0.2-py3-none-any.whl
| Download URL | aitestgen-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4fa3c96f37485c1277322f0c40517cc0292eba7dfce63d51c7f6e394980f6459
|
|
BLAKE2b-256 checksum How to use checksums |
0e06a28e2f82f4a4523ff812581b162f9f01a6112fd911bc5416e4117a29f42f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.6 Linux/6.5.0-10-generic
|
Security for aitestgen 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.