Adding a tox.ini file.

This commit is contained in:
Julien Palard 2023-11-08 10:02:33 +01:00
parent df625530bd
commit 697ae95047
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
3 changed files with 58 additions and 16 deletions

21
fib.py
View File

@ -1,36 +1,27 @@
from functools import lru_cache
# vscode fait par Microsoft, open-source :
# - publiée par Microsoft
# - vscodium publié par des bénévoles
# pycharm ("community" vs "pro")
# Est-ce qu'il est "bon" d'éditer des fichiers Python (.py, pas des .ipynb) avec JupyterLab ?
# vim/emacs
"""A demo module implementing fib."""
import argparse
def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(description="Compute fibonacci sequence numbers.")
parser.add_argument("n", type=int, help="To compute the nth element of fib.")
return parser.parse_args()
def fib(n):
def fib(n: int) -> int:
"""Return the *n*th element in the Fibonacci sequence."""
a, b = 1, 1
for _ in range(n):
a, b = b, a + b
return a
def main():
def main() -> None:
"""The module entry point."""
args = parse_args()
print(fib(args.n))
if __name__ == "__main__":
main()
# Pour exécuter depuis un shell:
# - Sur Debian/Ubuntu je conseille gnome-terminal
# - Sur Windows je conseille "git bash", je déconseille fortement cmd.exe (pas maintenu).
# - Sur macOS : il y un terminal fourni par macOS mais j'ignore son nom.

View File

@ -12,6 +12,7 @@ def test_fib_start():
def test_fib_next(i):
assert fib(i) > 1
@given(integers(min_value=2, max_value=1_000))
def test_fib(n):
assert fib(n - 1) + fib(n - 2) == fib(n)
@ -19,7 +20,7 @@ def test_fib(n):
@given(
floats(allow_nan=False, allow_infinity=False),
floats(allow_nan=False, allow_infinity=False)
floats(allow_nan=False, allow_infinity=False),
)
def test_commutativity(a, b):
assert a + b == b + a

50
tox.ini Normal file
View File

@ -0,0 +1,50 @@
[flake8]
max-line-length = 88
[tox]
envlist = py37, py38, py39, py310, py311, py312, flake8, mypy, black, pylint, isort, ruff, bandit
isolated_build = True
skip_missing_interpreters = True
[testenv]
deps =
pytest
hypothesis
commands = python -m pytest
[testenv:flake8]
deps =
flake8
flake8-bugbear
skip_install = True
commands = flake8 --max-complexity 9 tests/ fib.py
[testenv:black]
deps = black
skip_install = True
commands = black --check --diff tests/ fib.py
[testenv:mypy]
deps = mypy
skip_install = True
commands = mypy --ignore-missing-imports fib.py
[testenv:pylint]
deps = pylint
skip_install = True
commands = pylint fib.py
[testenv:isort]
deps = isort
skip_install = True
commands = isort --check --profile=black fib.py
[testenv:ruff]
deps = ruff
skip_install = True
commands = ruff check fib.py
[testenv:bandit]
deps = bandit
skip_install = True
commands = bandit fib.py