{ "info": { "author": "Ryan Northey", "author_email": "ryan@3ca.org.uk", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Detailed documentation\n**********************\n\naio.testing\n===========\n\nTest utils for the aio_ asyncio framework\n\n.. _aio: https://github.com/phlax/aio\n\n\nBuild status\n------------\n\n.. image:: https://travis-ci.org/phlax/aio.testing.svg?branch=master\n\t :target: https://travis-ci.org/phlax/aio.testing\n\n\nInstallation\n------------\n\nRequires python >= 3.4\n\nInstall with:\n\n.. code:: bash\n\n\t pip install aio.testing\n\n\nAio testing provides 2 decorators for running asyncio tests\n\n- *aio.testing.run_until_complete*:\n\n - creates a test loop\n - calls the test with loop.run_until_complete\n\n- *aio.testing.run_forever*:\n \n - creates a test loop\n - calls test using loop.run_forever\n - waits for number of seconds specified in \"timeout\" (default = 1)\n - if test returns a callable, calls it as a coroutine\n - waits for number of seconds specified in \"sleep\" (default = 0)\n\n\t \n\n@aio.testing.run_until_complete\n-------------------------------\n\naio.testing provides a method decorator for running asyncio-based tests\n\n.. code:: python\n\n\t import unittest\n\t import asyncio\n\n\t import aio.testing\n\n\n\t class MyTestCase(unittest.TestCase):\n\n\t @aio.testing.run_until_complete\n\t def test_example():\n\t yield from asyncio.sleep(2)\n\t\t self.assertTrue(True)\n\n\t\t \nPrior to the test running asyncio.get_new_loop() is called and set using asyncio.set_event_loop().\n\nOn completion of the test asyncio.set_event_loop() is again called with the original event loop.\n\n\n@aio.testing.run_forever\n------------------------\n\nIf your code needs to test long-running tasks, you can use the @aio.testing.run_forever decorator.\n\nThe @aio.testing.run_forever decorator uses loop.run_forever to run the test.\n\nAny setup required can be done in the body of the test function which can optionally return a test callback\n\nThe callback is wrapped in a coroutine, and called after 1 second\n\n.. code:: python\n\n\t import unittest\n\t import asyncio\n\n\t import aio.testing\n\n\n\t class MyFutureTestCase(unittest.TestCase):\n\n\t @aio.testing.run_forever\n\t def test_example():\n\t yield from asyncio.sleep(2)\n\n\t\t def callback_test(self):\n\t\t yield from asyncio.sleep(2)\t\t \n\t\t self.assertTrue(True)\n\n\t\t # this function is called 1 second after being returned\t\t \n\t\t return callback_test\n\n\nAs with aio.testing.run_until_complete, the test is run in a separate loop.\n\n\t\t \n@aio.testing.run_forever with timeout\n-------------------------------------\n\nYou can specify how many seconds to wait *before* running the callback tests by setting the timeout value\n\n\n.. code:: python\n\n\t import unittest\n\t import asyncio\n\n\t import aio.testing\n\n\n\t class MyFutureTestCase(unittest.TestCase):\n\n\t @aio.testing.run_forever(timeout=10)\n\t def test_example():\n\t yield from asyncio.sleep(2)\n\n\t\t def callback_test(self):\n\t\t yield from asyncio.sleep(2)\t\t \n\t\t self.assertTrue(True)\n\n\t\t # this function is called 10 seconds after being returned\t\t \n\t\t return callback_test\n\n\n@aio.testing.run_forever with sleep\n-----------------------------------\n\nSometimes a test needs to wait for some time after services have been stopped and the test loop has been destroyed.\n\nYou can specify how many seconds to wait *after* running the callback tests by setting the sleep value\n\n\n.. code:: python\n\n\t import unittest\n\t import asyncio\n\n\t import aio.testing\n\n\n\t class MyFutureTestCase(unittest.TestCase):\n\n\t @aio.testing.run_forever(sleep=10)\n\t def test_example():\n\t yield from asyncio.sleep(2)\n\n\t\t def callback_test(self):\n\t\t yield from asyncio.sleep(2)\t\t \n\t\t self.assertTrue(True)\n\n\t\t return callback_test\n\t\t \n\n\naio.testing usage\n=================\n\n\naio.testing.run_until_complete\n------------------------------\n\nLets create a test\n\n>>> import asyncio\n>>> import aio.testing\n\n>>> @aio.testing.run_until_complete\n... def run_test(parent_loop):\n... yield from asyncio.sleep(1)\n... \n... print(asyncio.get_event_loop() != parent_loop)\n\nAnd lets check that the test loop is not the same as the current one\n\n>>> loop_before_test = asyncio.get_event_loop()\n>>> run_test(loop_before_test)\nTrue\n\nAfter the test has run we have the original event loop back\n\n>>> asyncio.get_event_loop() == loop_before_test\nTrue\n\nWe can raise an error in the test\n\n>>> @aio.testing.run_until_complete\n... def run_test():\n... assert(True == False)\n\n>>> try:\n... run_test()\n... except Exception as e:\n... print(repr(e))\nAssertionError()\n\n \naio.testing.run_forever\n-----------------------\n\nLets create a future test\n\n>>> import asyncio\n\n>>> @aio.testing.run_forever\n... def run_test(parent_loop):\n... yield from asyncio.sleep(1)\n... \n... print(asyncio.get_event_loop() != parent_loop)\n\nJust like with aio.testing.run_until_complete, the test is run in a separate loop\n\n>>> loop_before_test = asyncio.get_event_loop() \n>>> run_test(loop_before_test)\nTrue\n\nAnd again, after the test has run we have the original event loop back\n\n>>> asyncio.get_event_loop() == loop_before_test\nTrue\n \nIf the test returns a callable, its called 1 second later.\n\nThe test_callback runs in the same loop as the test\n \n>>> @aio.testing.run_forever\n... def run_test():\n... test_loop = asyncio.get_event_loop()\n... \n... @asyncio.coroutine\n... def test_callback():\n... print(\n... asyncio.get_event_loop() == test_loop)\n... \n... return test_callback\n \n>>> run_test()\nTrue\n\nThe test_callback is always wrapped in asyncio.coroutine if its not one already\n\n>>> @aio.testing.run_forever\n... def run_test():\n... \n... def test_callback():\n... yield from asyncio.sleep(1)\n... print(\"test_callback is always wrapped in a coroutine!\")\n... \n... return test_callback\n \n>>> run_test()\ntest_callback is always wrapped in a coroutine!\n\n\nWe can raise an error in the test\n\n>>> @aio.testing.run_forever\n... def run_test():\n... assert(True == False)\n\n>>> try:\n... run_test()\n... except Exception as e:\n... print(repr(e))\nAssertionError()\n\nAnd we can raise an error in the test callback\n\n>>> @aio.testing.run_forever\n... def run_test():\n... \n... def test_callback():\n... assert(True == False)\n... \n... return test_callback\n \n>>> try:\n... run_test()\n... except Exception as e:\n... print(repr(e))\nAssertionError()\n\nBy default the test_callback is called 1 second after being returned\n\n>>> import time\n\n>>> @aio.testing.run_forever\n... def run_test():\n... test_run_at = int(time.time())\n... \n... return lambda: (\n... print(\"callback called %s second(s) after test\" % (\n... int(time.time()) - test_run_at)))\n \n>>> run_test()\ncallback called 1 second(s) after test\n\nYou can set the amount of time to wait before calling the test_callback by setting the \"timeout\" argument in the decorator\n\n>>> import time\n\n>>> @aio.testing.run_forever(timeout=3)\n... def run_test():\n... test_run_at = int(time.time())\n... \n... return lambda: print(\n... \"callback called %s second(s) after test\" % (\n... int(time.time()) - test_run_at))\n \n>>> run_test()\ncallback called 3 second(s) after test\n \nYou can also set the amount of time to wait after the test has completely finished, by setting the \"sleep\" argument on the decorator\n\n>>> @aio.testing.run_forever(sleep=3)\n... def run_test(test_time):\n... return lambda: (\n... test_time.__setitem__('completed_at', int(time.time())))\n\n>>> test_time = {}\n>>> run_test(test_time)\n \n>>> print(\"test waited %s second(s) after completing\" % (\n... int(time.time()) - test_time['completed_at']))\ntest waited 3 second(s) after completing", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/phlax/aio.testing", "keywords": "", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "aio.testing", "package_url": "https://pypi.org/project/aio.testing/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/aio.testing/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/phlax/aio.testing" }, "release_url": "https://pypi.org/project/aio.testing/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Testing utils for aio asyncio framework", "version": "0.1.0" }, "last_serial": 1560689, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "81542ddc1953c0319ad760b98bbb90bd", "sha256": "37e11741998b4dbc7f6bbeb6078aa770b2530f68cddbeb63505d9d9af609e0bf" }, "downloads": -1, "filename": "aio.testing-0.0.1.tar.gz", "has_sig": false, "md5_digest": "81542ddc1953c0319ad760b98bbb90bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3907, "upload_time": "2015-05-17T15:46:59", "url": "https://files.pythonhosted.org/packages/73/06/99f1ab3d0e7cbf5f557bfc9a8e78c8fffea9ba7ebd4b41c2d4a1701cb84c/aio.testing-0.0.1.tar.gz" } ], "0.0.10": [ { "comment_text": "", "digests": { "md5": "88235a34c78995a921444e3c51a5338f", "sha256": "69f5e1c09d7e95c63379e7a7784fdb2a582175a00a68d167bdcdb4f1dcdb57d7" }, "downloads": -1, "filename": "aio.testing-0.0.10.tar.gz", "has_sig": false, "md5_digest": "88235a34c78995a921444e3c51a5338f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5161, "upload_time": "2015-05-23T22:06:13", "url": "https://files.pythonhosted.org/packages/7d/ff/d4c01255f6a7bebf2a74acda9548244715f555ac402227348118ad963b90/aio.testing-0.0.10.tar.gz" } ], "0.0.11": [ { "comment_text": "", "digests": { "md5": "a468c478916bbf93a654010df0007c6b", "sha256": "c5f20a19ce644bae0bf14978096e383b30417d798cec66bc2b2ab94922c2a34d" }, "downloads": -1, "filename": "aio.testing-0.0.11.tar.gz", "has_sig": false, "md5_digest": "a468c478916bbf93a654010df0007c6b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5158, "upload_time": "2015-05-23T22:39:19", "url": "https://files.pythonhosted.org/packages/db/66/5a85552bc05972f28e5ca251ce06bfe75d7d0ddf6f47a1b2559d5c7d940c/aio.testing-0.0.11.tar.gz" } ], "0.0.12": [ { "comment_text": "", "digests": { "md5": "5304a70988b24ed1d54c1d43e5916a28", "sha256": "87acc27f7517810ceddd0b2a34675a6c4f4b73adf4115abe9ab617f18b40a06c" }, "downloads": -1, "filename": "aio.testing-0.0.12.tar.gz", "has_sig": false, "md5_digest": "5304a70988b24ed1d54c1d43e5916a28", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5166, "upload_time": "2015-05-24T13:54:10", "url": "https://files.pythonhosted.org/packages/60/99/8c235331e5f4d9c685ddc0875c04da4ae0ff37426bb8b4bcd4827491ddd5/aio.testing-0.0.12.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "8928f5172a31f97ed08d4b2cdb55fb85", "sha256": "73f6867a05c288daab29aecbc060122e39b28c8eca9f264d2d0f709255c96ea0" }, "downloads": -1, "filename": "aio.testing-0.0.2.tar.gz", "has_sig": false, "md5_digest": "8928f5172a31f97ed08d4b2cdb55fb85", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4016, "upload_time": "2015-05-18T12:13:11", "url": "https://files.pythonhosted.org/packages/39/25/a9f481f6a67bf081e20c794dc7a45b95fe23979605a2081646ec78f3a634/aio.testing-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "1e9b0461fe8d57b523e002c11a35cf5b", "sha256": "238a1523460f9a1f65f69d1bf56699d88fedff4f5ca845c410162834445987f3" }, "downloads": -1, "filename": "aio.testing-0.0.3.tar.gz", "has_sig": false, "md5_digest": "1e9b0461fe8d57b523e002c11a35cf5b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5124, "upload_time": "2015-05-23T13:51:27", "url": "https://files.pythonhosted.org/packages/05/5b/130a312888cc7869e9eb08050ebc8aee8220b9e0640f39e1b4e61dd80de9/aio.testing-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "60ec6db09b945ea09cddeff82fc01944", "sha256": "7fec16daeae607efeab715dcae074c0e0d5c80722b9a1ed96a65995d9c8ed910" }, "downloads": -1, "filename": "aio.testing-0.0.4.tar.gz", "has_sig": false, "md5_digest": "60ec6db09b945ea09cddeff82fc01944", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5050, "upload_time": "2015-05-23T15:43:27", "url": "https://files.pythonhosted.org/packages/b6/af/bea30013c6373a64d4d2ab82888f7f22de0fe8169226a3b419c42c46776b/aio.testing-0.0.4.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "7e0eda5083f861805de60d7e7203aa81", "sha256": "6684f2e46045373c1a88fdb3ce9961eccb6716aecd5d55384ba82b0dc03b78f4" }, "downloads": -1, "filename": "aio.testing-0.0.6.tar.gz", "has_sig": false, "md5_digest": "7e0eda5083f861805de60d7e7203aa81", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5116, "upload_time": "2015-05-23T20:41:42", "url": "https://files.pythonhosted.org/packages/21/ff/615e5a2f0776f28c5b02c823b22e4e8245370779a9eea20f10b440fc59d6/aio.testing-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "f905209396dadad3af166fb38fe31f7a", "sha256": "03c3528dfb5fd5ea8a53054ec592a960ea223c59689ae0259aa571c2923dc331" }, "downloads": -1, "filename": "aio.testing-0.0.7.tar.gz", "has_sig": false, "md5_digest": "f905209396dadad3af166fb38fe31f7a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5117, "upload_time": "2015-05-23T20:57:50", "url": "https://files.pythonhosted.org/packages/9a/5b/9d895ded5417a3f9c0d4e4c6d3bfe2b031c8f29d629a31436569d01e5863/aio.testing-0.0.7.tar.gz" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "5cd7fb4b5bf139d06c26a95332e5eec7", "sha256": "d73f83756a60634e96130062ecd8ee50a7e6706ad7d584462b297d01bb48e014" }, "downloads": -1, "filename": "aio.testing-0.0.8.tar.gz", "has_sig": false, "md5_digest": "5cd7fb4b5bf139d06c26a95332e5eec7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5167, "upload_time": "2015-05-23T22:02:48", "url": "https://files.pythonhosted.org/packages/5a/6a/bff8a4805d63ee5e10efeca003abc09607b7b27c2de40e9d375cdbfd45ad/aio.testing-0.0.8.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "6b6771a65caf191f31dc51acdc3b5b21", "sha256": "2844d8f5db977229b181041e5c02723802b60fcf3b29b4788fa1c81ed0ae13a8" }, "downloads": -1, "filename": "aio.testing-0.0.9.tar.gz", "has_sig": false, "md5_digest": "6b6771a65caf191f31dc51acdc3b5b21", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5170, "upload_time": "2015-05-23T22:04:19", "url": "https://files.pythonhosted.org/packages/4c/d2/c66018e122792fefaa5d78457b873ec8d5a00c80814013dc94368b4186c0/aio.testing-0.0.9.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "aca317660b3346753ab3ae62fbc511b7", "sha256": "a2d70bde99496df5cb68c596a15acc9e6656413d434b9c965d699480e882d9c6" }, "downloads": -1, "filename": "aio.testing-0.1.0.tar.gz", "has_sig": false, "md5_digest": "aca317660b3346753ab3ae62fbc511b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5162, "upload_time": "2015-05-24T21:36:57", "url": "https://files.pythonhosted.org/packages/ba/63/8918c82791993b179355fd5dda5e4a926e49484bda65b2788379e40279f6/aio.testing-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "aca317660b3346753ab3ae62fbc511b7", "sha256": "a2d70bde99496df5cb68c596a15acc9e6656413d434b9c965d699480e882d9c6" }, "downloads": -1, "filename": "aio.testing-0.1.0.tar.gz", "has_sig": false, "md5_digest": "aca317660b3346753ab3ae62fbc511b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5162, "upload_time": "2015-05-24T21:36:57", "url": "https://files.pythonhosted.org/packages/ba/63/8918c82791993b179355fd5dda5e4a926e49484bda65b2788379e40279f6/aio.testing-0.1.0.tar.gz" } ] }