Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanchao2012/gutt
Auto Generate Unit Test Templates
https://github.com/ryanchao2012/gutt
code-generation codegen gutt python testing unit-testing
Last synced: 2 days ago
JSON representation
Auto Generate Unit Test Templates
- Host: GitHub
- URL: https://github.com/ryanchao2012/gutt
- Owner: ryanchao2012
- License: mit
- Created: 2021-03-28T17:49:23.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-03T13:26:50.000Z (11 months ago)
- Last Synced: 2024-11-09T11:49:09.843Z (6 days ago)
- Topics: code-generation, codegen, gutt, python, testing, unit-testing
- Language: Python
- Homepage:
- Size: 118 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![](https://github.com/ryanchao2012/gutt/actions/workflows/gutt-run-unittests.yml/badge.svg)
![](https://img.shields.io/pypi/v/gutt.svg)
![](https://img.shields.io/pypi/pyversions/gutt)
![](https://img.shields.io/github/license/ryanchao2012/gutt)# gutt
Auto Generate Unit Test Templates## Install
```
$ pip install gutt
```## Basic Usage
Assume you have a package, and its layout:
```
my_awesome_package
├── __init__.py
└── module1.py
```some codes inside `my_awesome_package/module1.py`:
```python
import sys
MY_CONST = 123
def funcion1():
passdef function2():
passclass MyObject:
def method1(self):
pass@classmethod
def classmethod1(cls):
pass@staticmethod
def staticmethod1():
pass```
`gutt` can generate unit testing templates for all implementations in just one line:
```
$ gutt -m my_awesome_package -o mytests
```The output layout:
```
mytests
├── __init__.py
└── my_awesome_package
├── __init__.py
└── test_module1.py```
The unit test templates inside `test_module1.py`
```python
def test_funcion1():
from my_awesome_package.module1 import funcion1assert funcion1
def test_function2():
from my_awesome_package.module1 import function2assert function2
class TestMyObject:
@classmethod
def setup_class(cls):
from my_awesome_package.module1 import MyObjectassert MyObject
@classmethod
def teardown_class(cls):
passdef setup_method(self, method):
passdef teardown_method(self, method):
passdef test_method1(self):
passdef test_classmethod1(self):
passdef test_staticmethod1(self):
pass```
Each module in source codes maps to a testing module(`module1.py --> test_module1.py`), and each function, each class and all methods inside that class maps to corresponding test templates.
- `gutt` will skip code generation if the test templates for the functions already exist.
- `gutt` won't delete the corresponding test templates if the source codes get deleted or renamed.
- For new added codes: modules, functions or methods inside class, just re-run `gutt` to generate new test templates for them.Run unit test with `pytest`, for example:
```
$ pytest --doctest-modules --cov=my_awesome_package mytests=============================== test session starts ===============================
platform linux -- Python 3.8.8, pytest-4.6.11, py-1.10.0, pluggy-0.13.1
rootdir: /home/ryan/Workspace/my_awesome_package
plugins: mock-1.13.0, cov-2.11.1
collected 5 itemsmytests/my_awesome_package/test_module1.py ..... [100%]
----------- coverage: platform linux, python 3.8.8-final-0 -----------
Name Stmts Miss Cover
----------------------------------------------------
my_awesome_package/__init__.py 0 0 100%
my_awesome_package/module1.py 13 5 62%
----------------------------------------------------
TOTAL 13 5 62%============================ 5 passed in 0.07 seconds =============================
```