From 404b6e175f4b197f07cb68a442ab9c47edbac6ce Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Tue, 12 Dec 2023 17:27:18 +0100 Subject: [PATCH] Hello tox. To run tox: tox -p all --- classes.py | 42 +++++++++++++++++++++--------------------- list-comprehension.py | 7 +++++++ point.py | 12 +++++++++--- tox.ini | 31 +++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 tox.ini diff --git a/classes.py b/classes.py index 212b6f4..394e591 100644 --- a/classes.py +++ b/classes.py @@ -35,16 +35,16 @@ class DiceCup: dice.throw() def total(self): - return sum([dice.value for dice in self.dices]) + return sum(dice.value for dice in self.dices) def mean(self): - return mean([dice.value for dice in self.dices]) + return mean(dice.value for dice in self.dices) def show_graph(): cup = DiceCup([Dice() for _ in range(1000)]) results = {} - for i in range(10000): + for _ in range(10_000): cup.shake() try: results[cup.total()] = results[cup.total()] + 1 @@ -55,24 +55,24 @@ def show_graph(): plt.show() -def dist_from_origin(x, y): - """Compute distance between a point and the origin.""" - return (x**2 + y**2) ** 0.5 - - -def dist(x1, y1, x2, y2): - """Compute distance between two points.""" - return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 - - -def dist_from_origin(point): - """Compute distance between a point and the origin.""" - return (point["x"] ** 2 + point["y"] ** 2) ** 0.5 - - -def dist(p1, p2): - """Compute distance between two points.""" - return ((p1["x"] - p2["x"]) ** 2 + (p1["y"] - p2["y"]) ** 2) ** 0.5 +# def dist_from_origin(x, y): +# """Compute distance between a point and the origin.""" +# return (x**2 + y**2) ** 0.5 +# +# +# def dist(x1, y1, x2, y2): +# """Compute distance between two points.""" +# return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 +# +# +# def dist_from_origin(point): +# """Compute distance between a point and the origin.""" +# return (point["x"] ** 2 + point["y"] ** 2) ** 0.5 +# +# +# def dist(p1, p2): +# """Compute distance between two points.""" +# return ((p1["x"] - p2["x"]) ** 2 + (p1["y"] - p2["y"]) ** 2) ** 0.5 def dist_from_origin(point): diff --git a/list-comprehension.py b/list-comprehension.py index 7c070d6..7563dac 100644 --- a/list-comprehension.py +++ b/list-comprehension.py @@ -11,4 +11,11 @@ ensemble_en_intension = {i for i in range(0, 100) if i % 3 == 0 or i % 5 == 0} print({i: i**2 for i in range(0, 100) if i % 3 == 0 or i % 5 == 0}) +recettes = [ + {"durée": 10}, + {"durée": 12}, + {"durée": 14}, + {"durée": 60}, +] + durées = [recette["durée"] for recette in recettes] diff --git a/point.py b/point.py index 014480d..9e0d724 100644 --- a/point.py +++ b/point.py @@ -1,14 +1,20 @@ +"""Demo implementation of a simple Point class.""" + + class Point: - def __init__(self, x, y): # Dunder init "Double underscore init" + """A 2D point.""" + + def __init__(self, x: float, y: float): # Dunder init "Double underscore init" self.x = x self.y = y def __repr__(self): return f"Point(x={self.x}, y={self.y})" - def dist_from_origin(self): + def dist_from_origin(self) -> float: + """Compute distance between self and origin.""" return (self.x**2 + self.y**2) ** 0.5 - def dist(self, other): + def dist(self, other) -> float: """Compute distance between two points.""" return ((self.x - other.x) ** 2 + (self.y - other.y) ** 2) ** 0.5 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..9ce4f48 --- /dev/null +++ b/tox.ini @@ -0,0 +1,31 @@ +[tox] +envlist = py3{7,8,9,10,11,12,13}, mypy, black, pylint, isort, ruff +isolated_build = True +skip_missing_interpreters = True + +[testenv] +deps = + pytest + hypothesis +skip_install = True +commands = python -m pytest + +[testenv:black] +deps = black +commands = black --check --diff tests/ point.py + +[testenv:mypy] +deps = mypy +commands = mypy --ignore-missing-imports point.py + +[testenv:pylint] +deps = pylint +commands = pylint point.py + +[testenv:isort] +deps = isort +commands = isort --check --profile=black point.py + +[testenv:ruff] +deps = ruff +commands = ruff check point.py