diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..27c1cc0 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,28 @@ +skip_tags: true + +os: Visual Studio 2015 + +environment: + matrix: + - PYTHON: "C:\\Python35" + - PYTHON: "C:\\Python35-x64" + - PYTHON: "C:\\Python36" + - PYTHON: "C:\\Python36-x64" + +build_script: + - "git --no-pager log -n2" + - "echo %APPVEYOR_REPO_COMMIT%" + - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;;%PATH%" + - "python --version" + - "python -c \"import struct; print(struct.calcsize('P') * 8)\"" + - "pip install ." + - "pip install -Ur test-requirements.txt" + - "pip install codecov" + +test_script: + - "mkdir empty" + - "cd empty" + # Make sure it's being imported from where we expect + - "python -c \"import os, pytest_trio; print(os.path.dirname(pytest_trio.__file__))\"" + - "python -u -m pytest -W error -ra -v -s --pyargs pytest_trio --cov=pytest_trio --cov-config=../.coveragerc" + - "codecov" diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..5687b73 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,9 @@ +[run] +branch=True +source=pytest_trio + +[report] +precision = 1 +exclude_lines = + pragma: no cover + abc.abstractmethod diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..afdfef3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,57 @@ +# Add any project-specific files here: + + +# Sphinx docs +docs/build/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*~ +\#* +.#* + +# C extensions +*.so + +# Distribution / packaging +.Python +/build/ +/develop-eggs/ +/dist/ +/eggs/ +/lib/ +/lib64/ +/parts/ +/sdist/ +/var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Rope +.ropeproject + +# Django stuff: +*.log +*.pot diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 0000000..7052a9a --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,10 @@ +# https://docs.readthedocs.io/en/latest/yaml-config.html +formats: + - htmlzip + - epub + +requirements_file: ci/rtd-requirements.txt + +python: + version: 3.6 + pip_install: True diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 0000000..2c71c9d --- /dev/null +++ b/.style.yapf @@ -0,0 +1,180 @@ +[style] +# Align closing bracket with visual indentation. +align_closing_bracket_with_visual_indent=True + +# Allow dictionary keys to exist on multiple lines. For example: +# +# x = { +# ('this is the first element of a tuple', +# 'this is the second element of a tuple'): +# value, +# } +allow_multiline_dictionary_keys=False + +# Allow lambdas to be formatted on more than one line. +allow_multiline_lambdas=False + +# Insert a blank line before a class-level docstring. +blank_line_before_class_docstring=False + +# Insert a blank line before a 'def' or 'class' immediately nested +# within another 'def' or 'class'. For example: +# +# class Foo: +# # <------ this blank line +# def method(): +# ... +blank_line_before_nested_class_or_def=False + +# Do not split consecutive brackets. Only relevant when +# dedent_closing_brackets is set. For example: +# +# call_func_that_takes_a_dict( +# { +# 'key1': 'value1', +# 'key2': 'value2', +# } +# ) +# +# would reformat to: +# +# call_func_that_takes_a_dict({ +# 'key1': 'value1', +# 'key2': 'value2', +# }) +coalesce_brackets=False + +# The column limit. +column_limit=79 + +# Indent width used for line continuations. +continuation_indent_width=4 + +# Put closing brackets on a separate line, dedented, if the bracketed +# expression can't fit in a single line. Applies to all kinds of brackets, +# including function definitions and calls. For example: +# +# config = { +# 'key1': 'value1', +# 'key2': 'value2', +# } # <--- this bracket is dedented and on a separate line +# +# time_series = self.remote_client.query_entity_counters( +# entity='dev3246.region1', +# key='dns.query_latency_tcp', +# transform=Transformation.AVERAGE(window=timedelta(seconds=60)), +# start_ts=now()-timedelta(days=3), +# end_ts=now(), +# ) # <--- this bracket is dedented and on a separate line +dedent_closing_brackets=True + +# Place each dictionary entry onto its own line. +each_dict_entry_on_separate_line=True + +# The regex for an i18n comment. The presence of this comment stops +# reformatting of that line, because the comments are required to be +# next to the string they translate. +i18n_comment= + +# The i18n function call names. The presence of this function stops +# reformattting on that line, because the string it has cannot be moved +# away from the i18n comment. +i18n_function_call= + +# Indent the dictionary value if it cannot fit on the same line as the +# dictionary key. For example: +# +# config = { +# 'key1': +# 'value1', +# 'key2': value1 + +# value2, +# } +indent_dictionary_value=True + +# The number of columns to use for indentation. +indent_width=4 + +# Join short lines into one line. E.g., single line 'if' statements. +join_multiple_lines=False + +# Use spaces around default or named assigns. +spaces_around_default_or_named_assign=False + +# Use spaces around the power operator. +spaces_around_power_operator=False + +# The number of spaces required before a trailing comment. +spaces_before_comment=2 + +# Insert a space between the ending comma and closing bracket of a list, +# etc. +space_between_ending_comma_and_closing_bracket=False + +# Split before arguments if the argument list is terminated by a +# comma. +split_arguments_when_comma_terminated=True + +# Set to True to prefer splitting before '&', '|' or '^' rather than +# after. +split_before_bitwise_operator=True + +# Split before a dictionary or set generator (comp_for). For example, note +# the split before the 'for': +# +# foo = { +# variable: 'Hello world, have a nice day!' +# for variable in bar if variable != 42 +# } +split_before_dict_set_generator=True + +# If an argument / parameter list is going to be split, then split before +# the first argument. +split_before_first_argument=True + +# Set to True to prefer splitting before 'and' or 'or' rather than +# after. +split_before_logical_operator=True + +# Split named assignments onto individual lines. +split_before_named_assigns=True + +# The penalty for splitting right after the opening bracket. +split_penalty_after_opening_bracket=30 + +# The penalty for splitting the line after a unary operator. +split_penalty_after_unary_operator=10000 + +# The penalty for splitting right before an if expression. +split_penalty_before_if_expr=0 + +# The penalty of splitting the line around the '&', '|', and '^' +# operators. +split_penalty_bitwise_operator=300 + +# The penalty for characters over the column limit. +split_penalty_excess_character=4500 + +# The penalty incurred by adding a line split to the unwrapped line. The +# more line splits added the higher the penalty. +split_penalty_for_added_line_split=30 + +# The penalty of splitting a list of "import as" names. For example: +# +# from a_very_long_or_indented_module_name_yada_yad import (long_argument_1, +# long_argument_2, +# long_argument_3) +# +# would reformat to something like: +# +# from a_very_long_or_indented_module_name_yada_yad import ( +# long_argument_1, long_argument_2, long_argument_3) +split_penalty_import_names=0 + +# The penalty of splitting the line around the 'and' and 'or' +# operators. +split_penalty_logical_operator=0 + +# Use the Tab character for indentation. +use_tabs=False + diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..af25368 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,37 @@ +language: python +python: + - 3.5.0 + - 3.5.2 + - 3.5-dev + - 3.6 + - 3.6-dev + - 3.7-dev +sudo: false +dist: trusty + +matrix: + include: + - os: linux + language: generic + env: USE_PYPY_RELEASE_VERSION=5.9-beta + # Uncomment if you want to test on pypy nightly + # - os: linux + # language: generic + # env: USE_PYPY_NIGHTLY=1 + - os: osx + language: generic + env: MACPYTHON=3.5.4 + - os: osx + language: generic + env: MACPYTHON=3.6.3 + - os: linux + language: python + python: 3.6 + env: CHECK_DOCS=1 + - os: linux + language: python + python: 3.6 + env: CHECK_FORMATTING=1 + +script: + - ci/travis.sh diff --git a/CHEATSHEET.rst b/CHEATSHEET.rst new file mode 100644 index 0000000..93f6e33 --- /dev/null +++ b/CHEATSHEET.rst @@ -0,0 +1,80 @@ +Finishing setting up your project +================================= + +Thanks for using cookiecutter-trio! This is your project now; you can +customize it however you like. Here's some reminders of things you +might want to do to get started: + +* Check this into source control (``git init .; git add .; git + commit -m "Initial commit"``) + +* Add a CODE_OF_CONDUCT.md + +* Add a CONTRIBUTING.md + +* Search the source tree for COOKIECUTTER-TRIO-TODO to find other + places to fill in.* Enable `Read the Docs `__. (Note: this + project contains a ``.readthedocs.yml`` file that should be enough + to get things working.) + +* Set up continuous integration: Currently, this project is set up to + test on Linux and MacOS using Travis, on Windows using Appveyor, and + to test on PyPy. + + If that's what you want, then go to Travis and Appveyor and enable + testing for your repo. + + If that's not what you want, then you can trim the list by modifying + (or deleting) ``.travis.yml``, ``.appveyor.yml``, ``ci/travis.sh``. + +* Enable `Codecov `__ for your repo. + +* File bugs or pull requests on `cookiecutter-trio + `__ reporting any + problems or awkwardness you ran into (no matter how small!) + +* Delete this checklist once it's no longer useful + + +Tips +==== + +To run tests +------------ + +* Install requirements: ``pip install -r test-requirements.txt`` + (possibly in a virtualenv) + +* Actually run the tests: ``pytest pytest_trio`` + + +To run yapf +----------- + +* Show what changes yapf wants to make: ``yapf -rpd setup.py + pytest_trio`` + +* Apply all changes directly to the source tree: ``yapf -rpi setup.py + pytest_trio`` + + +To make a release +----------------- + +* Update the version in ``pytest_trio/_version.py`` + +* Run ``towncrier`` to collect your release notes. + +* Review your release notes. + +* Check everything in. + +* Double-check it all works, docs build, etc. + +* Build your sdist and wheel: ``python setup.py sdist bdist_wheel`` + +* Upload to PyPI: ``twine upload dist/*`` + +* Use ``git tag`` to tag your version. + +* Don't forget to ``git push --tags``. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..51f3442 --- /dev/null +++ b/LICENSE @@ -0,0 +1,3 @@ +This software is made available under the terms of *either* of the +licenses found in LICENSE.APACHE2 or LICENSE.MIT. Contributions to are +made under the terms of *both* these licenses. diff --git a/LICENSE.APACHE2 b/LICENSE.APACHE2 new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APACHE2 @@ -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/LICENSE.MIT b/LICENSE.MIT new file mode 100644 index 0000000..b8bb971 --- /dev/null +++ b/LICENSE.MIT @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..4edd4b1 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include README.rst CHEATSHEET.rst LICENSE* CODE_OF_CONDUCT* CONTRIBUTING* +include .coveragerc .style.yapf +include test-requirements.txt +recursive-include docs * +prune docs/build diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..6aad3a2 --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] + +url = "https://pypi.python.org/simple" +verify_ssl = true +name = "pypi" + + +[packages] + + + +[dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..e849938 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,31 @@ +{ + "_meta": { + "hash": { + "sha256": "5f0257fe8c7a73db1c8de519faa92c658282a01087eb2bfafba7962704c23e27" + }, + "host-environment-markers": { + "implementation_name": "cpython", + "implementation_version": "3.6.1", + "os_name": "posix", + "platform_machine": "x86_64", + "platform_python_implementation": "CPython", + "platform_release": "4.4.0-101-generic", + "platform_system": "Linux", + "platform_version": "#124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017", + "python_full_version": "3.6.1", + "python_version": "3.6", + "sys_platform": "linux" + }, + "pipfile-spec": 6, + "requires": {}, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.python.org/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": {} +} diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..6b3e5d0 --- /dev/null +++ b/README.rst @@ -0,0 +1,11 @@ +pytest-trio +=========== + +Welcome to `pytest-trio `__! + +Pytest plugin for trio + +License: Your choice of MIT or Apache License 2.0 + +COOKIECUTTER-TRIO-TODO: finish filling in your README! +Must be valid ReST; also used as the PyPI description. diff --git a/ci/rtd-requirements.txt b/ci/rtd-requirements.txt new file mode 100644 index 0000000..67898ba --- /dev/null +++ b/ci/rtd-requirements.txt @@ -0,0 +1,4 @@ +# RTD is currently installing 1.5.3, which has a bug in :lineno-match: +sphinx >= 1.6.1 +sphinx_rtd_theme +sphinxcontrib-trio diff --git a/ci/travis.sh b/ci/travis.sh new file mode 100755 index 0000000..b296cc5 --- /dev/null +++ b/ci/travis.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +set -ex + +# See https://github.com/python-trio/trio/issues/334 +YAPF_VERSION=0.17.0 + +if [ "$TRAVIS_OS_NAME" = "osx" ]; then + curl -Lo macpython.pkg https://www.python.org/ftp/python/${MACPYTHON}/python-${MACPYTHON}-macosx10.6.pkg + sudo installer -pkg macpython.pkg -target / + ls /Library/Frameworks/Python.framework/Versions/*/bin/ + PYTHON_EXE=/Library/Frameworks/Python.framework/Versions/*/bin/python3 + sudo $PYTHON_EXE -m pip install virtualenv + $PYTHON_EXE -m virtualenv testenv + source testenv/bin/activate +fi + +if [ "$USE_PYPY_NIGHTLY" = "1" ]; then + curl -fLo pypy.tar.bz2 http://buildbot.pypy.org/nightly/py3.5/pypy-c-jit-latest-linux64.tar.bz2 + if [ ! -s pypy.tar.bz2 ]; then + # We know: + # - curl succeeded (200 response code; -f means "exit with error if + # server returns 4xx or 5xx") + # - nonetheless, pypy.tar.bz2 does not exist, or contains no data + # This isn't going to work, and the failure is not informative of + # anything involving this package. + ls -l + echo "PyPy3 nightly build failed to download – something is wrong on their end." + echo "Skipping testing against the nightly build for right now." + exit 0 + fi + tar xaf pypy.tar.bz2 + # something like "pypy-c-jit-89963-748aa3022295-linux64" + PYPY_DIR=$(echo pypy-c-jit-*) + PYTHON_EXE=$PYPY_DIR/bin/pypy3 + ($PYTHON_EXE -m ensurepip \ + && $PYTHON_EXE -m pip install virtualenv \ + && $PYTHON_EXE -m virtualenv testenv) \ + || (echo "pypy nightly is broken; skipping tests"; exit 0) + source testenv/bin/activate +fi + +if [ "$USE_PYPY_RELEASE_VERSION" != "" ]; then + curl -fLo pypy.tar.bz2 https://bitbucket.org/squeaky/portable-pypy/downloads/pypy3.5-${USE_PYPY_RELEASE_VERSION}-linux_x86_64-portable.tar.bz2 + tar xaf pypy.tar.bz2 + # something like "pypy3.5-5.7.1-beta-linux_x86_64-portable" + PYPY_DIR=$(echo pypy3.5-*) + PYTHON_EXE=$PYPY_DIR/bin/pypy3 + $PYTHON_EXE -m ensurepip + $PYTHON_EXE -m pip install virtualenv + $PYTHON_EXE -m virtualenv testenv + source testenv/bin/activate +fi + +pip install -U pip setuptools wheel + +if [ "$CHECK_FORMATTING" = "1" ]; then + pip install yapf==${YAPF_VERSION} + if ! yapf -rpd setup.py pytest_trio; then + cat <NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/docs/source/_static/.gitkeep b/docs/source/_static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..c0e6c29 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,194 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Documentation build configuration file, created by +# sphinx-quickstart on Sat Jan 21 19:11:14 2017. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys +# So autodoc can import our package +sys.path.insert(0, os.path.abspath('../..')) + +# Warn about all references to unknown targets +nitpicky = True +# Except for these ones, which we expect to point to unknown targets: +nitpick_ignore = [ + # Format is ("sphinx reference type", "string"), e.g.: + ("py:obj", "bytes-like"), +] + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx.ext.coverage', + 'sphinx.ext.napoleon', + 'sphinxcontrib_trio', +] + +intersphinx_mapping = { + "python": ('https://docs.python.org/3', None), + "trio": ('https://trio.readthedocs.io/', None), +} + +autodoc_member_order = "bysource" + +# Add any paths that contain templates here, relative to this directory. +templates_path = [] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = 'pytest-trio' +copyright = 'The pytest-trio authors' +author = 'The pytest-trio authors' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +import pytest_trio +version = pytest_trio.__version__ +# The full version, including alpha/beta/rc tags. +release = version + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# The default language for :: blocks +highlight_language = 'python3' + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +#html_theme = 'alabaster' + +# We have to set this ourselves, not only because it's useful for local +# testing, but also because if we don't then RTD will throw away our +# html_theme_options. +import sphinx_rtd_theme +html_theme = 'sphinx_rtd_theme' +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +html_theme_options = { + # default is 2 + # show deeper nesting in the RTD theme's sidebar TOC + # https://stackoverflow.com/questions/27669376/ + # I'm not 100% sure this actually does anything with our current + # versions/settings... + "navigation_depth": 4, + "logo_only": True, +} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + + +# -- Options for HTMLHelp output ------------------------------------------ + +# Output file base name for HTML help builder. +htmlhelp_basename = 'pytest-triodoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'pytest-trio.tex', 'Trio Documentation', + author, 'manual'), +] + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'pytest-trio', 'pytest-trio Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'pytest-trio', 'pytest-trio Documentation', + author, 'pytest-trio', 'Pytest plugin for trio', + 'Miscellaneous'), +] diff --git a/docs/source/history.rst b/docs/source/history.rst new file mode 100644 index 0000000..10c48f3 --- /dev/null +++ b/docs/source/history.rst @@ -0,0 +1,6 @@ +Release history +=============== + +.. currentmodule:: pytest_trio + +.. towncrier release notes start diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..118c45b --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,23 @@ +.. documentation master file, created by + sphinx-quickstart on Sat Jan 21 19:11:14 2017. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + + +=================================== +pytest-trio: Pytest plugin for trio +=================================== + +.. toctree:: + :maxdepth: 2 + + history.rst + +==================== + Indices and tables +==================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` +* :ref:`glossary` diff --git a/newsfragments/.gitkeep b/newsfragments/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/newsfragments/README.rst b/newsfragments/README.rst new file mode 100644 index 0000000..291bfea --- /dev/null +++ b/newsfragments/README.rst @@ -0,0 +1,40 @@ +Adding newsfragments +==================== + +This directory collects "newsfragments": short files that each contain +a snippet of ReST-formatted text that will be added to the next +release notes. This should be a description of aspects of the change +(if any) that are relevant to users. (This contrasts with your commit +message and PR description, which are a description of the change as +relevant to people working on the code itself.) + +Each file should be named like ``..rst``, where +```` is an issue numbers, and ```` is one of: + +* ``feature`` +* ``bugfix`` +* ``doc`` +* ``removal`` +* ``misc`` + +So for example: ``123.feature.rst``, ``456.bugfix.rst`` + +If your PR fixes an issue, use that number here. If there is no issue, +then after you submit the PR and get the PR number you can add a +newsfragment using that instead. + +Note that the ``towncrier`` tool will automatically +reflow your text, so don't try to do any fancy formatting. You can +install ``towncrier`` and then run ``towncrier --draft`` if you want +to get a preview of how your change will look in the final release +notes. + + +Making releases +=============== + +``pip install towncrier``, then run ``towncrier``. (You can use +``towncrier --draft`` to get a preview of what this will do.) + +You can configure ``towncrier`` (for example: customizing the +different types of changes) by modifying ``pyproject.toml``. diff --git a/plugin.py b/plugin.py new file mode 100644 index 0000000..1490b50 --- /dev/null +++ b/plugin.py @@ -0,0 +1,143 @@ +"""pytest-trio implementation.""" +import contextlib +import inspect +import socket +from functools import partial + +import pytest +import trio + + +def pytest_configure(config): + """Inject documentation.""" + config.addinivalue_line("markers", + "trio: " + "mark the test as a coroutine, it will be " + "run using an asyncio event loop") + + +def _trio_test_runner_factory(item, clock): + testfunc = item.function + + async def _bootstrap_fixture_and_run_test(**kwargs): + kwargs = await _resolve_coroutine_fixtures_in(kwargs) + await testfunc(**kwargs) + + def run_test_in_trio(**kwargs): + trio._core.run(partial(_bootstrap_fixture_and_run_test, **kwargs), clock=clock) + + return run_test_in_trio + + +async def _resolve_coroutine_fixtures_in(deps): + resolved_deps = {**deps} + + async def _resolve_and_update_deps(afunc, deps, entry): + deps[entry] = await afunc() + + async with trio.open_nursery() as nursery: + for depname, depval in resolved_deps.items(): + if isinstance(depval, CoroutineFixture): + nursery.start_soon( + _resolve_and_update_deps, depval.resolve, resolved_deps, depname) + return resolved_deps + + +class CoroutineFixture: + """ + Represent a fixture that need to be run in a trio context to be resolved. + Can be async function fixture or a syncronous fixture with async + dependencies fixtures. + """ + NOTSET = object() + + def __init__(self, fixturefunc, fixturedef, deps={}): + self.fixturefunc = fixturefunc + # Note fixturedef.func + self.fixturedef = fixturedef + self.deps = deps + self._ret = self.NOTSET + + async def resolve(self): + if self._ret is self.NOTSET: + resolved_deps = await _resolve_coroutine_fixtures_in(self.deps) + if inspect.iscoroutinefunction(self.fixturefunc): + self._ret = await self.fixturefunc(**resolved_deps) + else: + self._ret = self.fixturefunc(**resolved_deps) + return self._ret + + +def _install_coroutine_fixture_if_needed(fixturedef, request): + deps = {dep: request.getfixturevalue(dep) for dep in fixturedef.argnames} + corofix = None + if not deps and inspect.iscoroutinefunction(fixturedef.func): + # Top level async coroutine + corofix = CoroutineFixture(fixturedef.func, fixturedef) + elif any(dep for dep in deps.values() if isinstance(dep, CoroutineFixture)): + # Fixture with coroutine fixture dependencies + corofix = CoroutineFixture(fixturedef.func, fixturedef, deps) + # The coroutine fixture must be evaluated from within the trio context + # which is spawed in the function test's trio decorator. + # The trick is to make pytest's fixture call return the CoroutineFixture + # object which will be actully resolved just before we run the test. + if corofix: + fixturedef.func = lambda **kwargs: corofix + + +@pytest.hookimpl(tryfirst=True) +def pytest_fixture_setup(fixturedef, request): + if 'trio' in request.keywords: + _install_coroutine_fixture_if_needed(fixturedef, request) + + +@pytest.hookimpl(tryfirst=True) +def pytest_collection_modifyitems(session, config, items): + # Retrieve test marked as `trio` + for item in items: + if 'trio' not in item.keywords: + continue + if not inspect.iscoroutinefunction(item.function): + pytest.fail('test function `%r` is marked trio but is not async' % item) + # Extract the clock fixture if provided + clocks = [c for c in item.funcargs.values() if isinstance(c, trio.abc.Clock)] + if not clocks: + clock = None + elif len(clocks) == 1: + clock = clocks[0] + else: + raise pytest.fail("too many clocks spoil the broth!") + item.obj = _trio_test_runner_factory(item, clock) + + +@pytest.hookimpl(tryfirst=True) +def pytest_exception_interact(node, call, report): + if issubclass(call.excinfo.type, trio.MultiError): + # TODO: not really elegant (pytest cannot output color with this hack) + report.longrepr = ''.join(trio.format_exception(*call.excinfo._excinfo)) + + +@pytest.fixture +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_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/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..843839a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[tool.towncrier] +package = "pytest_trio" +filename = "docs/source/history.rst" +directory = "newsfragments" +underlines = ["-", "~", "^"] +# COOKIECUTTER-TRIO-TODO: fill in the URL below to point to your issue tracker: +issue_format = "`#{issue} `__" diff --git a/pytest_trio/__init__.py b/pytest_trio/__init__.py new file mode 100644 index 0000000..ffd3b89 --- /dev/null +++ b/pytest_trio/__init__.py @@ -0,0 +1,3 @@ +"""Top-level package for pytest-trio.""" + +from ._version import __version__ diff --git a/pytest_trio/_tests/__init__.py b/pytest_trio/_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pytest_trio/_tests/conftest.py b/pytest_trio/_tests/conftest.py new file mode 100644 index 0000000..25c5453 --- /dev/null +++ b/pytest_trio/_tests/conftest.py @@ -0,0 +1,21 @@ +# XX this should switch to using pytest-trio as soon as pytest-trio is +# released... + +import inspect +import pytest +from trio.testing import MockClock, trio_test + +@pytest.fixture +def mock_clock(): + return MockClock() + + +@pytest.fixture +def autojump_clock(): + return MockClock(autojump_threshold=0) + + +@pytest.hookimpl(tryfirst=True) +def pytest_pyfunc_call(pyfuncitem): + if inspect.iscoroutinefunction(pyfuncitem.obj): + pyfuncitem.obj = trio_test(pyfuncitem.obj) diff --git a/pytest_trio/_tests/test_example.py b/pytest_trio/_tests/test_example.py new file mode 100644 index 0000000..ce10f92 --- /dev/null +++ b/pytest_trio/_tests/test_example.py @@ -0,0 +1,15 @@ +import trio + +# We can just use 'async def test_*' to define async tests. +# This also uses a virtual clock fixture, so time passes quickly and +# predictably. +async def test_sleep_with_autojump_clock(autojump_clock): + assert trio.current_time() == 0 + + for i in range(10): + print("Sleeping {} seconds".format(i)) + start_time = trio.current_time() + await trio.sleep(i) + end_time = trio.current_time() + + assert end_time - start_time == i diff --git a/pytest_trio/_version.py b/pytest_trio/_version.py new file mode 100644 index 0000000..490c03a --- /dev/null +++ b/pytest_trio/_version.py @@ -0,0 +1,3 @@ +# This file is imported from __init__.py and exec'd from setup.py + +__version__ = "0.0.0" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..295d84b --- /dev/null +++ b/setup.py @@ -0,0 +1,45 @@ +from setuptools import setup, find_packages + +exec(open("pytest_trio/_version.py", encoding="utf-8").read()) + +LONG_DESC = open("README.rst", encoding="utf-8").read() + +setup( + name="pytest-trio", + version=__version__, + description="Pytest plugin for trio", + url="https://github.com/python-trio/pytest-trio", + long_description=open("README.rst").read(), + author="Emmanuel Leblond", + author_email="emmanuel.leblond@gmail.com", + license="MIT -or- Apache License 2.0", + packages=find_packages(), + install_requires=[ + "trio", + ], + keywords=[ + # COOKIECUTTER-TRIO-TODO: add some keywords + # "async", "io", "networking", ... + ], + python_requires=">=3.5", + classifiers=[ + "License :: OSI Approved :: MIT License", + "License :: OSI Approved :: Apache Software License", + # COOKIECUTTER-TRIO-TODO: Remove any of these classifiers that don't + # apply: + "Operating System :: POSIX :: Linux", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + # COOKIECUTTER-TRIO-TODO: Consider adding trove classifiers for: + # + # - Development Status + # - Intended Audience + # - Topic + # + # For the full list of options, see: + # https://pypi.python.org/pypi?%3Aaction=list_classifiers + ], +) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..9955dec --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +pytest +pytest-cov