Metadata-Version: 2.4
Name: fixturify
Version: 0.1.9
Summary: A collection of convenient testing utilities for Python
Project-URL: Homepage, https://github.com/eleven-sea/pytools
Project-URL: Repository, https://github.com/eleven-sea/pytools
Project-URL: Issues, https://github.com/eleven-sea/pytools/issues
Author: eleven-sea
License-Expression: MIT
Keywords: fixtures,json,mocking,pytest,sql,testing
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Requires-Dist: deepdiff>=6.0
Description-Content-Type: text/markdown

# pytools

A collection of Python testing utilities.

## Installation

```bash
pip install fixturify
```

## Modules

| Module | Description | Docs |
|--------|-------------|------|
| [sql](docs/sql.md) | Execute SQL files before/after tests | [docs/sql.md](docs/sql.md) |
| [read](docs/read.md) | Inject JSON fixtures into test functions | [docs/read.md](docs/read.md) |
| [http](docs/http.md) | Record and replay HTTP calls | [docs/http.md](docs/http.md) |
| [JsonAssert](docs/json_assert.md) | Compare objects to JSON files | [docs/json_assert.md](docs/json_assert.md) |
| [ObjectMapper](docs/object_mapper.md) | Bidirectional object-JSON mapping | [docs/object_mapper.md](docs/object_mapper.md) |

## Quick examples

### sql

```python
from fixturify import sql, Phase

@sql(path="./setup.sql")
@sql(path="./cleanup.sql", phase=Phase.AFTER)
def test_database():
    # SQL executed before and after test
    pass
```

### read

```python
from fixturify import read

@read.fixture(path="./fixtures/user.json", fixture_name="user", object_class=User)
def test_user(user: User):
    assert user.name == "John"
```

### http

```python
from fixturify import http

@http(path="./fixtures/api.json")
def test_api():
    # First run: records HTTP calls
    # Next runs: replays from file
    response = requests.get("https://api.example.com/users")
    assert response.status_code == 200
```

### JsonAssert

```python
from fixturify import JsonAssert

def test_response():
    data = {"name": "John", "age": 30}
    JsonAssert(data).ignore("age").compare_to_file("./expected.json")
```

### ObjectMapper

```python
from fixturify import ObjectMapper

# Object to JSON
user = User(name="John", age=30)
data = ObjectMapper(user).to_json()

# JSON to object
data = {"name": "John", "age": 30}
user = ObjectMapper(data).to_object(User)
```

## Public API

```python
from fixturify import (
    # Decorators
    sql,
    read,
    http,
    # Enums
    Phase,
    # Config
    SqlTestConfig,
    HttpTestConfig,
    # Classes
    JsonAssert,
    ObjectMapper,
)
```
