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

tests/opengl/test_texmobject_opengl.py

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

1919

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

tests/test_graphical_units/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ def show_diff(request):
1010

1111
@pytest.fixture(params=[True, False])
1212
def use_vectorized(request):
13-
yield request.param
13+
return request.param

tests/test_graphical_units/test_transform_matching_parts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def test_TransformMatchingLeavesOneObject(scene):
1212
circle = Circle().shift(RIGHT)
1313
scene.add(square)
1414
scene.play(TransformMatchingShapes(square, circle))
15-
assert len(scene.mobjects) == 1 and isinstance(scene.mobjects[0], Circle)
15+
assert len(scene.mobjects) == 1
16+
assert isinstance(scene.mobjects[0], Circle)
1617

1718

1819
@frames_comparison(last_frame=False)

tests/test_linear_transformation_scene.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ def test_ghost_vectors_len_and_types():
2020
assert len(ghosts[0]) == 2
2121

2222
# check types of ghost vectors
23-
assert isinstance(ghosts, VGroup) and isinstance(ghosts[0], VGroup)
23+
assert isinstance(ghosts, VGroup)
24+
assert isinstance(ghosts[0], VGroup)
2425
assert all(isinstance(x, Vector) for x in ghosts[0])

tests/test_logging/test_logging.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def test_error_logging(tmp_path, python_version):
4646
out, err, exitcode = capture(command)
4747
if err is None:
4848
err = out
49-
assert exitcode != 0 and "Traceback (most recent call last)" in err
49+
assert exitcode != 0
50+
assert "Traceback (most recent call last)" in err
5051

5152

5253
@logs_comparison(
@@ -69,4 +70,5 @@ def test_tex_error_logs(tmp_path, python_version):
6970
"BadTex",
7071
]
7172
_, err, exitcode = capture(command)
72-
assert exitcode != 0 and len(err) > 0
73+
assert exitcode != 0
74+
assert len(err) > 0

tests/test_plugins/test_plugins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def {function_name}():
5959

6060
@pytest.fixture
6161
def simple_scenes_path():
62-
yield Path(__file__).parent / "simple_scenes.py"
62+
return Path(__file__).parent / "simple_scenes.py"
6363

6464

6565
def cfg_file_create(cfg_file_contents, path):
@@ -73,7 +73,7 @@ def random_string():
7373
all_letters = string.ascii_lowercase
7474
a = random.Random()
7575
final_letters = [a.choice(all_letters) for _ in range(8)]
76-
yield "".join(final_letters)
76+
return "".join(final_letters)
7777

7878

7979
def test_plugin_warning(tmp_path, python_version, simple_scenes_path):

tests/test_scene_rendering/test_file_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_gif_writing(tmp_path, transparent):
8181

8282
@pytest.mark.slow
8383
@pytest.mark.parametrize(
84-
"format, transparent, codec, pixel_format",
84+
("format", "transparent", "codec", "pixel_format"),
8585
[
8686
("mp4", False, "h264", "yuv420p"),
8787
("mov", False, "h264", "yuv420p"),

0 commit comments

Comments
 (0)