.. image:: https://img.shields.io/pypi/v/asynctest.svg
:target: https://pypi.python.org/pypi/asynctest
:alt: PyPI
.. image:: https://travis-ci.org/Martiusweb/asynctest.svg?branch=master
:target: https://travis-ci.org/Martiusweb/asynctest
:alt: Travis
.. image:: https://ci.appveyor.com/api/projects/status/github/Martiusweb/asynctest?branch=master&svg=true
:target: https://ci.appveyor.com/project/Martiusweb/asynctest/branch/master
:alt: AppVeyor
.. image:: https://img.shields.io/pypi/pyversions/asynctest.svg
:target: https://github.com/Martiusweb/asynctest
:alt: Supported Python versions
=========
asynctest
=========
The package asynctest is built on top of the standard unittest module and
cuts down boilerplate code when testing libraries for asyncio.
Currently, asynctest targets the "selector" model, hence, some features
will not (yet?) work with Windows' proactor.
.. warning::
Since asynctest 0.13, Python 3.4 is not supported anymore.
Author & license
----------------
Authored by Martin Richard <martius@martiusweb.net> and licensed under the
Apache 2 license.
See the AUTHORS file for a comprehensive list of the authors.
Documentation
-------------
.. image:: https://readthedocs.org/projects/asynctest/badge/
:target: http://asynctest.readthedocs.org/en/latest/
Full documentation is available at http://asynctest.readthedocs.org/en/latest/.
It includes a tutorial with tested examples of how to use ``TestCase`` or
mocks.
Features
--------
TestCases
~~~~~~~~~
- Initialize and close a loop created for each test (it can be
configurated), if the loop uses a selector, it will be updated with
a TestSelector object wrapping the original selector (see below),
- if the test function is a coroutine function or returns a coroutine, it
will run on the loop,
- TestCase.setUp() and TestCase.tearDown() can be coroutine functions,
- control post-test checks with `@fail_on`, for instance, the test fail if
the loop didn't run, some optional checks can be activated,
- ClockedTestCase allows to control the loop clock and run timed events
without waiting the wall clock.
Mock and CoroutineMock
~~~~~~~~~~~~~~~~~~~~~~
- CoroutineMock is a new Mock class which mocks a coroutine function, and
returns a coroutine when called,
- MagicMock supports asynchronous context managers and asynchronous
iterators,
- NonCallableMock, Mock and CoroutineMock can return CoroutineMock objects
when its attributes are get if there is a matching attribute in the spec
(or spec_set) object which is a coroutine function,
- patch(), patch.object(), patch.multiple() return a MagickMock or
CoroutineMock object by default, according to the patched target,
- patch(), patch.object(), patch.multiple() handle generators and coroutines
and their behavior can be controled when the generator or coroutine pauses,
- all the patch() methods can decorate coroutine functions,
- mock_open() returns a MagickMock object by default.
- return_once() can be used with Mock.side_effect to return a value only
once when a mock is called.
Selectors
~~~~~~~~~
The module asynctest.selector provides classes to mock objects performing IO
(files, sockets, etc).
- FileMock is a special type of mock which represents a file.
FileMock.fileno() returns a special value which allows to identify uniquely
the mock,
- SocketMock is a special type of FileMock which uses socket.socket as spec,
- TestSelector is a custom selector able to wrap a real selector
implementation and deal with FileMock objects, it can replace a selector
loop by calling `loop._selector = TestSelector(loop._selector)`, and will
intercept mock so they don't get registered to the actual selector.
- set_read_ready() and set_write_ready() to force read and write event
callbacks to be scheduled on the loop, as if the selector scheduled them.
Helpers
~~~~~~~
- the coroutine exhaust_callbacks(loop) returns once all the callbacks which
should be called immediately are executed, which is useful when the test
author needs to assert things which are not yet executed by the loop.
Roadmap
-------
I hope I will find time to develop and release the following features:
- set of warnings against common mistakes
- proactor support
Tests
-----
asynctest is unit tested. You can run asynctest test suite with this command::
$ PYTHONPATH=. python -m unittest test
Raw data
{
"_id": null,
"home_page": "https://github.com/Martiusweb/asynctest/",
"name": "asynctest",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "unittest,test,testing,asyncio,tulip,selectors,async,mock",
"author": "Martin Richard",
"author_email": "martius@martiusweb.net",
"download_url": "https://files.pythonhosted.org/packages/0c/0f/6056f4435923d2f8c89ac9ef2d18506a569348d8f9cc827b0dd7a4c8acc4/asynctest-0.13.0.tar.gz",
"platform": "",
"description": ".. image:: https://img.shields.io/pypi/v/asynctest.svg\n :target: https://pypi.python.org/pypi/asynctest\n :alt: PyPI\n.. image:: https://travis-ci.org/Martiusweb/asynctest.svg?branch=master\n :target: https://travis-ci.org/Martiusweb/asynctest\n :alt: Travis\n.. image:: https://ci.appveyor.com/api/projects/status/github/Martiusweb/asynctest?branch=master&svg=true\n :target: https://ci.appveyor.com/project/Martiusweb/asynctest/branch/master\n :alt: AppVeyor\n.. image:: https://img.shields.io/pypi/pyversions/asynctest.svg\n :target: https://github.com/Martiusweb/asynctest\n :alt: Supported Python versions\n\n=========\nasynctest\n=========\n\nThe package asynctest is built on top of the standard unittest module and\ncuts down boilerplate code when testing libraries for asyncio.\n\nCurrently, asynctest targets the \"selector\" model, hence, some features\nwill not (yet?) work with Windows' proactor.\n\n.. warning::\n\n Since asynctest 0.13, Python 3.4 is not supported anymore.\n\nAuthor & license\n----------------\n\nAuthored by Martin Richard <martius@martiusweb.net> and licensed under the\nApache 2 license.\n\nSee the AUTHORS file for a comprehensive list of the authors.\n\nDocumentation\n-------------\n\n.. image:: https://readthedocs.org/projects/asynctest/badge/\n :target: http://asynctest.readthedocs.org/en/latest/\n\nFull documentation is available at http://asynctest.readthedocs.org/en/latest/.\nIt includes a tutorial with tested examples of how to use ``TestCase`` or\nmocks.\n\nFeatures\n--------\n\nTestCases\n~~~~~~~~~\n\n - Initialize and close a loop created for each test (it can be\n configurated), if the loop uses a selector, it will be updated with\n a TestSelector object wrapping the original selector (see below),\n\n - if the test function is a coroutine function or returns a coroutine, it\n will run on the loop,\n\n - TestCase.setUp() and TestCase.tearDown() can be coroutine functions,\n\n - control post-test checks with `@fail_on`, for instance, the test fail if\n the loop didn't run, some optional checks can be activated,\n\n - ClockedTestCase allows to control the loop clock and run timed events\n without waiting the wall clock.\n\nMock and CoroutineMock\n~~~~~~~~~~~~~~~~~~~~~~\n\n - CoroutineMock is a new Mock class which mocks a coroutine function, and\n returns a coroutine when called,\n\n - MagicMock supports asynchronous context managers and asynchronous\n iterators,\n\n - NonCallableMock, Mock and CoroutineMock can return CoroutineMock objects\n when its attributes are get if there is a matching attribute in the spec\n (or spec_set) object which is a coroutine function,\n\n - patch(), patch.object(), patch.multiple() return a MagickMock or\n CoroutineMock object by default, according to the patched target,\n\n - patch(), patch.object(), patch.multiple() handle generators and coroutines\n and their behavior can be controled when the generator or coroutine pauses,\n\n - all the patch() methods can decorate coroutine functions,\n\n - mock_open() returns a MagickMock object by default.\n\n - return_once() can be used with Mock.side_effect to return a value only\n once when a mock is called.\n\nSelectors\n~~~~~~~~~\n\nThe module asynctest.selector provides classes to mock objects performing IO\n(files, sockets, etc).\n\n - FileMock is a special type of mock which represents a file.\n FileMock.fileno() returns a special value which allows to identify uniquely\n the mock,\n\n - SocketMock is a special type of FileMock which uses socket.socket as spec,\n\n - TestSelector is a custom selector able to wrap a real selector\n implementation and deal with FileMock objects, it can replace a selector\n loop by calling `loop._selector = TestSelector(loop._selector)`, and will\n intercept mock so they don't get registered to the actual selector.\n\n - set_read_ready() and set_write_ready() to force read and write event\n callbacks to be scheduled on the loop, as if the selector scheduled them.\n\nHelpers\n~~~~~~~\n\n - the coroutine exhaust_callbacks(loop) returns once all the callbacks which\n should be called immediately are executed, which is useful when the test\n author needs to assert things which are not yet executed by the loop.\n\nRoadmap\n-------\n\nI hope I will find time to develop and release the following features:\n\n- set of warnings against common mistakes\n- proactor support\n\nTests\n-----\n\nasynctest is unit tested. You can run asynctest test suite with this command::\n\n$ PYTHONPATH=. python -m unittest test\n\n\n",
"bugtrack_url": null,
"license": "Apache 2",
"summary": "Enhance the standard unittest package with features for testing asyncio libraries",
"version": "0.13.0",
"split_keywords": [
"unittest",
"test",
"testing",
"asyncio",
"tulip",
"selectors",
"async",
"mock"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "82ac26a6b42400fb636817e130f70b6d",
"sha256": "5da6118a7e6d6b54d83a8f7197769d046922a44d2a99c21382f0a6e4fadae676"
},
"downloads": -1,
"filename": "asynctest-0.13.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "82ac26a6b42400fb636817e130f70b6d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 26427,
"upload_time": "2019-05-14T16:42:22",
"upload_time_iso_8601": "2019-05-14T16:42:22.894733Z",
"url": "https://files.pythonhosted.org/packages/e8/b6/8d17e169d577ca7678b11cd0d3ceebb0a6089a7f4a2de4b945fe4b1c86db/asynctest-0.13.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "b616fb83a225dcfa74b365deb40b8a64",
"sha256": "c27862842d15d83e6a34eb0b2866c323880eb3a75e4485b079ea11748fd77fac"
},
"downloads": -1,
"filename": "asynctest-0.13.0.tar.gz",
"has_sig": false,
"md5_digest": "b616fb83a225dcfa74b365deb40b8a64",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 42301,
"upload_time": "2019-05-14T16:42:24",
"upload_time_iso_8601": "2019-05-14T16:42:24.242020Z",
"url": "https://files.pythonhosted.org/packages/0c/0f/6056f4435923d2f8c89ac9ef2d18506a569348d8f9cc827b0dd7a4c8acc4/asynctest-0.13.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2019-05-14 16:42:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Martiusweb",
"github_project": "asynctest",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"appveyor": true,
"lcname": "asynctest"
}