Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Use ruff for pytest style (#3872)

adeshpandec8fe4d9e4f9c
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index ee487a7fc..75f4ed830 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -1988,7 +1988,8 @@ class Mobject:
def reduce_across_dimension(self, reduce_func: Callable, dim: int):
"""Find the min or max value from a dimension across all points in this and submobjects."""
- assert dim >= 0 and dim <= 2
+ assert dim >= 0
+ assert dim <= 2
if len(self.submobjects) == 0 and len(self.points) == 0:
# If we have no points and no submobjects, return 0 (e.g. center)
return 0
diff --git a/pyproject.toml b/pyproject.toml
index c38f80dae..45962eea9 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -68,9 +68,7 @@ flake8-bugbear = "^23.11.28"
flake8-builtins = "^2.2.0"
flake8-comprehensions = "^3.7.0"
flake8-docstrings = "^1.7.0"
-flake8-pytest-style = "^1.7.2"
flake8-simplify = "^0.14.1"
-flake8-rst-docstrings = "^0.3.0"
furo = "^2023.09.10"
gitpython = "^3"
isort = "^5.12.0"
@@ -139,6 +137,7 @@ select = [
"E",
"F",
"I",
+ "PT",
"UP",
]
@@ -146,6 +145,10 @@ ignore = [
# due to the import * used in manim
"F403",
"F405",
+ # fixtures not returning anything should have leading underscore
+ "PT004",
+ # Exception too broad (this would require lots of changes + re.escape) for little benefit
+ "PT011",
# as recommended by https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"E111",
"E114",
@@ -176,6 +179,10 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]
+[tool.ruff.lint.flake8-pytest-style]
+fixture-parentheses = false
+mark-parentheses = false
+
[tool.ruff.format]
docstring-code-format = true
diff --git a/tests/module/animation/test_animate.py b/tests/module/animation/test_animate.py
index 4f39d8548..91d3b19df 100644
--- a/tests/module/animation/test_animate.py
+++ b/tests/module/animation/test_animate.py
@@ -23,10 +23,8 @@ def test_chained_animate():
scale_factor = 2
direction = np.array((1, 1, 0))
anim = s.animate.scale(scale_factor).shift(direction).build()
- assert (
- anim.mobject.target.width == scale_factor * s.width
- and (anim.mobject.target.get_center() == direction).all()
- )
+ assert anim.mobject.target.width == scale_factor * s.width
+ assert (anim.mobject.target.get_center() == direction).all()
def test_overridden_animate():
@@ -103,10 +101,8 @@ def test_chained_animate_with_args():
run_time = 2
anim = s.animate(run_time=run_time).scale(scale_factor).shift(direction).build()
- assert (
- anim.mobject.target.width == scale_factor * s.width
- and (anim.mobject.target.get_center() == direction).all()
- )
+ assert anim.mobject.target.width == scale_factor * s.width
+ assert (anim.mobject.target.get_center() == direction).all()
assert anim.run_time == run_time
diff --git a/tests/module/animation/test_composition.py b/tests/module/animation/test_composition.py
index 89eb22658..53d5767aa 100644
--- a/tests/module/animation/test_composition.py
+++ b/tests/module/animation/test_composition.py
@@ -132,7 +132,7 @@ def test_animationgroup_with_wait():
@pytest.mark.parametrize(
- "animation_remover, animation_group_remover",
+ ("animation_remover", "animation_group_remover"),
[(False, True), (True, False)],
)
def test_animationgroup_is_passing_remover_to_animations(
diff --git a/tests/module/mobject/graphing/test_coordinate_system.py b/tests/module/mobject/graphing/test_coordinate_system.py
index 727bb0ba6..470d9d007 100644
--- a/tests/module/mobject/graphing/test_coordinate_system.py
+++ b/tests/module/mobject/graphing/test_coordinate_system.py
@@ -56,7 +56,7 @@ def test_dimension():
def test_abstract_base_class():
"""Check that CoordinateSystem has some abstract methods."""
- with pytest.raises(Exception):
+ with pytest.raises(NotImplementedError):
CS().get_axes()
diff --git a/tests/module/mobject/test_boolean_ops.py b/tests/module/mobject/test_boolean_ops.py
index 844a9f2b5..b3560e87f 100644
--- a/tests/module/mobject/test_boolean_ops.py
+++ b/tests/module/mobject/test_boolean_ops.py
@@ -8,7 +8,7 @@ from manim.mobject.geometry.boolean_ops import _BooleanOps
@pytest.mark.parametrize(
- "test_input,expected",
+ ("test_input", "expected"),
[
(
[(1.0, 2.0), (3.0, 4.0)],
diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py
index 52cc1554c..72467b4e4 100644
--- a/tests/module/mobject/text/test_texmobject.py
+++ b/tests/module/mobject/text/test_texmobject.py
@@ -19,7 +19,7 @@ def test_SingleStringMathTex(config):
@pytest.mark.parametrize( # : PT006
- "text_input,length_sub",
+ ("text_input", "length_sub"),
[("{{ a }} + {{ b }} = {{ c }}", 5), (r"\frac{1}{a+b\sqrt{2}}", 1)],
)
def test_double_braces_testing(text_input, length_sub):
diff --git a/tests/module/scene/test_auto_zoom.py b/tests/module/scene/test_auto_zoom.py
index 76c17231f..4c95ed83c 100644
--- a/tests/module/scene/test_auto_zoom.py
+++ b/tests/module/scene/test_auto_zoom.py
@@ -16,6 +16,7 @@ def test_zoom():
assert scene.camera.frame_width == abs(
s1.get_left()[0] - s2.get_right()[0],
- ) and scene.camera.frame.get_center()[0] == (
+ )
+ assert scene.camera.frame.get_center()[0] == (
abs(s1.get_center()[0] + s2.get_center()[0]) / 2
)
diff --git a/tests/opengl/test_animate_opengl.py b/tests/opengl/test_animate_opengl.py
index 1243fcb21..b5cf21afa 100644
--- a/tests/opengl/test_animate_opengl.py
+++ b/tests/opengl/test_animate_opengl.py
@@ -23,10 +23,8 @@ def test_chained_animate(using_opengl_renderer):
scale_factor = 2
direction = np.array((1, 1, 0))
anim = s.animate.scale(scale_factor).shift(direction).build()
- assert (
- anim.mobject.target.width == scale_factor * s.width
- and (anim.mobject.target.get_center() == direction).all()
- )
+ assert anim.mobject.target.width == scale_factor * s.width
+ assert (anim.mobject.target.get_center() == direction).all()
def test_overridden_animate(using_opengl_renderer):
@@ -103,10 +101,8 @@ def test_chained_animate_with_args(using_opengl_renderer):
run_time = 2
anim = s.animate(run_time=run_time).scale(scale_factor).shift(direction).build()
- assert (
- anim.mobject.target.width == scale_factor * s.width
- and (anim.mobject.target.get_center() == direction).all()
- )
+ assert anim.mobject.target.width == scale_factor * s.width
+ assert (anim.mobject.target.get_center() == direction).all()
assert anim.run_time == run_time
diff --git a/tests/opengl/test_coordinate_system_opengl.py b/tests/opengl/test_coordinate_system_opengl.py
index ed596d7e9..b63a43123 100644
--- a/tests/opengl/test_coordinate_system_opengl.py
+++ b/tests/opengl/test_coordinate_system_opengl.py
@@ -55,7 +55,7 @@ def test_dimension(using_opengl_renderer):
def test_abstract_base_class(using_opengl_renderer):
"""Check that CoordinateSystem has some abstract methods."""
- with pytest.raises(Exception):
+ with pytest.raises(NotImplementedError):
CS().get_axes()
diff --git a/tests/opengl/test_texmobject_opengl.py b/tests/opengl/test_texmobject_opengl.py
index a9dd20ba0..9c065f044 100644
--- a/tests/opengl/test_texmobject_opengl.py
+++ b/tests/opengl/test_texmobject_opengl.py
@@ -18,7 +18,7 @@ def test_SingleStringMathTex(config, using_opengl_renderer):
@pytest.mark.parametrize( # : PT006
- "text_input,length_sub",
+ ("text_input", "length_sub"),
[("{{ a }} + {{ b }} = {{ c }}", 5), (r"\frac{1}{a+b\sqrt{2}}", 1)],
)
def test_double_braces_testing(using_opengl_renderer, text_input, length_sub):
diff --git a/tests/test_graphical_units/conftest.py b/tests/test_graphical_units/conftest.py
index 9a00b0264..331454102 100644
--- a/tests/test_graphical_units/conftest.py
+++ b/tests/test_graphical_units/conftest.py
@@ -10,4 +10,4 @@ def show_diff(request):
@pytest.fixture(params=[True, False])
def use_vectorized(request):
- yield request.param
+ return request.param
diff --git a/tests/test_graphical_units/test_transform_matching_parts.py b/tests/test_graphical_units/test_transform_matching_parts.py
index b5af1fb2a..3694f51be 100644
--- a/tests/test_graphical_units/test_transform_matching_parts.py
+++ b/tests/test_graphical_units/test_transform_matching_parts.py
@@ -12,7 +12,8 @@ def test_TransformMatchingLeavesOneObject(scene):
circle = Circle().shift(RIGHT)
scene.add(square)
scene.play(TransformMatchingShapes(square, circle))
- assert len(scene.mobjects) == 1 and isinstance(scene.mobjects[0], Circle)
+ assert len(scene.mobjects) == 1
+ assert isinstance(scene.mobjects[0], Circle)
@frames_comparison(last_frame=False)
diff --git a/tests/test_linear_transformation_scene.py b/tests/test_linear_transformation_scene.py
index c45e3f699..d0592b8f4 100644
--- a/tests/test_linear_transformation_scene.py
+++ b/tests/test_linear_transformation_scene.py
@@ -20,5 +20,6 @@ def test_ghost_vectors_len_and_types():
assert len(ghosts[0]) == 2
# check types of ghost vectors
- assert isinstance(ghosts, VGroup) and isinstance(ghosts[0], VGroup)
+ assert isinstance(ghosts, VGroup)
+ assert isinstance(ghosts[0], VGroup)
assert all(isinstance(x, Vector) for x in ghosts[0])
diff --git a/tests/test_logging/test_logging.py b/tests/test_logging/test_logging.py
index ca209482a..397573a51 100644
--- a/tests/test_logging/test_logging.py
+++ b/tests/test_logging/test_logging.py
@@ -46,7 +46,8 @@ def test_error_logging(tmp_path, python_version):
out, err, exitcode = capture(command)
if err is None:
err = out
- assert exitcode != 0 and "Traceback (most recent call last)" in err
+ assert exitcode != 0
+ assert "Traceback (most recent call last)" in err
@logs_comparison(
@@ -69,4 +70,5 @@ def test_tex_error_logs(tmp_path, python_version):
"BadTex",
]
_, err, exitcode = capture(command)
- assert exitcode != 0 and len(err) > 0
+ assert exitcode != 0
+ assert len(err) > 0
diff --git a/tests/test_plugins/test_plugins.py b/tests/test_plugins/test_plugins.py
index e81dc4708..428dbd732 100644
--- a/tests/test_plugins/test_plugins.py
+++ b/tests/test_plugins/test_plugins.py
@@ -59,7 +59,7 @@ cfg_file_contents = textwrap.dedent(
@pytest.fixture
def simple_scenes_path():
- yield Path(__file__).parent / "simple_scenes.py"
+ return Path(__file__).parent / "simple_scenes.py"
def cfg_file_create(cfg_file_contents, path):
@@ -73,7 +73,7 @@ def random_string():
all_letters = string.ascii_lowercase
a = random.Random()
final_letters = [a.choice(all_letters) for _ in range(8)]
- yield "".join(final_letters)
+ return "".join(final_letters)
def test_plugin_warning(tmp_path, python_version, simple_scenes_path):
diff --git a/tests/test_scene_rendering/test_file_writer.py b/tests/test_scene_rendering/test_file_writer.py
index 6ccc8b25d..004756280 100644
--- a/tests/test_scene_rendering/test_file_writer.py
+++ b/tests/test_scene_rendering/test_file_writer.py
@@ -81,7 +81,7 @@ def test_gif_writing(tmp_path, transparent):
@pytest.mark.slow
@pytest.mark.parametrize(
- "format, transparent, codec, pixel_format",
+ ("format", "transparent", "codec", "pixel_format"),
[
("mp4", False, "h264", "yuv420p"),
("mov", False, "h264", "yuv420p"),