Include doctests in the test suite
- use xdoctest to validate all code snippets in docstrings - add xdoctest to the nox session "test"
This commit is contained in:
parent
48fe2f6879
commit
126dcf7c39
4 changed files with 58 additions and 7 deletions
24
noxfile.py
24
noxfile.py
|
@ -13,6 +13,8 @@ MAIN_PYTHON = '3.8'
|
||||||
# Keep the project is forward compatible.
|
# Keep the project is forward compatible.
|
||||||
NEXT_PYTHON = '3.9'
|
NEXT_PYTHON = '3.9'
|
||||||
|
|
||||||
|
PACKAGE_IMPORT_NAME = 'urban_meal_delivery'
|
||||||
|
|
||||||
# Path to the *.py files to be packaged.
|
# Path to the *.py files to be packaged.
|
||||||
PACKAGE_SOURCE_LOCATION = 'src/'
|
PACKAGE_SOURCE_LOCATION = 'src/'
|
||||||
|
|
||||||
|
@ -48,6 +50,8 @@ def format_(session):
|
||||||
Otherwise, they are interpreted as paths the formatters work on recursively.
|
Otherwise, they are interpreted as paths the formatters work on recursively.
|
||||||
"""
|
"""
|
||||||
_begin(session)
|
_begin(session)
|
||||||
|
# The formatting tools do not require the developed
|
||||||
|
# package be installed in the virtual environment.
|
||||||
_install_packages(session, 'autoflake', 'black', 'isort')
|
_install_packages(session, 'autoflake', 'black', 'isort')
|
||||||
# Interpret extra arguments as locations of source files.
|
# Interpret extra arguments as locations of source files.
|
||||||
locations = session.posargs or SRC_LOCATIONS
|
locations = session.posargs or SRC_LOCATIONS
|
||||||
|
@ -78,6 +82,8 @@ def lint(session):
|
||||||
Otherwise, they are interpreted as paths the linters work on recursively.
|
Otherwise, they are interpreted as paths the linters work on recursively.
|
||||||
"""
|
"""
|
||||||
_begin(session)
|
_begin(session)
|
||||||
|
# The linting tools do not require the developed
|
||||||
|
# package be installed in the virtual environment.
|
||||||
_install_packages(
|
_install_packages(
|
||||||
session,
|
session,
|
||||||
'flake8',
|
'flake8',
|
||||||
|
@ -122,13 +128,15 @@ def lint(session):
|
||||||
def test(session):
|
def test(session):
|
||||||
"""Test the code base.
|
"""Test the code base.
|
||||||
|
|
||||||
Runs the unit and integration tests (written with pytest).
|
Runs the unit and integration tests with pytest and
|
||||||
|
validate that all code snippets in docstrings work with xdoctest.
|
||||||
|
|
||||||
If no extra arguments are provided, the entire test suite
|
If no extra arguments are provided, the entire test suite
|
||||||
is exexcuted and succeeds only with 100% coverage.
|
is exexcuted and succeeds only with 100% coverage.
|
||||||
|
|
||||||
If extra arguments are provided, they are
|
If extra arguments are provided, they are
|
||||||
forwarded to pytest without any changes.
|
forwarded to pytest and xdoctest without any changes.
|
||||||
|
xdoctest ignores arguments it does not understand.
|
||||||
"""
|
"""
|
||||||
# Re-using an old environment is not so easy here as
|
# Re-using an old environment is not so easy here as
|
||||||
# `poetry install --no-dev` removes previously installed packages.
|
# `poetry install --no-dev` removes previously installed packages.
|
||||||
|
@ -139,9 +147,12 @@ def test(session):
|
||||||
)
|
)
|
||||||
|
|
||||||
_begin(session)
|
_begin(session)
|
||||||
# Install only the non-develop dependencies and the testing tool chain.
|
# The testing tools require the developed package and its
|
||||||
|
# non-develop dependencies be installed in the virtual environment.
|
||||||
session.run('poetry', 'install', '--no-dev', external=True)
|
session.run('poetry', 'install', '--no-dev', external=True)
|
||||||
_install_packages(session, 'pytest', 'pytest-cov')
|
_install_packages(
|
||||||
|
session, 'packaging', 'pytest', 'pytest-cov', 'xdoctest[optional]',
|
||||||
|
)
|
||||||
# Interpret extra arguments as options for pytest.
|
# Interpret extra arguments as options for pytest.
|
||||||
# They are "dropped" by the hack in the pre_merge() function
|
# They are "dropped" by the hack in the pre_merge() function
|
||||||
# if this function is run within the "pre-merge" session.
|
# if this function is run within the "pre-merge" session.
|
||||||
|
@ -154,7 +165,12 @@ def test(session):
|
||||||
'--cov-report=term-missing:skip-covered',
|
'--cov-report=term-missing:skip-covered',
|
||||||
PYTEST_LOCATION,
|
PYTEST_LOCATION,
|
||||||
)
|
)
|
||||||
|
session.run('pytest', '--version')
|
||||||
session.run('pytest', *args)
|
session.run('pytest', *args)
|
||||||
|
# For xdoctest, the default arguments are different from pytest.
|
||||||
|
args = posargs or [PACKAGE_IMPORT_NAME]
|
||||||
|
session.run('xdoctest', '--version')
|
||||||
|
session.run('xdoctest', '--quiet', *args) # --quiet => less verbose output
|
||||||
|
|
||||||
|
|
||||||
@nox.session(name='pre-commit', python=MAIN_PYTHON, venv_backend='none')
|
@nox.session(name='pre-commit', python=MAIN_PYTHON, venv_backend='none')
|
||||||
|
|
32
poetry.lock
generated
32
poetry.lock
generated
|
@ -137,7 +137,7 @@ version = "7.1.2"
|
||||||
[[package]]
|
[[package]]
|
||||||
category = "dev"
|
category = "dev"
|
||||||
description = "Cross-platform colored terminal text."
|
description = "Cross-platform colored terminal text."
|
||||||
marker = "sys_platform == \"win32\" or platform_system == \"Windows\""
|
marker = "sys_platform == \"win32\" or platform_system == \"Windows\" or platform_system == \"Windows\""
|
||||||
name = "colorama"
|
name = "colorama"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||||
|
@ -885,8 +885,32 @@ optional = false
|
||||||
python-versions = "*"
|
python-versions = "*"
|
||||||
version = "1.12.1"
|
version = "1.12.1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
category = "dev"
|
||||||
|
description = "A rewrite of the builtin doctest module"
|
||||||
|
name = "xdoctest"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
version = "0.13.0"
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
six = "*"
|
||||||
|
|
||||||
|
[package.dependencies.Pygments]
|
||||||
|
optional = true
|
||||||
|
version = "*"
|
||||||
|
|
||||||
|
[package.dependencies.colorama]
|
||||||
|
optional = true
|
||||||
|
version = "*"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
all = ["six", "pytest", "pytest-cov", "codecov", "scikit-build", "cmake", "ninja", "pybind11", "pygments", "colorama"]
|
||||||
|
optional = ["pygments", "colorama"]
|
||||||
|
tests = ["pytest", "pytest-cov", "codecov", "scikit-build", "cmake", "ninja", "pybind11"]
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
content-hash = "899f376a54c187e41392fb83831a59926668b662bfb32004f4a0964c1202698c"
|
content-hash = "79e46e67260312ba1b227f7717d0ba781a6ad5df352f83fe6e1b72a98ad1ec5b"
|
||||||
lock-version = "1.0"
|
lock-version = "1.0"
|
||||||
python-versions = "^3.8"
|
python-versions = "^3.8"
|
||||||
|
|
||||||
|
@ -1311,3 +1335,7 @@ wemake-python-styleguide = [
|
||||||
wrapt = [
|
wrapt = [
|
||||||
{file = "wrapt-1.12.1.tar.gz", hash = "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"},
|
{file = "wrapt-1.12.1.tar.gz", hash = "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"},
|
||||||
]
|
]
|
||||||
|
xdoctest = [
|
||||||
|
{file = "xdoctest-0.13.0-py2.py3-none-any.whl", hash = "sha256:de861fd5230a46bd26c054b4981169dd963f813768cb62b62e104e4d2644ac94"},
|
||||||
|
{file = "xdoctest-0.13.0.tar.gz", hash = "sha256:4f113a430076561a9d7f31af65b5d5acda62ee06b05cb6894264cb9efb8196ac"},
|
||||||
|
]
|
||||||
|
|
|
@ -53,6 +53,7 @@ wemake-python-styleguide = "^0.14.1" # flake8 plug-in
|
||||||
packaging = "^20.4" # used to test the packaged version
|
packaging = "^20.4" # used to test the packaged version
|
||||||
pytest = "^6.0.1"
|
pytest = "^6.0.1"
|
||||||
pytest-cov = "^2.10.0"
|
pytest-cov = "^2.10.0"
|
||||||
|
xdoctest = { version="^0.13.0", extras=["optional"] }
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
umd = "urban_meal_delivery.console:main"
|
umd = "urban_meal_delivery.console:main"
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
"""Source code for the urban-meal-delivery research project."""
|
"""Source code for the urban-meal-delivery research project.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>>> import urban_meal_delivery as umd
|
||||||
|
>>> umd.__version__ != '0.0.0'
|
||||||
|
True
|
||||||
|
"""
|
||||||
|
|
||||||
from importlib import metadata as _metadata
|
from importlib import metadata as _metadata
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue