diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/tools/third_party/pytest-asyncio | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/tools/third_party/pytest-asyncio')
13 files changed, 1427 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/LICENSE b/testing/web-platform/tests/tools/third_party/pytest-asyncio/LICENSE new file mode 100644 index 0000000000..e06d208186 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/LICENSE @@ -0,0 +1,202 @@ +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/PKG-INFO b/testing/web-platform/tests/tools/third_party/pytest-asyncio/PKG-INFO new file mode 100644 index 0000000000..bb7611bc1a --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/PKG-INFO @@ -0,0 +1,302 @@ +Metadata-Version: 2.1 +Name: pytest-asyncio +Version: 0.14.0 +Summary: Pytest support for asyncio. +Home-page: https://github.com/pytest-dev/pytest-asyncio +Author: Tin Tvrtković +Author-email: tinchester@gmail.com +License: Apache 2.0 +Description: pytest-asyncio: pytest support for asyncio + ========================================== + + .. image:: https://img.shields.io/pypi/v/pytest-asyncio.svg + :target: https://pypi.python.org/pypi/pytest-asyncio + .. image:: https://travis-ci.org/pytest-dev/pytest-asyncio.svg?branch=master + :target: https://travis-ci.org/pytest-dev/pytest-asyncio + .. image:: https://coveralls.io/repos/pytest-dev/pytest-asyncio/badge.svg + :target: https://coveralls.io/r/pytest-dev/pytest-asyncio + .. image:: https://img.shields.io/pypi/pyversions/pytest-asyncio.svg + :target: https://github.com/pytest-dev/pytest-asyncio + :alt: Supported Python versions + + pytest-asyncio is an Apache2 licensed library, written in Python, for testing + asyncio code with pytest. + + asyncio code is usually written in the form of coroutines, which makes it + slightly more difficult to test using normal testing tools. pytest-asyncio + provides useful fixtures and markers to make testing easier. + + .. code-block:: python + + @pytest.mark.asyncio + async def test_some_asyncio_code(): + res = await library.do_something() + assert b'expected result' == res + + pytest-asyncio has been strongly influenced by pytest-tornado_. + + .. _pytest-tornado: https://github.com/eugeniy/pytest-tornado + + Features + -------- + + - fixtures for creating and injecting versions of the asyncio event loop + - fixtures for injecting unused tcp ports + - pytest markers for treating tests as asyncio coroutines + - easy testing with non-default event loops + - support for `async def` fixtures and async generator fixtures + + Installation + ------------ + + To install pytest-asyncio, simply: + + .. code-block:: bash + + $ pip install pytest-asyncio + + This is enough for pytest to pick up pytest-asyncio. + + Fixtures + -------- + + ``event_loop`` + ~~~~~~~~~~~~~~ + Creates and injects a new instance of the default asyncio event loop. By + default, the loop will be closed at the end of the test (i.e. the default + fixture scope is ``function``). + + Note that just using the ``event_loop`` fixture won't make your test function + a coroutine. You'll need to interact with the event loop directly, using methods + like ``event_loop.run_until_complete``. See the ``pytest.mark.asyncio`` marker + for treating test functions like coroutines. + + Simply using this fixture will not set the generated event loop as the + default asyncio event loop, or change the asyncio event loop policy in any way. + Use ``pytest.mark.asyncio`` for this purpose. + + .. code-block:: python + + def test_http_client(event_loop): + url = 'http://httpbin.org/get' + resp = event_loop.run_until_complete(http_client(url)) + assert b'HTTP/1.1 200 OK' in resp + + This fixture can be easily overridden in any of the standard pytest locations + (e.g. directly in the test file, or in ``conftest.py``) to use a non-default + event loop. This will take effect even if you're using the + ``pytest.mark.asyncio`` marker and not the ``event_loop`` fixture directly. + + .. code-block:: python + + @pytest.fixture + def event_loop(): + loop = MyCustomLoop() + yield loop + loop.close() + + If the ``pytest.mark.asyncio`` marker is applied, a pytest hook will + ensure the produced loop is set as the default global loop. + Fixtures depending on the ``event_loop`` fixture can expect the policy to be properly modified when they run. + + ``unused_tcp_port`` + ~~~~~~~~~~~~~~~~~~~ + Finds and yields a single unused TCP port on the localhost interface. Useful for + binding temporary test servers. + + ``unused_tcp_port_factory`` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + A callable which returns a different unused TCP port each invocation. Useful + when several unused TCP ports are required in a test. + + .. code-block:: python + + def a_test(unused_tcp_port_factory): + port1, port2 = unused_tcp_port_factory(), unused_tcp_port_factory() + ... + + Async fixtures + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Asynchronous fixtures are defined just like ordinary pytest fixtures, except they should be coroutines or asynchronous generators. + + .. code-block:: python3 + + @pytest.fixture + async def async_gen_fixture(): + await asyncio.sleep(0.1) + yield 'a value' + + @pytest.fixture(scope='module') + async def async_fixture(): + return await asyncio.sleep(0.1) + + All scopes are supported, but if you use a non-function scope you will need + to redefine the ``event_loop`` fixture to have the same or broader scope. + Async fixtures need the event loop, and so must have the same or narrower scope + than the ``event_loop`` fixture. + + If you want to do this with Python 3.5, the ``yield`` statement must be replaced with ``await yield_()`` and the coroutine + function must be decorated with ``@async_generator``, like so: + + .. code-block:: python3 + + from async_generator import yield_, async_generator + + @pytest.fixture + @async_generator + async def async_gen_fixture(): + await asyncio.sleep(0.1) + await yield_('a value') + + + Markers + ------- + + ``pytest.mark.asyncio`` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Mark your test coroutine with this marker and pytest will execute it as an + asyncio task using the event loop provided by the ``event_loop`` fixture. See + the introductory section for an example. + + The event loop used can be overriden by overriding the ``event_loop`` fixture + (see above). + + In order to make your test code a little more concise, the pytest |pytestmark|_ + feature can be used to mark entire modules or classes with this marker. + Only test coroutines will be affected (by default, coroutines prefixed by + ``test_``), so, for example, fixtures are safe to define. + + .. code-block:: python + + import asyncio + import pytest + + # All test coroutines will be treated as marked. + pytestmark = pytest.mark.asyncio + + async def test_example(event_loop): + """No marker!""" + await asyncio.sleep(0, loop=event_loop) + + .. |pytestmark| replace:: ``pytestmark`` + .. _pytestmark: http://doc.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules + + Changelog + --------- + 0.13.0 (2020-06-24) + ~~~~~~~~~~~~~~~~~~~ + - Fix `#162 <https://github.com/pytest-dev/pytest-asyncio/issues/162>`_, and ``event_loop`` fixture behavior now is coherent on all scopes. + `#164 <https://github.com/pytest-dev/pytest-asyncio/pull/164>`_ + + 0.12.0 (2020-05-04) + ~~~~~~~~~~~~~~~~~~~ + - Run the event loop fixture as soon as possible. This helps with fixtures that have an implicit dependency on the event loop. + `#156 <https://github.com/pytest-dev/pytest-asyncio/pull/156>`_ + + 0.11.0 (2020-04-20) + ~~~~~~~~~~~~~~~~~~~ + - Test on 3.8, drop 3.3 and 3.4. Stick to 0.10 for these versions. + `#152 <https://github.com/pytest-dev/pytest-asyncio/pull/152>`_ + - Use the new Pytest 5.4.0 Function API. We therefore depend on pytest >= 5.4.0. + `#142 <https://github.com/pytest-dev/pytest-asyncio/pull/142>`_ + - Better ``pytest.skip`` support. + `#126 <https://github.com/pytest-dev/pytest-asyncio/pull/126>`_ + + 0.10.0 (2019-01-08) + ~~~~~~~~~~~~~~~~~~~~ + - ``pytest-asyncio`` integrates with `Hypothesis <https://hypothesis.readthedocs.io>`_ + to support ``@given`` on async test functions using ``asyncio``. + `#102 <https://github.com/pytest-dev/pytest-asyncio/pull/102>`_ + - Pytest 4.1 support. + `#105 <https://github.com/pytest-dev/pytest-asyncio/pull/105>`_ + + 0.9.0 (2018-07-28) + ~~~~~~~~~~~~~~~~~~ + - Python 3.7 support. + - Remove ``event_loop_process_pool`` fixture and + ``pytest.mark.asyncio_process_pool`` marker (see + https://bugs.python.org/issue34075 for deprecation and removal details) + + 0.8.0 (2017-09-23) + ~~~~~~~~~~~~~~~~~~ + - Improve integration with other packages (like aiohttp) with more careful event loop handling. + `#64 <https://github.com/pytest-dev/pytest-asyncio/pull/64>`_ + + 0.7.0 (2017-09-08) + ~~~~~~~~~~~~~~~~~~ + - Python versions pre-3.6 can use the async_generator library for async fixtures. + `#62 <https://github.com/pytest-dev/pytest-asyncio/pull/62>` + + + 0.6.0 (2017-05-28) + ~~~~~~~~~~~~~~~~~~ + - Support for Python versions pre-3.5 has been dropped. + - ``pytestmark`` now works on both module and class level. + - The ``forbid_global_loop`` parameter has been removed. + - Support for async and async gen fixtures has been added. + `#45 <https://github.com/pytest-dev/pytest-asyncio/pull/45>`_ + - The deprecation warning regarding ``asyncio.async()`` has been fixed. + `#51 <https://github.com/pytest-dev/pytest-asyncio/pull/51>`_ + + 0.5.0 (2016-09-07) + ~~~~~~~~~~~~~~~~~~ + - Introduced a changelog. + `#31 <https://github.com/pytest-dev/pytest-asyncio/issues/31>`_ + - The ``event_loop`` fixture is again responsible for closing itself. + This makes the fixture slightly harder to correctly override, but enables + other fixtures to depend on it correctly. + `#30 <https://github.com/pytest-dev/pytest-asyncio/issues/30>`_ + - Deal with the event loop policy by wrapping a special pytest hook, + ``pytest_fixture_setup``. This allows setting the policy before fixtures + dependent on the ``event_loop`` fixture run, thus allowing them to take + advantage of the ``forbid_global_loop`` parameter. As a consequence of this, + we now depend on pytest 3.0. + `#29 <https://github.com/pytest-dev/pytest-asyncio/issues/29>`_ + + + 0.4.1 (2016-06-01) + ~~~~~~~~~~~~~~~~~~ + - Fix a bug preventing the propagation of exceptions from the plugin. + `#25 <https://github.com/pytest-dev/pytest-asyncio/issues/25>`_ + + 0.4.0 (2016-05-30) + ~~~~~~~~~~~~~~~~~~ + - Make ``event_loop`` fixtures simpler to override by closing them in the + plugin, instead of directly in the fixture. + `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_ + - Introduce the ``forbid_global_loop`` parameter. + `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_ + + 0.3.0 (2015-12-19) + ~~~~~~~~~~~~~~~~~~ + - Support for Python 3.5 ``async``/``await`` syntax. + `#17 <https://github.com/pytest-dev/pytest-asyncio/pull/17>`_ + + 0.2.0 (2015-08-01) + ~~~~~~~~~~~~~~~~~~ + - ``unused_tcp_port_factory`` fixture. + `#10 <https://github.com/pytest-dev/pytest-asyncio/issues/10>`_ + + + 0.1.1 (2015-04-23) + ~~~~~~~~~~~~~~~~~~ + Initial release. + + + Contributing + ------------ + Contributions are very welcome. Tests can be run with ``tox``, please ensure + the coverage at least stays the same before you submit a pull request. + +Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: Apache Software License +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Topic :: Software Development :: Testing +Classifier: Framework :: Pytest +Requires-Python: >= 3.5 +Provides-Extra: testing diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/README.rst b/testing/web-platform/tests/tools/third_party/pytest-asyncio/README.rst new file mode 100644 index 0000000000..6ea6014cce --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/README.rst @@ -0,0 +1,281 @@ +pytest-asyncio: pytest support for asyncio +========================================== + +.. image:: https://img.shields.io/pypi/v/pytest-asyncio.svg + :target: https://pypi.python.org/pypi/pytest-asyncio +.. image:: https://travis-ci.org/pytest-dev/pytest-asyncio.svg?branch=master + :target: https://travis-ci.org/pytest-dev/pytest-asyncio +.. image:: https://coveralls.io/repos/pytest-dev/pytest-asyncio/badge.svg + :target: https://coveralls.io/r/pytest-dev/pytest-asyncio +.. image:: https://img.shields.io/pypi/pyversions/pytest-asyncio.svg + :target: https://github.com/pytest-dev/pytest-asyncio + :alt: Supported Python versions + +pytest-asyncio is an Apache2 licensed library, written in Python, for testing +asyncio code with pytest. + +asyncio code is usually written in the form of coroutines, which makes it +slightly more difficult to test using normal testing tools. pytest-asyncio +provides useful fixtures and markers to make testing easier. + +.. code-block:: python + + @pytest.mark.asyncio + async def test_some_asyncio_code(): + res = await library.do_something() + assert b'expected result' == res + +pytest-asyncio has been strongly influenced by pytest-tornado_. + +.. _pytest-tornado: https://github.com/eugeniy/pytest-tornado + +Features +-------- + +- fixtures for creating and injecting versions of the asyncio event loop +- fixtures for injecting unused tcp ports +- pytest markers for treating tests as asyncio coroutines +- easy testing with non-default event loops +- support for `async def` fixtures and async generator fixtures + +Installation +------------ + +To install pytest-asyncio, simply: + +.. code-block:: bash + + $ pip install pytest-asyncio + +This is enough for pytest to pick up pytest-asyncio. + +Fixtures +-------- + +``event_loop`` +~~~~~~~~~~~~~~ +Creates and injects a new instance of the default asyncio event loop. By +default, the loop will be closed at the end of the test (i.e. the default +fixture scope is ``function``). + +Note that just using the ``event_loop`` fixture won't make your test function +a coroutine. You'll need to interact with the event loop directly, using methods +like ``event_loop.run_until_complete``. See the ``pytest.mark.asyncio`` marker +for treating test functions like coroutines. + +Simply using this fixture will not set the generated event loop as the +default asyncio event loop, or change the asyncio event loop policy in any way. +Use ``pytest.mark.asyncio`` for this purpose. + +.. code-block:: python + + def test_http_client(event_loop): + url = 'http://httpbin.org/get' + resp = event_loop.run_until_complete(http_client(url)) + assert b'HTTP/1.1 200 OK' in resp + +This fixture can be easily overridden in any of the standard pytest locations +(e.g. directly in the test file, or in ``conftest.py``) to use a non-default +event loop. This will take effect even if you're using the +``pytest.mark.asyncio`` marker and not the ``event_loop`` fixture directly. + +.. code-block:: python + + @pytest.fixture + def event_loop(): + loop = MyCustomLoop() + yield loop + loop.close() + +If the ``pytest.mark.asyncio`` marker is applied, a pytest hook will +ensure the produced loop is set as the default global loop. +Fixtures depending on the ``event_loop`` fixture can expect the policy to be properly modified when they run. + +``unused_tcp_port`` +~~~~~~~~~~~~~~~~~~~ +Finds and yields a single unused TCP port on the localhost interface. Useful for +binding temporary test servers. + +``unused_tcp_port_factory`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~ +A callable which returns a different unused TCP port each invocation. Useful +when several unused TCP ports are required in a test. + +.. code-block:: python + + def a_test(unused_tcp_port_factory): + port1, port2 = unused_tcp_port_factory(), unused_tcp_port_factory() + ... + +Async fixtures +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Asynchronous fixtures are defined just like ordinary pytest fixtures, except they should be coroutines or asynchronous generators. + +.. code-block:: python3 + + @pytest.fixture + async def async_gen_fixture(): + await asyncio.sleep(0.1) + yield 'a value' + + @pytest.fixture(scope='module') + async def async_fixture(): + return await asyncio.sleep(0.1) + +All scopes are supported, but if you use a non-function scope you will need +to redefine the ``event_loop`` fixture to have the same or broader scope. +Async fixtures need the event loop, and so must have the same or narrower scope +than the ``event_loop`` fixture. + +If you want to do this with Python 3.5, the ``yield`` statement must be replaced with ``await yield_()`` and the coroutine +function must be decorated with ``@async_generator``, like so: + +.. code-block:: python3 + + from async_generator import yield_, async_generator + + @pytest.fixture + @async_generator + async def async_gen_fixture(): + await asyncio.sleep(0.1) + await yield_('a value') + + +Markers +------- + +``pytest.mark.asyncio`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Mark your test coroutine with this marker and pytest will execute it as an +asyncio task using the event loop provided by the ``event_loop`` fixture. See +the introductory section for an example. + +The event loop used can be overriden by overriding the ``event_loop`` fixture +(see above). + +In order to make your test code a little more concise, the pytest |pytestmark|_ +feature can be used to mark entire modules or classes with this marker. +Only test coroutines will be affected (by default, coroutines prefixed by +``test_``), so, for example, fixtures are safe to define. + +.. code-block:: python + + import asyncio + import pytest + + # All test coroutines will be treated as marked. + pytestmark = pytest.mark.asyncio + + async def test_example(event_loop): + """No marker!""" + await asyncio.sleep(0, loop=event_loop) + +.. |pytestmark| replace:: ``pytestmark`` +.. _pytestmark: http://doc.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules + +Changelog +--------- +0.13.0 (2020-06-24) +~~~~~~~~~~~~~~~~~~~ +- Fix `#162 <https://github.com/pytest-dev/pytest-asyncio/issues/162>`_, and ``event_loop`` fixture behavior now is coherent on all scopes. + `#164 <https://github.com/pytest-dev/pytest-asyncio/pull/164>`_ + +0.12.0 (2020-05-04) +~~~~~~~~~~~~~~~~~~~ +- Run the event loop fixture as soon as possible. This helps with fixtures that have an implicit dependency on the event loop. + `#156 <https://github.com/pytest-dev/pytest-asyncio/pull/156>`_ + +0.11.0 (2020-04-20) +~~~~~~~~~~~~~~~~~~~ +- Test on 3.8, drop 3.3 and 3.4. Stick to 0.10 for these versions. + `#152 <https://github.com/pytest-dev/pytest-asyncio/pull/152>`_ +- Use the new Pytest 5.4.0 Function API. We therefore depend on pytest >= 5.4.0. + `#142 <https://github.com/pytest-dev/pytest-asyncio/pull/142>`_ +- Better ``pytest.skip`` support. + `#126 <https://github.com/pytest-dev/pytest-asyncio/pull/126>`_ + +0.10.0 (2019-01-08) +~~~~~~~~~~~~~~~~~~~~ +- ``pytest-asyncio`` integrates with `Hypothesis <https://hypothesis.readthedocs.io>`_ + to support ``@given`` on async test functions using ``asyncio``. + `#102 <https://github.com/pytest-dev/pytest-asyncio/pull/102>`_ +- Pytest 4.1 support. + `#105 <https://github.com/pytest-dev/pytest-asyncio/pull/105>`_ + +0.9.0 (2018-07-28) +~~~~~~~~~~~~~~~~~~ +- Python 3.7 support. +- Remove ``event_loop_process_pool`` fixture and + ``pytest.mark.asyncio_process_pool`` marker (see + https://bugs.python.org/issue34075 for deprecation and removal details) + +0.8.0 (2017-09-23) +~~~~~~~~~~~~~~~~~~ +- Improve integration with other packages (like aiohttp) with more careful event loop handling. + `#64 <https://github.com/pytest-dev/pytest-asyncio/pull/64>`_ + +0.7.0 (2017-09-08) +~~~~~~~~~~~~~~~~~~ +- Python versions pre-3.6 can use the async_generator library for async fixtures. + `#62 <https://github.com/pytest-dev/pytest-asyncio/pull/62>` + + +0.6.0 (2017-05-28) +~~~~~~~~~~~~~~~~~~ +- Support for Python versions pre-3.5 has been dropped. +- ``pytestmark`` now works on both module and class level. +- The ``forbid_global_loop`` parameter has been removed. +- Support for async and async gen fixtures has been added. + `#45 <https://github.com/pytest-dev/pytest-asyncio/pull/45>`_ +- The deprecation warning regarding ``asyncio.async()`` has been fixed. + `#51 <https://github.com/pytest-dev/pytest-asyncio/pull/51>`_ + +0.5.0 (2016-09-07) +~~~~~~~~~~~~~~~~~~ +- Introduced a changelog. + `#31 <https://github.com/pytest-dev/pytest-asyncio/issues/31>`_ +- The ``event_loop`` fixture is again responsible for closing itself. + This makes the fixture slightly harder to correctly override, but enables + other fixtures to depend on it correctly. + `#30 <https://github.com/pytest-dev/pytest-asyncio/issues/30>`_ +- Deal with the event loop policy by wrapping a special pytest hook, + ``pytest_fixture_setup``. This allows setting the policy before fixtures + dependent on the ``event_loop`` fixture run, thus allowing them to take + advantage of the ``forbid_global_loop`` parameter. As a consequence of this, + we now depend on pytest 3.0. + `#29 <https://github.com/pytest-dev/pytest-asyncio/issues/29>`_ + + +0.4.1 (2016-06-01) +~~~~~~~~~~~~~~~~~~ +- Fix a bug preventing the propagation of exceptions from the plugin. + `#25 <https://github.com/pytest-dev/pytest-asyncio/issues/25>`_ + +0.4.0 (2016-05-30) +~~~~~~~~~~~~~~~~~~ +- Make ``event_loop`` fixtures simpler to override by closing them in the + plugin, instead of directly in the fixture. + `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_ +- Introduce the ``forbid_global_loop`` parameter. + `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_ + +0.3.0 (2015-12-19) +~~~~~~~~~~~~~~~~~~ +- Support for Python 3.5 ``async``/``await`` syntax. + `#17 <https://github.com/pytest-dev/pytest-asyncio/pull/17>`_ + +0.2.0 (2015-08-01) +~~~~~~~~~~~~~~~~~~ +- ``unused_tcp_port_factory`` fixture. + `#10 <https://github.com/pytest-dev/pytest-asyncio/issues/10>`_ + + +0.1.1 (2015-04-23) +~~~~~~~~~~~~~~~~~~ +Initial release. + + +Contributing +------------ +Contributions are very welcome. Tests can be run with ``tox``, please ensure +the coverage at least stays the same before you submit a pull request. diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/PKG-INFO b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/PKG-INFO new file mode 100644 index 0000000000..bb7611bc1a --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/PKG-INFO @@ -0,0 +1,302 @@ +Metadata-Version: 2.1 +Name: pytest-asyncio +Version: 0.14.0 +Summary: Pytest support for asyncio. +Home-page: https://github.com/pytest-dev/pytest-asyncio +Author: Tin Tvrtković +Author-email: tinchester@gmail.com +License: Apache 2.0 +Description: pytest-asyncio: pytest support for asyncio + ========================================== + + .. image:: https://img.shields.io/pypi/v/pytest-asyncio.svg + :target: https://pypi.python.org/pypi/pytest-asyncio + .. image:: https://travis-ci.org/pytest-dev/pytest-asyncio.svg?branch=master + :target: https://travis-ci.org/pytest-dev/pytest-asyncio + .. image:: https://coveralls.io/repos/pytest-dev/pytest-asyncio/badge.svg + :target: https://coveralls.io/r/pytest-dev/pytest-asyncio + .. image:: https://img.shields.io/pypi/pyversions/pytest-asyncio.svg + :target: https://github.com/pytest-dev/pytest-asyncio + :alt: Supported Python versions + + pytest-asyncio is an Apache2 licensed library, written in Python, for testing + asyncio code with pytest. + + asyncio code is usually written in the form of coroutines, which makes it + slightly more difficult to test using normal testing tools. pytest-asyncio + provides useful fixtures and markers to make testing easier. + + .. code-block:: python + + @pytest.mark.asyncio + async def test_some_asyncio_code(): + res = await library.do_something() + assert b'expected result' == res + + pytest-asyncio has been strongly influenced by pytest-tornado_. + + .. _pytest-tornado: https://github.com/eugeniy/pytest-tornado + + Features + -------- + + - fixtures for creating and injecting versions of the asyncio event loop + - fixtures for injecting unused tcp ports + - pytest markers for treating tests as asyncio coroutines + - easy testing with non-default event loops + - support for `async def` fixtures and async generator fixtures + + Installation + ------------ + + To install pytest-asyncio, simply: + + .. code-block:: bash + + $ pip install pytest-asyncio + + This is enough for pytest to pick up pytest-asyncio. + + Fixtures + -------- + + ``event_loop`` + ~~~~~~~~~~~~~~ + Creates and injects a new instance of the default asyncio event loop. By + default, the loop will be closed at the end of the test (i.e. the default + fixture scope is ``function``). + + Note that just using the ``event_loop`` fixture won't make your test function + a coroutine. You'll need to interact with the event loop directly, using methods + like ``event_loop.run_until_complete``. See the ``pytest.mark.asyncio`` marker + for treating test functions like coroutines. + + Simply using this fixture will not set the generated event loop as the + default asyncio event loop, or change the asyncio event loop policy in any way. + Use ``pytest.mark.asyncio`` for this purpose. + + .. code-block:: python + + def test_http_client(event_loop): + url = 'http://httpbin.org/get' + resp = event_loop.run_until_complete(http_client(url)) + assert b'HTTP/1.1 200 OK' in resp + + This fixture can be easily overridden in any of the standard pytest locations + (e.g. directly in the test file, or in ``conftest.py``) to use a non-default + event loop. This will take effect even if you're using the + ``pytest.mark.asyncio`` marker and not the ``event_loop`` fixture directly. + + .. code-block:: python + + @pytest.fixture + def event_loop(): + loop = MyCustomLoop() + yield loop + loop.close() + + If the ``pytest.mark.asyncio`` marker is applied, a pytest hook will + ensure the produced loop is set as the default global loop. + Fixtures depending on the ``event_loop`` fixture can expect the policy to be properly modified when they run. + + ``unused_tcp_port`` + ~~~~~~~~~~~~~~~~~~~ + Finds and yields a single unused TCP port on the localhost interface. Useful for + binding temporary test servers. + + ``unused_tcp_port_factory`` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + A callable which returns a different unused TCP port each invocation. Useful + when several unused TCP ports are required in a test. + + .. code-block:: python + + def a_test(unused_tcp_port_factory): + port1, port2 = unused_tcp_port_factory(), unused_tcp_port_factory() + ... + + Async fixtures + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Asynchronous fixtures are defined just like ordinary pytest fixtures, except they should be coroutines or asynchronous generators. + + .. code-block:: python3 + + @pytest.fixture + async def async_gen_fixture(): + await asyncio.sleep(0.1) + yield 'a value' + + @pytest.fixture(scope='module') + async def async_fixture(): + return await asyncio.sleep(0.1) + + All scopes are supported, but if you use a non-function scope you will need + to redefine the ``event_loop`` fixture to have the same or broader scope. + Async fixtures need the event loop, and so must have the same or narrower scope + than the ``event_loop`` fixture. + + If you want to do this with Python 3.5, the ``yield`` statement must be replaced with ``await yield_()`` and the coroutine + function must be decorated with ``@async_generator``, like so: + + .. code-block:: python3 + + from async_generator import yield_, async_generator + + @pytest.fixture + @async_generator + async def async_gen_fixture(): + await asyncio.sleep(0.1) + await yield_('a value') + + + Markers + ------- + + ``pytest.mark.asyncio`` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Mark your test coroutine with this marker and pytest will execute it as an + asyncio task using the event loop provided by the ``event_loop`` fixture. See + the introductory section for an example. + + The event loop used can be overriden by overriding the ``event_loop`` fixture + (see above). + + In order to make your test code a little more concise, the pytest |pytestmark|_ + feature can be used to mark entire modules or classes with this marker. + Only test coroutines will be affected (by default, coroutines prefixed by + ``test_``), so, for example, fixtures are safe to define. + + .. code-block:: python + + import asyncio + import pytest + + # All test coroutines will be treated as marked. + pytestmark = pytest.mark.asyncio + + async def test_example(event_loop): + """No marker!""" + await asyncio.sleep(0, loop=event_loop) + + .. |pytestmark| replace:: ``pytestmark`` + .. _pytestmark: http://doc.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules + + Changelog + --------- + 0.13.0 (2020-06-24) + ~~~~~~~~~~~~~~~~~~~ + - Fix `#162 <https://github.com/pytest-dev/pytest-asyncio/issues/162>`_, and ``event_loop`` fixture behavior now is coherent on all scopes. + `#164 <https://github.com/pytest-dev/pytest-asyncio/pull/164>`_ + + 0.12.0 (2020-05-04) + ~~~~~~~~~~~~~~~~~~~ + - Run the event loop fixture as soon as possible. This helps with fixtures that have an implicit dependency on the event loop. + `#156 <https://github.com/pytest-dev/pytest-asyncio/pull/156>`_ + + 0.11.0 (2020-04-20) + ~~~~~~~~~~~~~~~~~~~ + - Test on 3.8, drop 3.3 and 3.4. Stick to 0.10 for these versions. + `#152 <https://github.com/pytest-dev/pytest-asyncio/pull/152>`_ + - Use the new Pytest 5.4.0 Function API. We therefore depend on pytest >= 5.4.0. + `#142 <https://github.com/pytest-dev/pytest-asyncio/pull/142>`_ + - Better ``pytest.skip`` support. + `#126 <https://github.com/pytest-dev/pytest-asyncio/pull/126>`_ + + 0.10.0 (2019-01-08) + ~~~~~~~~~~~~~~~~~~~~ + - ``pytest-asyncio`` integrates with `Hypothesis <https://hypothesis.readthedocs.io>`_ + to support ``@given`` on async test functions using ``asyncio``. + `#102 <https://github.com/pytest-dev/pytest-asyncio/pull/102>`_ + - Pytest 4.1 support. + `#105 <https://github.com/pytest-dev/pytest-asyncio/pull/105>`_ + + 0.9.0 (2018-07-28) + ~~~~~~~~~~~~~~~~~~ + - Python 3.7 support. + - Remove ``event_loop_process_pool`` fixture and + ``pytest.mark.asyncio_process_pool`` marker (see + https://bugs.python.org/issue34075 for deprecation and removal details) + + 0.8.0 (2017-09-23) + ~~~~~~~~~~~~~~~~~~ + - Improve integration with other packages (like aiohttp) with more careful event loop handling. + `#64 <https://github.com/pytest-dev/pytest-asyncio/pull/64>`_ + + 0.7.0 (2017-09-08) + ~~~~~~~~~~~~~~~~~~ + - Python versions pre-3.6 can use the async_generator library for async fixtures. + `#62 <https://github.com/pytest-dev/pytest-asyncio/pull/62>` + + + 0.6.0 (2017-05-28) + ~~~~~~~~~~~~~~~~~~ + - Support for Python versions pre-3.5 has been dropped. + - ``pytestmark`` now works on both module and class level. + - The ``forbid_global_loop`` parameter has been removed. + - Support for async and async gen fixtures has been added. + `#45 <https://github.com/pytest-dev/pytest-asyncio/pull/45>`_ + - The deprecation warning regarding ``asyncio.async()`` has been fixed. + `#51 <https://github.com/pytest-dev/pytest-asyncio/pull/51>`_ + + 0.5.0 (2016-09-07) + ~~~~~~~~~~~~~~~~~~ + - Introduced a changelog. + `#31 <https://github.com/pytest-dev/pytest-asyncio/issues/31>`_ + - The ``event_loop`` fixture is again responsible for closing itself. + This makes the fixture slightly harder to correctly override, but enables + other fixtures to depend on it correctly. + `#30 <https://github.com/pytest-dev/pytest-asyncio/issues/30>`_ + - Deal with the event loop policy by wrapping a special pytest hook, + ``pytest_fixture_setup``. This allows setting the policy before fixtures + dependent on the ``event_loop`` fixture run, thus allowing them to take + advantage of the ``forbid_global_loop`` parameter. As a consequence of this, + we now depend on pytest 3.0. + `#29 <https://github.com/pytest-dev/pytest-asyncio/issues/29>`_ + + + 0.4.1 (2016-06-01) + ~~~~~~~~~~~~~~~~~~ + - Fix a bug preventing the propagation of exceptions from the plugin. + `#25 <https://github.com/pytest-dev/pytest-asyncio/issues/25>`_ + + 0.4.0 (2016-05-30) + ~~~~~~~~~~~~~~~~~~ + - Make ``event_loop`` fixtures simpler to override by closing them in the + plugin, instead of directly in the fixture. + `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_ + - Introduce the ``forbid_global_loop`` parameter. + `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_ + + 0.3.0 (2015-12-19) + ~~~~~~~~~~~~~~~~~~ + - Support for Python 3.5 ``async``/``await`` syntax. + `#17 <https://github.com/pytest-dev/pytest-asyncio/pull/17>`_ + + 0.2.0 (2015-08-01) + ~~~~~~~~~~~~~~~~~~ + - ``unused_tcp_port_factory`` fixture. + `#10 <https://github.com/pytest-dev/pytest-asyncio/issues/10>`_ + + + 0.1.1 (2015-04-23) + ~~~~~~~~~~~~~~~~~~ + Initial release. + + + Contributing + ------------ + Contributions are very welcome. Tests can be run with ``tox``, please ensure + the coverage at least stays the same before you submit a pull request. + +Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: Apache Software License +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Topic :: Software Development :: Testing +Classifier: Framework :: Pytest +Requires-Python: >= 3.5 +Provides-Extra: testing diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/SOURCES.txt b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/SOURCES.txt new file mode 100644 index 0000000000..40cd5d7c7f --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/SOURCES.txt @@ -0,0 +1,12 @@ +LICENSE +README.rst +setup.cfg +setup.py +pytest_asyncio/__init__.py +pytest_asyncio/plugin.py +pytest_asyncio.egg-info/PKG-INFO +pytest_asyncio.egg-info/SOURCES.txt +pytest_asyncio.egg-info/dependency_links.txt +pytest_asyncio.egg-info/entry_points.txt +pytest_asyncio.egg-info/requires.txt +pytest_asyncio.egg-info/top_level.txt
\ No newline at end of file diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/dependency_links.txt b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/dependency_links.txt new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/entry_points.txt b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/entry_points.txt new file mode 100644 index 0000000000..69c53be38a --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/entry_points.txt @@ -0,0 +1,3 @@ +[pytest11] +asyncio = pytest_asyncio.plugin + diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/requires.txt b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/requires.txt new file mode 100644 index 0000000000..d546f122ad --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/requires.txt @@ -0,0 +1,9 @@ +pytest>=5.4.0 + +[:python_version == "3.5"] +async_generator>=1.3 + +[testing] +async_generator>=1.3 +coverage +hypothesis>=5.7.1 diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/top_level.txt b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/top_level.txt new file mode 100644 index 0000000000..08d05d1ecf --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio.egg-info/top_level.txt @@ -0,0 +1 @@ +pytest_asyncio diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio/__init__.py b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio/__init__.py new file mode 100644 index 0000000000..61c5f43b95 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio/__init__.py @@ -0,0 +1,2 @@ +"""The main point for importing pytest-asyncio items.""" +__version__ = "0.14.0" diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio/plugin.py b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio/plugin.py new file mode 100644 index 0000000000..2fdc5f4e77 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/pytest_asyncio/plugin.py @@ -0,0 +1,240 @@ +"""pytest-asyncio implementation.""" +import asyncio +import contextlib +import functools +import inspect +import socket + +import pytest +try: + from _pytest.python import transfer_markers +except ImportError: # Pytest 4.1.0 removes the transfer_marker api (#104) + def transfer_markers(*args, **kwargs): # noqa + """Noop when over pytest 4.1.0""" + pass + +try: + from async_generator import isasyncgenfunction +except ImportError: + from inspect import isasyncgenfunction + + +def _is_coroutine(obj): + """Check to see if an object is really an asyncio coroutine.""" + return asyncio.iscoroutinefunction(obj) or inspect.isgeneratorfunction(obj) + + +def pytest_configure(config): + """Inject documentation.""" + config.addinivalue_line("markers", + "asyncio: " + "mark the test as a coroutine, it will be " + "run using an asyncio event loop") + + +@pytest.mark.tryfirst +def pytest_pycollect_makeitem(collector, name, obj): + """A pytest hook to collect asyncio coroutines.""" + if collector.funcnamefilter(name) and _is_coroutine(obj): + item = pytest.Function.from_parent(collector, name=name) + + # Due to how pytest test collection works, module-level pytestmarks + # are applied after the collection step. Since this is the collection + # step, we look ourselves. + transfer_markers(obj, item.cls, item.module) + item = pytest.Function.from_parent(collector, name=name) # To reload keywords. + + if 'asyncio' in item.keywords: + return list(collector._genfunctions(name, obj)) + + +class FixtureStripper: + """Include additional Fixture, and then strip them""" + REQUEST = "request" + EVENT_LOOP = "event_loop" + + def __init__(self, fixturedef): + self.fixturedef = fixturedef + self.to_strip = set() + + def add(self, name): + """Add fixture name to fixturedef + and record in to_strip list (If not previously included)""" + if name in self.fixturedef.argnames: + return + self.fixturedef.argnames += (name, ) + self.to_strip.add(name) + + def get_and_strip_from(self, name, data_dict): + """Strip name from data, and return value""" + result = data_dict[name] + if name in self.to_strip: + del data_dict[name] + return result + +@pytest.hookimpl(trylast=True) +def pytest_fixture_post_finalizer(fixturedef, request): + """Called after fixture teardown""" + if fixturedef.argname == "event_loop": + # Set empty loop policy, so that subsequent get_event_loop() provides a new loop + asyncio.set_event_loop_policy(None) + + + +@pytest.hookimpl(hookwrapper=True) +def pytest_fixture_setup(fixturedef, request): + """Adjust the event loop policy when an event loop is produced.""" + if fixturedef.argname == "event_loop": + outcome = yield + loop = outcome.get_result() + policy = asyncio.get_event_loop_policy() + policy.set_event_loop(loop) + return + + if isasyncgenfunction(fixturedef.func): + # This is an async generator function. Wrap it accordingly. + generator = fixturedef.func + + fixture_stripper = FixtureStripper(fixturedef) + fixture_stripper.add(FixtureStripper.EVENT_LOOP) + fixture_stripper.add(FixtureStripper.REQUEST) + + + def wrapper(*args, **kwargs): + loop = fixture_stripper.get_and_strip_from(FixtureStripper.EVENT_LOOP, kwargs) + request = fixture_stripper.get_and_strip_from(FixtureStripper.REQUEST, kwargs) + + gen_obj = generator(*args, **kwargs) + + async def setup(): + res = await gen_obj.__anext__() + return res + + def finalizer(): + """Yield again, to finalize.""" + async def async_finalizer(): + try: + await gen_obj.__anext__() + except StopAsyncIteration: + pass + else: + msg = "Async generator fixture didn't stop." + msg += "Yield only once." + raise ValueError(msg) + loop.run_until_complete(async_finalizer()) + + request.addfinalizer(finalizer) + return loop.run_until_complete(setup()) + + fixturedef.func = wrapper + elif inspect.iscoroutinefunction(fixturedef.func): + coro = fixturedef.func + + fixture_stripper = FixtureStripper(fixturedef) + fixture_stripper.add(FixtureStripper.EVENT_LOOP) + + def wrapper(*args, **kwargs): + loop = fixture_stripper.get_and_strip_from(FixtureStripper.EVENT_LOOP, kwargs) + + async def setup(): + res = await coro(*args, **kwargs) + return res + + return loop.run_until_complete(setup()) + + fixturedef.func = wrapper + yield + + +@pytest.hookimpl(tryfirst=True, hookwrapper=True) +def pytest_pyfunc_call(pyfuncitem): + """ + Run asyncio marked test functions in an event loop instead of a normal + function call. + """ + if 'asyncio' in pyfuncitem.keywords: + if getattr(pyfuncitem.obj, 'is_hypothesis_test', False): + pyfuncitem.obj.hypothesis.inner_test = wrap_in_sync( + pyfuncitem.obj.hypothesis.inner_test, + _loop=pyfuncitem.funcargs['event_loop'] + ) + else: + pyfuncitem.obj = wrap_in_sync( + pyfuncitem.obj, + _loop=pyfuncitem.funcargs['event_loop'] + ) + yield + + +def wrap_in_sync(func, _loop): + """Return a sync wrapper around an async function executing it in the + current event loop.""" + + @functools.wraps(func) + def inner(**kwargs): + coro = func(**kwargs) + if coro is not None: + task = asyncio.ensure_future(coro, loop=_loop) + try: + _loop.run_until_complete(task) + except BaseException: + # run_until_complete doesn't get the result from exceptions + # that are not subclasses of `Exception`. Consume all + # exceptions to prevent asyncio's warning from logging. + if task.done() and not task.cancelled(): + task.exception() + raise + return inner + + +def pytest_runtest_setup(item): + if 'asyncio' in item.keywords: + # inject an event loop fixture for all async tests + if 'event_loop' in item.fixturenames: + item.fixturenames.remove('event_loop') + item.fixturenames.insert(0, 'event_loop') + if item.get_closest_marker("asyncio") is not None \ + and not getattr(item.obj, 'hypothesis', False) \ + and getattr(item.obj, 'is_hypothesis_test', False): + pytest.fail( + 'test function `%r` is using Hypothesis, but pytest-asyncio ' + 'only works with Hypothesis 3.64.0 or later.' % item + ) + + +@pytest.fixture +def event_loop(request): + """Create an instance of the default event loop for each test case.""" + loop = asyncio.get_event_loop_policy().new_event_loop() + yield loop + loop.close() + + +def _unused_tcp_port(): + """Find an unused localhost TCP port from 1024-65535 and return it.""" + with contextlib.closing(socket.socket()) as sock: + sock.bind(('127.0.0.1', 0)) + return sock.getsockname()[1] + + +@pytest.fixture +def unused_tcp_port(): + return _unused_tcp_port() + + +@pytest.fixture +def unused_tcp_port_factory(): + """A factory function, producing different unused TCP ports.""" + produced = set() + + def factory(): + """Return an unused port.""" + port = _unused_tcp_port() + + while port in produced: + port = _unused_tcp_port() + + produced.add(port) + + return port + return factory diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/setup.cfg b/testing/web-platform/tests/tools/third_party/pytest-asyncio/setup.cfg new file mode 100644 index 0000000000..23a8eba2ce --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/setup.cfg @@ -0,0 +1,18 @@ +[coverage:run] +source = pytest_asyncio + +[coverage:report] +show_missing = true + +[tool:pytest] +addopts = -rsx --tb=short +testpaths = tests +filterwarnings = error + +[metadata] +license_file = LICENSE + +[egg_info] +tag_build = +tag_date = 0 + diff --git a/testing/web-platform/tests/tools/third_party/pytest-asyncio/setup.py b/testing/web-platform/tests/tools/third_party/pytest-asyncio/setup.py new file mode 100644 index 0000000000..6175711350 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/pytest-asyncio/setup.py @@ -0,0 +1,54 @@ +import re +from pathlib import Path + +from setuptools import setup, find_packages + + +def find_version(): + version_file = ( + Path(__file__) + .parent.joinpath("pytest_asyncio", "__init__.py") + .read_text() + ) + version_match = re.search( + r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M + ) + if version_match: + return version_match.group(1) + + raise RuntimeError("Unable to find version string.") + + +setup( + name="pytest-asyncio", + version=find_version(), + packages=find_packages(), + url="https://github.com/pytest-dev/pytest-asyncio", + license="Apache 2.0", + author="Tin Tvrtković", + author_email="tinchester@gmail.com", + description="Pytest support for asyncio.", + long_description=Path(__file__).parent.joinpath("README.rst").read_text(), + classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Topic :: Software Development :: Testing", + "Framework :: Pytest", + ], + python_requires=">= 3.5", + install_requires=["pytest >= 5.4.0"], + extras_require={ + ':python_version == "3.5"': "async_generator >= 1.3", + "testing": [ + "coverage", + "async_generator >= 1.3", + "hypothesis >= 5.7.1", + ], + }, + entry_points={"pytest11": ["asyncio = pytest_asyncio.plugin"]}, +) |