Skip to content

Commit c8fe4d9

Browse files
Use ruff for pytest style (#3872)
* Add ruff config for pytest * Fixes for pre-commit * Changes to make pre-commit happy (Unrelated to PR) --------- Co-authored-by: Tristan Schulz <[email protected]>
1 parent fa65b48 commit c8fe4d9

17 files changed

+39
-34
lines changed

manim/mobject/mobject.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,8 @@ def restore(self) -> Self:
19881988

19891989
def reduce_across_dimension(self, reduce_func: Callable, dim: int):
19901990
"""Find the min or max value from a dimension across all points in this and submobjects."""
1991-
assert dim >= 0 and dim <= 2
1991+
assert dim >= 0
1992+
assert dim <= 2
19921993
if len(self.submobjects) == 0 and len(self.points) == 0:
19931994
# If we have no points and no submobjects, return 0 (e.g. center)
19941995
return 0

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ flake8-bugbear = "^23.11.28"
6868
flake8-builtins = "^2.2.0"
6969
flake8-comprehensions = "^3.7.0"
7070
flake8-docstrings = "^1.7.0"
71-
flake8-pytest-style = "^1.7.2"
7271
flake8-simplify = "^0.14.1"
73-
flake8-rst-docstrings = "^0.3.0"
7472
furo = "^2023.09.10"
7573
gitpython = "^3"
7674
isort = "^5.12.0"
@@ -139,13 +137,18 @@ select = [
139137
"E",
140138
"F",
141139
"I",
140+
"PT",
142141
"UP",
143142
]
144143

145144
ignore = [
146145
# due to the import * used in manim
147146
"F403",
148147
"F405",
148+
# fixtures not returning anything should have leading underscore
149+
"PT004",
150+
# Exception too broad (this would require lots of changes + re.escape) for little benefit
151+
"PT011",
149152
# as recommended by https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
150153
"E111",
151154
"E114",
@@ -176,6 +179,10 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
176179
[tool.ruff.lint.isort]
177180
required-imports = ["from __future__ import annotations"]
178181

182+
[tool.ruff.lint.flake8-pytest-style]
183+
fixture-parentheses = false
184+
mark-parentheses = false
185+
179186
[tool.ruff.format]
180187
docstring-code-format = true
181188

tests/module/animation/test_animate.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ def test_chained_animate():
2323
scale_factor = 2
2424
direction = np.array((1, 1, 0))
2525
anim = s.animate.scale(scale_factor).shift(direction).build()
26-
assert (
27-
anim.mobject.target.width == scale_factor * s.width
28-
and (anim.mobject.target.get_center() == direction).all()
29-
)
26+
assert anim.mobject.target.width == scale_factor * s.width
27+
assert (anim.mobject.target.get_center() == direction).all()
3028

3129

3230
def test_overridden_animate():
@@ -103,10 +101,8 @@ def test_chained_animate_with_args():
103101
run_time = 2
104102

105103
anim = s.animate(run_time=run_time).scale(scale_factor).shift(direction).build()
106-
assert (
107-
anim.mobject.target.width == scale_factor * s.width
108-
and (anim.mobject.target.get_center() == direction).all()
109-
)
104+
assert anim.mobject.target.width == scale_factor * s.width
105+
assert (anim.mobject.target.get_center() == direction).all()
110106
assert anim.run_time == run_time
111107

112108

tests/module/animation/test_composition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_animationgroup_with_wait():
132132

133133

134134
@pytest.mark.parametrize(
135-
"animation_remover, animation_group_remover",
135+
("animation_remover", "animation_group_remover"),
136136
[(False, True), (True, False)],
137137
)
138138
def test_animationgroup_is_passing_remover_to_animations(

tests/module/mobject/graphing/test_coordinate_system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_dimension():
5656

5757
def test_abstract_base_class():
5858
"""Check that CoordinateSystem has some abstract methods."""
59-
with pytest.raises(Exception):
59+
with pytest.raises(NotImplementedError):
6060
CS().get_axes()
6161

6262

tests/module/mobject/test_boolean_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
@pytest.mark.parametrize(
11-
"test_input,expected",
11+
("test_input", "expected"),
1212
[
1313
(
1414
[(1.0, 2.0), (3.0, 4.0)],

tests/module/mobject/text/test_texmobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_SingleStringMathTex(config):
1919

2020

2121
@pytest.mark.parametrize( # : PT006
22-
"text_input,length_sub",
22+
("text_input", "length_sub"),
2323
[("{{ a }} + {{ b }} = {{ c }}", 5), (r"\frac{1}{a+b\sqrt{2}}", 1)],
2424
)
2525
def test_double_braces_testing(text_input, length_sub):

tests/module/scene/test_auto_zoom.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_zoom():
1616

1717
assert scene.camera.frame_width == abs(
1818
s1.get_left()[0] - s2.get_right()[0],
19-
) and scene.camera.frame.get_center()[0] == (
19+
)
20+
assert scene.camera.frame.get_center()[0] == (
2021
abs(s1.get_center()[0] + s2.get_center()[0]) / 2
2122
)

tests/opengl/test_animate_opengl.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ def test_chained_animate(using_opengl_renderer):
2323
scale_factor = 2
2424
direction = np.array((1, 1, 0))
2525
anim = s.animate.scale(scale_factor).shift(direction).build()
26-
assert (
27-
anim.mobject.target.width == scale_factor * s.width
28-
and (anim.mobject.target.get_center() == direction).all()
29-
)
26+
assert anim.mobject.target.width == scale_factor * s.width
27+
assert (anim.mobject.target.get_center() == direction).all()
3028

3129

3230
def test_overridden_animate(using_opengl_renderer):
@@ -103,10 +101,8 @@ def test_chained_animate_with_args(using_opengl_renderer):
103101
run_time = 2
104102

105103
anim = s.animate(run_time=run_time).scale(scale_factor).shift(direction).build()
106-
assert (
107-
anim.mobject.target.width == scale_factor * s.width
108-
and (anim.mobject.target.get_center() == direction).all()
109-
)
104+
assert anim.mobject.target.width == scale_factor * s.width
105+
assert (anim.mobject.target.get_center() == direction).all()
110106
assert anim.run_time == run_time
111107

112108

tests/opengl/test_coordinate_system_opengl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_dimension(using_opengl_renderer):
5555

5656
def test_abstract_base_class(using_opengl_renderer):
5757
"""Check that CoordinateSystem has some abstract methods."""
58-
with pytest.raises(Exception):
58+
with pytest.raises(NotImplementedError):
5959
CS().get_axes()
6060

6161

0 commit comments

Comments
 (0)