Adding a tox.ini file.
This commit is contained in:
parent
df625530bd
commit
697ae95047
21
fib.py
21
fib.py
|
@ -1,36 +1,27 @@
|
||||||
from functools import lru_cache
|
"""A demo module implementing fib."""
|
||||||
# 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
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
|
"""Parse command line arguments."""
|
||||||
parser = argparse.ArgumentParser(description="Compute fibonacci sequence numbers.")
|
parser = argparse.ArgumentParser(description="Compute fibonacci sequence numbers.")
|
||||||
parser.add_argument("n", type=int, help="To compute the nth element of fib.")
|
parser.add_argument("n", type=int, help="To compute the nth element of fib.")
|
||||||
return parser.parse_args()
|
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
|
a, b = 1, 1
|
||||||
for _ in range(n):
|
for _ in range(n):
|
||||||
a, b = b, a + b
|
a, b = b, a + b
|
||||||
return a
|
return a
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main() -> None:
|
||||||
|
"""The module entry point."""
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
print(fib(args.n))
|
print(fib(args.n))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
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.
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ def test_fib_start():
|
||||||
def test_fib_next(i):
|
def test_fib_next(i):
|
||||||
assert fib(i) > 1
|
assert fib(i) > 1
|
||||||
|
|
||||||
|
|
||||||
@given(integers(min_value=2, max_value=1_000))
|
@given(integers(min_value=2, max_value=1_000))
|
||||||
def test_fib(n):
|
def test_fib(n):
|
||||||
assert fib(n - 1) + fib(n - 2) == fib(n)
|
assert fib(n - 1) + fib(n - 2) == fib(n)
|
||||||
|
@ -19,7 +20,7 @@ def test_fib(n):
|
||||||
|
|
||||||
@given(
|
@given(
|
||||||
floats(allow_nan=False, allow_infinity=False),
|
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):
|
def test_commutativity(a, b):
|
||||||
assert a + b == b + a
|
assert a + b == b + a
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue