diff --git a/fib.py b/fib.py index 28d8da7..001286a 100644 --- a/fib.py +++ b/fib.py @@ -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. diff --git a/tests/test_fib.py b/tests/test_fib.py index 12b86ee..c474b97 100644 --- a/tests/test_fib.py +++ b/tests/test_fib.py @@ -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 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..bd47f2e --- /dev/null +++ b/tox.ini @@ -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 \ No newline at end of file