asyncio-time-travel


Nameasyncio-time-travel JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/realcr/asyncio_time_travel
SummaryAsyncio Time Travel Loop
upload_time2023-01-30 13:11:47
maintainer
docs_urlNone
authorreal
requires_python
licenseApache 2.0
keywords asyncio testing time travel sleep
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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()

async def inner_coro():
    # Sleep for a long time:
    await asyncio.sleep(SLEEP_TIME, loop=tloop)

tloop.run_until_complete(inner_coro())
```

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 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
pytest
```

If you haven't yet heard of [pytest](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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/realcr/asyncio_time_travel",
    "name": "asyncio-time-travel",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "asyncio testing time travel sleep",
    "author": "real",
    "author_email": "realcr@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/64/72/facd0556495b46c5f4e05a629de0db5c9340d0dca882294ef23fb68fab79/asyncio_time_travel-0.3.0.tar.gz",
    "platform": null,
    "description": "Asyncio Time Travel Loop\n========================\n\nIntro\n-----\n\nAsyncio Time Travel Loop allows you to test asyncio code that waits or sleeps,\nwithout actually waiting or sleeping.\n\nAt the same time, you don't have to bother thinking about how the time\nadvances. Your code should work exactly the same with TimeTravelLoop as it works\nwith a normal asyncio events loop.\n\nExample: Assume that you have a code that waits 1000 seconds, and you want to\ntests that code. Instead of actually waiting 1000 seconds, you could use\nTimeTravelLoop:\n\n```python\nimport asyncio\nfrom asyncio_time_travel import TimeTravelLoop\n\nSLEEP_TIME = 1000\n\ntloop = TimeTravelLoop()\n\nasync def inner_coro():\n    # Sleep for a long time:\n    await asyncio.sleep(SLEEP_TIME, loop=tloop)\n\ntloop.run_until_complete(inner_coro())\n```\n\nThis code completes immediately.\n\nSee 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.\n\nInstallation\n------------\nRun:\n```bash\npip install asyncio-time-travel\n```\nYou can also find the package at https://pypi.python.org/pypi/asyncio-time-travel .\n\nTests\n-----\n\nRun (Inside asyncio_time_travel dir):\n```bash\npytest\n```\n\nIf you haven't yet heard of [pytest](http://pytest.org), it's your lucky day :)\n\n\nHow does this work?\n-------------------\n\nTimeTravelLoop source is based on the source code of\nasyncio.test_utils.TestLoop.\n\nFor each _run_once iteration of the loop, the following is done:\n- Loop events are executed.\n- Time is advanced to the closest scheduled event.\n\nUsing this method your code never waits, and at the same time the events\nexecute in the correct order.\n\n\nLimitations\n-----------\n\nTimeTravelLoop is meant to be used with your tests, not for production code. In\nparticular, if your loop interacts with external events, bending time is not a\ngood idea (Time will advance differently outside of your loop).\n\n\nFurther work\n------------\n\n- The code might have bugs. If you find any issues, don't hesitate to fork or\nopen an issue. \n\n- It might be possible to integrate this code into asyncio.test_utils in some\n  way.\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "Asyncio Time Travel Loop",
    "version": "0.3.0",
    "split_keywords": [
        "asyncio",
        "testing",
        "time",
        "travel",
        "sleep"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d51d06a394b82bae2b8e16b7d4b62d440a515e9dfce4f34899efb8fd57894a76",
                "md5": "7019c9999a3ae479e883513c04e6cd3c",
                "sha256": "2837e001f23ae0c6106794e0c21ea7e29e2d014143af66fd8376b97fc7d14a22"
            },
            "downloads": -1,
            "filename": "asyncio_time_travel-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7019c9999a3ae479e883513c04e6cd3c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8669,
            "upload_time": "2023-01-30T13:11:46",
            "upload_time_iso_8601": "2023-01-30T13:11:46.190093Z",
            "url": "https://files.pythonhosted.org/packages/d5/1d/06a394b82bae2b8e16b7d4b62d440a515e9dfce4f34899efb8fd57894a76/asyncio_time_travel-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6472facd0556495b46c5f4e05a629de0db5c9340d0dca882294ef23fb68fab79",
                "md5": "32d24142efca218e84e0f518588de3d5",
                "sha256": "5989b38b34046e872acf960698295b0b50530d55af861aaf25fce296496f9e23"
            },
            "downloads": -1,
            "filename": "asyncio_time_travel-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "32d24142efca218e84e0f518588de3d5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8328,
            "upload_time": "2023-01-30T13:11:47",
            "upload_time_iso_8601": "2023-01-30T13:11:47.333741Z",
            "url": "https://files.pythonhosted.org/packages/64/72/facd0556495b46c5f4e05a629de0db5c9340d0dca882294ef23fb68fab79/asyncio_time_travel-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-30 13:11:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "realcr",
    "github_project": "asyncio_time_travel",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "asyncio-time-travel"
}
        
Elapsed time: 0.03925s