Asyncio Time Travel Loop
Project description
Asyncio Time Travel Loop
========================
Intro
-----
Asyncio Time Travel Loop allows you to test asyncio code that waits or sleeps,
without actually waiting or sleeping.
At the same time, you don't have to bother thinking about how the time
advances. Your code should work exactly the same with TimeTravelLoop as it works
with a normal asyncio events loop.
Example: Assume that you have a code that waits 1000 seconds, and you want to
tests that code. Instead of actually waiting 1000 seconds, you could use
TimeTravelLoop:
```python
import asyncio
from asyncio_time_travel import TimeTravelLoop
SLEEP_TIME = 1000
tloop = TimeTravelLoop()
@asyncio.coroutine
def inner_cor():
# Sleep for a long time:
yield from asyncio.sleep(SLEEP_TIME,loop=tloop)
tloop.run_until_complete(inner_cor())
```
This code completes immediately.
See some of the [tests](https://github.com/realcr/asyncio_time_travel/blob/master/asyncio_time_travel/tests/test_time_travel_loop.py) for more advanced examples of what TimeTravelLoop can do.
Installation
------------
Run:
```bash
pip install --pre asyncio-time-travel
```
You can also find the package at https://pypi.python.org/pypi/asyncio-time-travel .
Tests
-----
Run (Inside asyncio_time_travel dir):
```bash
py.test
```
If you haven't yet heard of [py.test](http://pytest.org), it's your lucky day :)
How does this work?
-------------------
TimeTravelLoop source is based on the source code of
asyncio.test_utils.TestLoop.
For each _run_once iteration of the loop, the following is done:
- Loop events are executed.
- Time is advanced to the closest scheduled event.
Using this method your code never waits, and at the same time the events
execute in the correct order.
Limitations
-----------
TimeTravelLoop is meant to be used with your tests, not for production code. In
particular, if your loop interacts with external events, bending time is not a
good idea (Time will advance differently outside of your loop).
Further work
------------
- The code might have bugs. If you find any issues, don't hesitate to fork or
open an issue.
- It might be possible to integrate this code into asyncio.test_utils in some
way.
========================
Intro
-----
Asyncio Time Travel Loop allows you to test asyncio code that waits or sleeps,
without actually waiting or sleeping.
At the same time, you don't have to bother thinking about how the time
advances. Your code should work exactly the same with TimeTravelLoop as it works
with a normal asyncio events loop.
Example: Assume that you have a code that waits 1000 seconds, and you want to
tests that code. Instead of actually waiting 1000 seconds, you could use
TimeTravelLoop:
```python
import asyncio
from asyncio_time_travel import TimeTravelLoop
SLEEP_TIME = 1000
tloop = TimeTravelLoop()
@asyncio.coroutine
def inner_cor():
# Sleep for a long time:
yield from asyncio.sleep(SLEEP_TIME,loop=tloop)
tloop.run_until_complete(inner_cor())
```
This code completes immediately.
See some of the [tests](https://github.com/realcr/asyncio_time_travel/blob/master/asyncio_time_travel/tests/test_time_travel_loop.py) for more advanced examples of what TimeTravelLoop can do.
Installation
------------
Run:
```bash
pip install --pre asyncio-time-travel
```
You can also find the package at https://pypi.python.org/pypi/asyncio-time-travel .
Tests
-----
Run (Inside asyncio_time_travel dir):
```bash
py.test
```
If you haven't yet heard of [py.test](http://pytest.org), it's your lucky day :)
How does this work?
-------------------
TimeTravelLoop source is based on the source code of
asyncio.test_utils.TestLoop.
For each _run_once iteration of the loop, the following is done:
- Loop events are executed.
- Time is advanced to the closest scheduled event.
Using this method your code never waits, and at the same time the events
execute in the correct order.
Limitations
-----------
TimeTravelLoop is meant to be used with your tests, not for production code. In
particular, if your loop interacts with external events, bending time is not a
good idea (Time will advance differently outside of your loop).
Further work
------------
- The code might have bugs. If you find any issues, don't hesitate to fork or
open an issue.
- It might be possible to integrate this code into asyncio.test_utils in some
way.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for asyncio_time_travel-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7af7bf71d9b0200a2f639939d5c248088b7ac002d3f2287c179a8b689166a1ad |
|
MD5 | 741417e6a40661b95d325e815c74d3ce |
|
BLAKE2b-256 | cbba224eb6847f93093932a1c0080047567f6d907a9a252012fc9098e2bb888b |