mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
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 <tristanschulz1200@gmail.com>
This commit is contained in:
parent
fa65b488b0
commit
c8fe4d9e4f
17 changed files with 39 additions and 34 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)],
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ def show_diff(request):
|
|||
|
||||
@pytest.fixture(params=[True, False])
|
||||
def use_vectorized(request):
|
||||
yield request.param
|
||||
return request.param
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue