Metadata-Version: 2.4
Name: wsgiref-fake
Version: 1.0.4
Summary: In-process WSGI HTTP and WebSocket test doubles (fake sockets, no listening port).
Project-URL: Homepage, https://github.com/adalekin/wsgiref-fake
Project-URL: Repository, https://github.com/adalekin/wsgiref-fake
Project-URL: Issues, https://github.com/adalekin/wsgiref-fake/issues
Author: Alexey Dalekin
License: MIT
License-File: LICENSE
Keywords: fake,http,testing,websocket,wsgi
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Requires-Dist: six>=1.12.0
Provides-Extra: gevent
Requires-Dist: gevent-websocket==0.9.5; extra == 'gevent'
Requires-Dist: gevent>=1.3.6; extra == 'gevent'
Provides-Extra: ws4py
Requires-Dist: ws4py>=0.5.1; extra == 'ws4py'
Description-Content-Type: text/markdown

# wsgiref-fake

In-process **WSGI** test doubles: fake sockets and a minimal server harness so you can exercise HTTP (and optionally WebSocket) applications **without binding a real port** or talking over the network.

Useful for fast, deterministic tests against code built on `wsgiref` and similar stacks.

## Requirements

- Python 3.10 or newer
- Runtime dependency: [`six`](https://pypi.org/project/six/) (Python 2/3 compatibility helpers used in this library)

## Installation

```bash
pip install wsgiref-fake
```

With [uv](https://docs.astral.sh/uv/):

```bash
uv add wsgiref-fake
```

### Optional extras

| Extra   | Purpose                                      |
| ------- | -------------------------------------------- |
| `gevent` | Gevent-based WebSocket client helpers       |
| `ws4py`  | Integration helpers around `ws4py`        |

```bash
pip install "wsgiref-fake[gevent]"
pip install "wsgiref-fake[ws4py]"
```

## Quick start (HTTP)

Wire your WSGI app to an in-process server, then drive it with `HTTPClient`:

```python
from wsgiref_fake.http.client import HTTPClient
from wsgiref_fake.server import make_server


def app(environ, start_response):
    start_response("200 OK", [("Content-Type", "text/plain")])
    return [b"Hello World"]


server = make_server(app=app)
client = HTTPClient(server=server)

response = client.request(method="GET", path="/")
assert response.status == 200
body = response.read()
```

`HTTPClient.request` accepts `method`, `path`, optional `json` (sets `Content-Type` and body), and optional `headers`.

## Why this exists

- **No listening socket** — tests stay hermetic and parallel-friendly.
- **Same WSGI surface** as production-oriented `wsgiref` servers, without TCP overhead.
- **WebSocket-related helpers** are available when you install the optional dependency groups above.

## Development

Clone the repository, then install the project with dev dependencies:

```bash
uv sync
```

Run the test suite:

```bash
uv run pytest
```

Lint and format the whole tree:

```bash
uv run ruff check .
uv run ruff format .
```

## Contributing

Issues and pull requests are welcome. Please run tests before opening a PR.

- [Issue tracker](https://github.com/adalekin/wsgiref-fake/issues)
- [Source code](https://github.com/adalekin/wsgiref-fake)

## License

This project is licensed under the [MIT License](LICENSE).
