Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/richecr/deflector
Deflector is a minimalist Python testing library that streamlines test creation with clear, intuitive syntax, enabling fast and efficient testing.
https://github.com/richecr/deflector
Last synced: about 4 hours ago
JSON representation
Deflector is a minimalist Python testing library that streamlines test creation with clear, intuitive syntax, enabling fast and efficient testing.
- Host: GitHub
- URL: https://github.com/richecr/deflector
- Owner: richecr
- License: mit
- Created: 2024-08-12T02:48:57.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-14T01:01:31.000Z (2 months ago)
- Last Synced: 2024-09-15T14:15:53.476Z (2 months ago)
- Language: Python
- Homepage:
- Size: 227 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deflector
---
π [Documentation - Under Construction]() ΒΊ [Pypi](https://pypi.org/project/deflector/)
---
## Why does Deflector exist?
π‘ **Deflector** is a minimalist testing library for Python designed to simplify test writing with a clear and intuitive syntax, allowing developers to create and run tests quickly and efficiently without unnecessary complications.
High **isolation** level per file
**Performant** and **lightweight**
**Fully typed** library---
## Quickstart
### Install
```zsh
$ pip install deflector
```Or with [poetry](https://python-poetry.org/docs/)
```zsh
poetry add deflector -G dev
```---
### Test
tests/test_file1.py```py
from deflector import affirmaffirm.equal(1, 1, "My first test with deflector")
```---
### Run
```bash
deflector # or poetry run deflector
```Or defining the directory where the tests are:
```bash
deflector --dir tests
```---
## Features
### Main
| Function | Description |
|--------------------------------------------------------|-------------------------------------------|
| [affirm](#affirm) | π Test assertion. |
| [it](#it) | π€Ήπ»ββοΈ Isolate tests. |
| [describe](#describe) | π€Ήπ»ββοΈ Grouping tests. |
| [before_each β’ after_each](#before-each--after-each) | π Functions for test setup and teardown. |#### Affirm
The `affirm` is used to create tests that validate whether the behavior of your code is as expected, checking the correspondence between values ββand triggering errors if there are discrepancies.
```python
from deflector import affirm
```| Function | Description |
|--------------------------------------------|----------------------------------------------|
| [ok](#ok) | Checks if a value is truthy. |
| [equal](#equals) | Compares if two values are equal. |
| [not_equal](#not-equals) | Verifies if two values are different. |
| [match_re](#match-regex) | Checks if a string matches a regex. |
| [does_not_match_re](#does-not-match-regex) | Verifies if a string does not match a regex. |##### Ok
```python
affirm.ok(value, message)
``````python
affirm.ok(True, "Ok")
```##### Equals
```python
affirm.equal(value, expected, message)
``````python
affirm.equal(1 + 2, 3, "Equal: Sum 1+2=3")
```##### Not Equals
```python
affirm.not_equal(value, expected, message)
``````python
affirm.not_equal(1 + 2, 4, "Not Equal: Sum 1+2!=4")
```##### Match Regex
```python
affirm.match_re(value, reg_exp, message)
``````python
affirm.match_re("acab", "ab", "Match Regex: ab in acab")
```##### Does Not Match Regex
```python
affirm.does_not_match_re(value, reg_exp, message)
``````python
affirm.does_not_match_re("ab", "abc", "Does Not Match Regex: ab not in a")
```#### It
```python
from deflector import affirm, it@it("It Test 1")
def test_1() -> None:
affirm.ok(True, "Ok")
affirm.equal(1 + 1, 2, "Equal")
affirm.not_equal(1 + 2, 1, "Not Equal")
affirm.match_re("acab", "ab", "Match Re")
affirm.does_not_match_re("a", "ab", "Does Not Match Re")
```#### Describe
```python
from deflector import affirm, describe, it@describe("Main 1")
def describe_main() -> None:
@it("It Test 1")
def test1() -> None:
affirm.equal(1 + 1, 2, "Equal 1+1=2")@it("It Test 2")
def test2() -> None:
affirm.match_re("acab", "ab", "Match Re")
```#### Before Each β’ After Each
```python
from deflector import affirm, describe, it@describe("Main 1")
def describe_main() -> None:
x = 1@before_each()
async def start() -> bool:
nonlocal x
await asyncio.sleep(1)
x += 1
return True@after_each()
async def end_() -> bool:
nonlocal x
await asyncio.sleep(1)
x = 1
return True@it("It Test 1")
def test1() -> None:
affirm.equal(x, 2, "Equal Before Each")
affirm.equal(1 + 1, 2, "Equal 1")
affirm.equal(1 + 1, 2, "Equal 2")@it("It Test 2")
def test2() -> None:
affirm.equal(x, 2, "Equal After Each")
affirm.equal(1 + 1, 2, "Equal")
affirm.not_equal(1 + 1, 1, "Not Equal")
affirm.ok(True, "Ok")
affirm.match_re("acab", "ab", "Match Re")
affirm.does_not_match_re("a", "ab", "Does Not Match Re")
```