Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC Add tox #254

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
**/*.pyc
**/__pycache__/
**/node_modules
**/package-lock.json
*.vsix
.*.sw?
.coverage
.coverage.*.*.*
.mypy_cache/
.tox/
.vscode
dist/
docs/_build/
htmlcov/
MANIFEST
TestSlide.egg-info/
**/node_modules
*.vsix
**/package-lock.json
TestSlide.egg-info/
3 changes: 3 additions & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
3.6.12
3.7.9
3.8.6
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
language: python
# FIXME use pyenv pinned versions from .python-version
python:
- 3.6
- 3.7
- 3.8
script:
TESTSLIDE_FORMAT=progress UNITTEST_VERBOSE=0 make travis V=1
install: pip install tox-travis
script: tox
env:
- TESTSLIDE_FORMAT=progress UNITTEST_VERBOSE=0 V=1
25 changes: 20 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,24 @@ We actively welcome your pull requests.

Generally speaking:

- Install a supported Python version (see `.travis.yml`) (suggestion: use [pyenv](https://github.com/pyenv/pyenv)).
- Install the dependencies: `make install_build_deps`.
- Run the tests: `make` (or `make V=1` for verbose output).
- Install supported Python versions (see `.python-version`).
- Using [pyenv](https://github.com/pyenv/pyenv) is highly advised!
- Enable the Python version defined at `tox.ini` `basepython`.
- Do `pip install tox` (and `tox-pyenv` if using pyenv).
- Run all tests: `tox`.

If you want more fine grained control over running tests you can:

- Create a venv: `python -m venv venv/`.
- Install deps: `pip install -e .`.
- Run individual tests:
- `make tests/strict_mock_testslide.py`

`make` has other goodies:

- `V=1`: verbose output.
- `TESTSLIDE_FORMAT`: set the formatter (progress, documentation etc).
- `UNITTEST_VERBOSE=0`: disable verbose.

Here's a quick cookbook on how to have a Python installation working using Docker:

Expand All @@ -41,8 +56,8 @@ eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
```
- Do `exec bash -i`.
- Install Python: `pyenv install 3.7.3`.
- Enable the installed version `pyenv shell 3.7.3`.
- Install Python: `pyenv install $SUPPORTED_PYTHON_VERSION`.
- Enable the installed version `pyenv shell $SUPPORTED_PYTHON_VERSION`.

## Contributor License Agreement ("CLA")

Expand Down
33 changes: 2 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ format_black:
.PHONY: tests
tests: \
unittest_tests \
testslide_tests \
mypy \
flake8 \
isort \
black
testslide_tests

.PHONY: format
format: \
Expand All @@ -148,6 +144,7 @@ coverage_combine: unittest_tests testslide_tests
coverage_report: coverage_combine
@printf "${TERM_BRIGHT}COVERAGE REPORT\n${TERM_NONE}"
${Q} coverage report
${Q} bash -c '[ -n "$$COVERALLS_REPO_TOKEN" ] && { echo -e "${TERM_BRIGHT}COVERALLS\\n${TERM_NONE}" && coveralls ; } || true'

.PHONY: coverage_html
coverage_html: coverage_combine
Expand All @@ -159,20 +156,10 @@ coverage_html_clean:
@printf "${TERM_BRIGHT}COVERAGE HTML CLEAN\n${TERM_NONE}"
${Q} rm -rf htmlcov/

.PHONY: coveralls
coveralls: coverage_combine
@printf "${TERM_BRIGHT}COVERALLS\n${TERM_NONE}"
${Q} coveralls

##
## Build
##

.PHONY: install_build_deps
install_build_deps:
@printf "${TERM_BRIGHT}INSTALL BUILD DEPS\n${TERM_NONE}"
${Q} pip install -e .[test,build]

.PHONY: sdist
sdist:
@printf "${TERM_BRIGHT}SDIST\n${TERM_NONE}"
Expand All @@ -187,22 +174,6 @@ sdist_clean:
twine: sdist
twine upload $(DIST_TAR_GZ)

.PHONY: install_local
install_local: sdist
@printf "${TERM_BRIGHT}INSTALL LOCAL\n${TERM_NONE}"
${Q} pip install $(DIST_TAR_GZ)
${Q} testslide --help

.PHONY: travis
travis: \
install_build_deps \
tests \
coverage_report \
coveralls \
docs \
sdist \
install_local

##
## Clean
##
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import sys
from typing import Dict, List

# -*- coding: utf-8 -*-
#
Expand Down Expand Up @@ -45,7 +45,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = []
extensions: List[str] = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down Expand Up @@ -122,7 +122,7 @@

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
latex_elements: Dict[str, str] = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
Expand Down
6 changes: 5 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ ignore_missing_imports = True
ignore_missing_imports = True
[mypy-psutil.*]
ignore_missing_imports = True
[mypy-sphinx_kr_theme.*]
ignore_missing_imports = True
[mypy-setuptools.*]
ignore_missing_imports = True
[mypy-testslide.testslide]
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
disallow_untyped_decorators = True
disallow_untyped_decorators = True
15 changes: 0 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@
"typeguard>=2.9.1",
'dataclasses==0.6; python_version < "3.7"',
],
extras_require={
"build": [
"black",
"coverage",
"coveralls",
"flake8",
"isort~=5.1",
"mypy==0.782",
"ipython",
"sphinx",
"sphinx-autobuild",
"sphinx-kr-theme",
"twine",
]
},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand Down
2 changes: 1 addition & 1 deletion tests/dsl_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ async def example(self):
asyncio.sleep(0.1)

with self.assertRaisesRegex(
RuntimeWarning, "coroutine '.+' was never awaited"
RuntimeError, "coroutine '.+' was never awaited"
):
self.run_first_context_first_example()

Expand Down
12 changes: 6 additions & 6 deletions testslide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def asyncio_run(coro):
asyncio_run = partial(asyncio.run, debug=True)


if sys.version_info < (3, 8):
if sys.version_info < (3, 7):
get_all_tasks = asyncio.Task.all_tasks
else:
get_all_tasks = asyncio.all_tasks
Expand Down Expand Up @@ -401,10 +401,10 @@ def _raise_if_asyncio_warnings(self, context_data: _ContextData) -> Iterator[Non
yield
return
original_showwarning = warnings.showwarning
caught_failures: List[Union[Exception, str]] = []
caught_failures: List[Exception] = []

def showwarning(
message: str,
message: Union[Warning, str],
category: Type[Warning],
filename: str,
lineno: int,
Expand All @@ -417,11 +417,11 @@ def showwarning(
warning_class = type(message)
pattern = failure_warning_messages.get(warning_class, None)
if pattern and re.compile(pattern).match(str(message)):
caught_failures.append(message)
caught_failures.append(RuntimeError(message))
else:
original_showwarning(message, category, filename, lineno, file, line)

warnings.showwarning = showwarning # type: ignore
warnings.showwarning = showwarning

original_logger_warning = asyncio.log.logger.warning

Expand Down Expand Up @@ -450,7 +450,7 @@ def logger_warning(msg: str, *args: Any, **kwargs: Any) -> None:
asyncio.log.logger.warning = original_logger_warning # type: ignore
for failure in caught_failures:
with aggregated_exceptions.catch():
raise failure # type: ignore
raise failure
aggregated_exceptions.raise_correct_exception()

def _async_run_all_hooks_and_example(self, context_data: _ContextData) -> None:
Expand Down
53 changes: 53 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# tox (https://tox.readthedocs.io/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = py36, py37, py38, mypy, flake8, isort, black, docs

[testenv]
deps = coverage
allowlist_externals = /usr/bin/make
passenv = TERM TESTSLIDE_FORMAT UNITTEST_VERBOSE V
commands =
make coverage_report TESTSLIDE_FORMAT=progress UNITTEST_VERBOSE=0

[testenv:mypy]
basepython = python3.8
allowlist_externals = /usr/bin/make
passenv = TERM TESTSLIDE_FORMAT UNITTEST_VERBOSE V
deps = mypy
commands = make mypy

[testenv:flake8]
basepython = python3.8
allowlist_externals = /usr/bin/make
passenv = TERM TESTSLIDE_FORMAT UNITTEST_VERBOSE V
deps = flake8
commands = make flake8

[testenv:isort]
basepython = python3.8
allowlist_externals = /usr/bin/make
passenv = TERM TESTSLIDE_FORMAT UNITTEST_VERBOSE V
deps = isort
commands = make isort

[testenv:black]
basepython = python3.8
allowlist_externals = /usr/bin/make
passenv = TERM TESTSLIDE_FORMAT UNITTEST_VERBOSE V
deps = black
commands = make black

[testenv:docs]
basepython = python3.8
passenv = TERM TESTSLIDE_FORMAT UNITTEST_VERBOSE V
allowlist_externals = /usr/bin/make
deps =
ipython
sphinx
sphinx-autobuild
sphinx-kr-theme
commands = make -C docs/ html