mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
* Future Annotations * Delete template_twitter_post.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestions from code review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed broken RTD Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from manim import Mobject
|
|
|
|
|
|
def test_mobject_add():
|
|
"""Test Mobject.add()."""
|
|
"""Call this function with a Container instance to test its add() method."""
|
|
# check that obj.submobjects is updated correctly
|
|
obj = Mobject()
|
|
assert len(obj.submobjects) == 0
|
|
obj.add(Mobject())
|
|
assert len(obj.submobjects) == 1
|
|
obj.add(*(Mobject() for _ in range(10)))
|
|
assert len(obj.submobjects) == 11
|
|
|
|
# check that adding a mobject twice does not actually add it twice
|
|
repeated = Mobject()
|
|
obj.add(repeated)
|
|
assert len(obj.submobjects) == 12
|
|
obj.add(repeated)
|
|
assert len(obj.submobjects) == 12
|
|
|
|
# check that Mobject.add() returns the Mobject (for chained calls)
|
|
assert obj.add(Mobject()) is obj
|
|
obj = Mobject()
|
|
|
|
# a Mobject cannot contain itself
|
|
with pytest.raises(ValueError):
|
|
obj.add(obj)
|
|
|
|
# can only add Mobjects
|
|
with pytest.raises(TypeError):
|
|
obj.add("foo")
|
|
|
|
|
|
def test_mobject_remove():
|
|
"""Test Mobject.remove()."""
|
|
obj = Mobject()
|
|
to_remove = Mobject()
|
|
obj.add(to_remove)
|
|
obj.add(*(Mobject() for _ in range(10)))
|
|
assert len(obj.submobjects) == 11
|
|
obj.remove(to_remove)
|
|
assert len(obj.submobjects) == 10
|
|
obj.remove(to_remove)
|
|
assert len(obj.submobjects) == 10
|
|
|
|
assert obj.remove(Mobject()) is obj
|