Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

added tests

Hugues Devimeux30776ef27c8d
diff --git a/tests/test_CLI.py b/tests/test_CLI.py
new file mode 100644
index 000000000..ab1953778
--- /dev/null
+++ b/tests/test_CLI.py
@@ -0,0 +1,49 @@
+import subprocess
+import os
+from shutil import rmtree
+
+
+def capture(command):
+ proc = subprocess.Popen(command,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )
+ out, err = proc.communicate()
+ return out, err, proc.returncode
+
+
+def test_help():
+ command = ["python", "-m", "manim", "--help"]
+ out, err, exitcode = capture(command)
+ assert exitcode == 0, "Manim is not correcly installed. Please refer to the troubleshooting section on the wiki. Error : {}".format(
+ err)
+
+
+def test_basicScene():
+ """ Simulate SquareToCircle. The cache will be saved in tests_caches/media_temp (temporary directory). This is mainly intended to test the partial-movies process. """
+ path_basic_scene = os.path.join(
+ "manim", "tests", "tests_data", "basic_scenes.py")
+ path_output = os.path.join("manim", "tests", "tests_cache", "media_temp")
+ command = ["python", "-m", "manim", path_basic_scene,
+ "SquareToCircle", "-l", "--media_dir", path_output]
+ out, err, exitcode = capture(command)
+ assert exitcode == 0, err
+ assert (b"Played 3 animation" in out.splitlines()[-1])
+ assert os.path.exists(os.path.join(
+ path_output, "videos", "basic_scenes", "480p15", "SquareToCircle.mp4")), "Error in the file generation. Please ignore if it was intended"
+ rmtree(path_output)
+
+
+def test_WriteStuff():
+ """Simulate WriteStuff. This is mainly intended to test the caching process of the tex objects"""
+ path_basic_scene = os.path.join(
+ "manim", "tests", "tests_data", "basic_scenes.py")
+ path_output = os.path.join("manim", "tests", "tests_cache", "media_temp")
+ command = ["python", "-m", "manim", path_basic_scene,
+ "WriteStuff", "-l", "--media_dir", path_output]
+ out, err, exitcode = capture(command)
+ assert exitcode == 0, err
+ assert (b"Played 2 animation" in out.splitlines()[-1])
+ assert os.path.exists(os.path.join(
+ path_output, "videos", "basic_scenes", "480p15", "WriteStuff.mp4")), "Error in the file generation. Please ignore if it was intended"
+ #rmtree(path_output)
diff --git a/tests/test_creation.py b/tests/test_creation.py
new file mode 100644
index 000000000..73c681729
--- /dev/null
+++ b/tests/test_creation.py
@@ -0,0 +1,115 @@
+from manim import *
+
+
+class ShowCreationTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(ShowCreation(square))
+
+
+class UncreateTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.add(square)
+ self.play(Uncreate(square))
+
+
+class DrawBorderThenFillTest(Scene):
+ def construct(self):
+ square = Square(fill_opacity=1)
+
+ self.play(DrawBorderThenFill(square))
+
+
+class WriteTest(Scene):
+ def construct(self):
+ t = Text('Test')
+
+ self.play(Write(t))
+
+
+class FadeOutTest(Scene):
+ def construct(self):
+ square = Square()
+ self.add(square)
+
+ self.play(FadeOut(square))
+
+
+class FadeInTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(FadeIn(square))
+
+
+class FadeInFromTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(FadeInFrom(square, direction=UP))
+
+
+class FadeInFromDownTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(FadeInFromDown(square))
+
+
+class FadeOutAndShiftTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(FadeOutAndShift(square, direction=UP))
+
+
+class FadeInFromLargeTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(FadeInFromLarge(square))
+
+
+class GrowFromPointTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(GrowFromPoint(square, np.array((1, 1, 0))))
+
+
+class GrowFromCenterTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(GrowFromCenter(square))
+
+
+class GrowFromEdgeTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(GrowFromEdge(square, DOWN))
+
+
+class SpinInFromNothingTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(SpinInFromNothing(square))
+
+
+class ShrinkToCenterTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(ShrinkToCenter(square))
+
+def test_scenes(get_config_test, Tester):
+ CONFIG = get_config_test
+ module_name = os.path.splitext(os.path.basename(__file__))[0].replace('test_', '')
+ for _, scene_tested in inspect.getmembers(sys.modules[__name__], lambda m: inspect.isclass(m) and m.__module__ == __name__):
+ Tester(scene_tested, CONFIG, module_name).test()
+
diff --git a/tests/test_geometry.py b/tests/test_geometry.py
new file mode 100644
index 000000000..0a793cad1
--- /dev/null
+++ b/tests/test_geometry.py
@@ -0,0 +1,126 @@
+from manim import *
+
+
+class CoordinatesTest(Scene):
+ def construct(self):
+ dots = []
+ for x in range(-7, 8):
+ for y in range(-4, 5):
+ dots.append(Dot(np.array([x, y, 0])))
+
+ self.play(Animation(VGroup(*dots)))
+
+
+class ArcTest(Scene):
+ def construct(self):
+ a = Arc(PI)
+ self.play(Animation(a))
+
+
+class ArcBetweenPointsTest(Scene):
+ def construct(self):
+ a = ArcBetweenPoints(np.array([1, 1, 0]), np.array([2, 2, 0]))
+ self.play(Animation(a))
+
+
+class CurvedArrowTest(Scene):
+ def construct(self):
+ a = CurvedArrow(np.array([1, 1, 0]), np.array([2, 2, 0]))
+ self.play(Animation(a))
+
+
+class CircleTest(Scene):
+ def construct(self):
+ circle = Circle()
+
+ self.play(Animation(circle))
+
+
+class DotTest(Scene):
+ def construct(self):
+ dot = Dot()
+
+ self.play(Animation(dot))
+
+
+class EllipseTest(Scene):
+ def construct(self):
+ e = Ellipse()
+
+ self.play(Animation(e))
+
+
+class SectorTest(Scene):
+ def construct(self):
+ e = Sector()
+
+ self.play(Animation(e))
+
+
+class AnnulusTest(Scene):
+ def construct(self):
+ a = Annulus()
+
+ self.play(Animation(a))
+
+
+class AnnularSectorTest(Scene):
+ def construct(self):
+ a = AnnularSector()
+
+ self.play(Animation(a))
+
+
+class LineTest(Scene):
+ def construct(self):
+ a = Line(np.array([1, 1, 0]), np.array([2, 2, 0]))
+
+ self.play(Animation(a))
+
+
+class Elbowtest(Scene):
+ def construct(self):
+ a = Elbow()
+
+ self.play(Animation(a))
+
+
+class DoubleArrowTest(Scene):
+ def construct(self):
+ a = DoubleArrow()
+
+ self.play(Animation(a))
+
+
+class VectorTest(Scene):
+ def construct(self):
+ a = Vector(UP)
+
+ self.play(Animation(a))
+
+
+class PolygonTest(Scene):
+ def construct(self):
+ a = Polygon(
+ *[np.array([1, 1, 0]), np.array([2, 2, 0]), np.array([2, 3, 0])])
+
+ self.play(Animation(a))
+
+
+class RectangleTest(Scene):
+ def construct(self):
+ a = Rectangle()
+
+ self.play(Animation(a))
+
+class RoundedRectangleTest(Scene):
+ def construct(self):
+ a = RoundedRectangle()
+
+ self.play(Animation(a))
+
+def test_scenes(get_config_test, Tester):
+ CONFIG = get_config_test
+ module_name = os.path.splitext(os.path.basename(__file__))[0].replace('test_', '')
+ for _, scene_tested in inspect.getmembers(sys.modules[__name__], lambda m: inspect.isclass(m) and m.__module__ == __name__):
+ Tester(scene_tested, CONFIG, module_name).test()
\ No newline at end of file
diff --git a/tests/test_graph.py b/tests/test_graph.py
new file mode 100644
index 000000000..205bfd117
--- /dev/null
+++ b/tests/test_graph.py
@@ -0,0 +1,19 @@
+from manim import *
+
+class PlotFunctions(GraphScene):
+ CONFIG = {
+ "x_min" : -10,
+ "x_max" : 10.3,
+ "y_min" : -1.5,
+ "y_max" : 1.5,
+ "graph_origin" : ORIGIN ,
+ "function_color" : RED ,
+ "axes_color" : GREEN,
+ "x_labeled_nums" :range(-10,12,2),
+ }
+
+ def construct(self):
+ self.setup_axes()
+ f = self.get_graph(lambda x : x**2)
+
+ self.play(Animation(f))
\ No newline at end of file
diff --git a/tests/test_indication.py b/tests/test_indication.py
new file mode 100644
index 000000000..8c64112ba
--- /dev/null
+++ b/tests/test_indication.py
@@ -0,0 +1,92 @@
+from manim import *
+
+
+class FocusOnTest(Scene):
+ def construct(self):
+ square = Square()
+ self.add(square)
+
+ self.play(FocusOn(square))
+
+
+class IndicateTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(Indicate(square))
+
+
+class FlashTest(Scene):
+ def construct(self):
+ square = Square()
+ self.add(square)
+
+ self.play(Flash(square))
+
+
+class CircleIndicateTest(Scene):
+ def construct(self):
+ square = Square()
+ self.add(square)
+
+ self.play(CircleIndicate(square))
+
+
+class ShowPassingFlashTest(Scene):
+ def construct(self):
+ square = Square()
+ self.add(square)
+
+ self.play(ShowPassingFlash(square))
+
+
+class ShowCreationThenDestructionTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(ShowCreationThenDestruction(square))
+
+
+class ShowCreationThenFadeOutTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(ShowCreationThenFadeOut(square))
+
+
+class ShowPassingFlashAroundTest(Scene):
+ def construct(self):
+ circle = Circle()
+
+ self.play(ShowPassingFlashAround(circle))
+
+
+class ApplyWaveTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(ApplyWave(square))
+
+
+class WiggleOutThenInTest(Scene):
+ def construct(self):
+ square = Square()
+ self.add(square)
+
+ self.play(WiggleOutThenIn(square))
+
+
+class TurnInsideOutTest(Scene):
+ def construct(self):
+ square = Square()
+ self.add(square)
+
+ self.play(TurnInsideOut(square))
+
+def test_scenes(get_config_test, Tester):
+ CONFIG = get_config_test
+ module_name = os.path.splitext(os.path.basename(__file__))[0].replace('test_', '')
+ for _, scene_tested in inspect.getmembers(sys.modules[__name__], lambda m: inspect.isclass(m) and m.__module__ == __name__):
+ Tester(scene_tested, CONFIG, module_name).test()
+
+
diff --git a/tests/test_movements.py b/tests/test_movements.py
new file mode 100644
index 000000000..204534215
--- /dev/null
+++ b/tests/test_movements.py
@@ -0,0 +1,56 @@
+from manim import *
+
+class HomotopyTest(Scene):
+ def construct(self):
+ def func(x,y,z,t):
+ norm = get_norm([x, y])
+ tau = interpolate(5, -5, t) + norm/FRAME_X_RADIUS
+ alpha = sigmoid(tau)
+ return [x, y + 0.5*np.sin(2*np.pi*alpha)-t*SMALL_BUFF/2, z]
+
+ square = Square()
+
+ self.play(Homotopy(func, square))
+
+
+class PhaseFlowTest(Scene):
+ def construct(self):
+ square = Square()
+ def func(t):
+ return t*0.5*UP
+
+ self.play(PhaseFlow(func, square ))
+
+class MoveAlongPathTest(Scene):
+ def construct(self):
+ square = Square()
+ dot = Dot()
+
+ self.play(MoveAlongPath(dot, square))
+
+class RotateTest(Scene):
+ def construct(self):
+ square= Square()
+
+ self.play(Rotate(square, PI))
+
+class MoveToTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(square.move_to, np.array([1.0, 1.0, 0.0]))
+
+
+class ShiftTest(Scene):
+ def construct(self):
+ square = Square()
+ self.play(square.shift, UP)
+
+
+
+def test_scenes(get_config_test, Tester):
+ CONFIG = get_config_test
+ module_name = os.path.splitext(os.path.basename(__file__))[0].replace('test_', '')
+ for _, scene_tested in inspect.getmembers(sys.modules[__name__], lambda m: inspect.isclass(m) and m.__module__ == __name__):
+ Tester(scene_tested, CONFIG, module_name).test()
+
diff --git a/tests/test_threed.py b/tests/test_threed.py
new file mode 100644
index 000000000..68c347cf7
--- /dev/null
+++ b/tests/test_threed.py
@@ -0,0 +1,38 @@
+from manim import *
+
+
+class CubeTest(ThreeDScene):
+ def construct(self):
+ self.play(Animation(Cube()))
+
+
+class SphereTest(ThreeDScene):
+ def construct(self):
+ self.play(Animation(Sphere()))
+
+
+class AxesTest(ThreeDScene):
+ def construct(self):
+ self.play(Animation(ThreeDAxes()))
+
+
+class CameraMoveTest(ThreeDScene):
+ def construct(self):
+ cube = Cube()
+ self.play(Animation(cube))
+ self.move_camera(phi=PI/4, theta=PI/4)
+
+
+class AmbientCameraMoveTest(ThreeDScene):
+ def construct(self):
+ cube = Cube()
+ self.begin_ambient_camera_rotation(rate=0.5)
+ self.play(Animation(cube))
+
+
+def test_scenes(get_config_test, Tester):
+ CONFIG = get_config_test
+ module_name = os.path.splitext(os.path.basename(__file__))[
+ 0].replace('test_', '')
+ for _, scene_tested in inspect.getmembers(sys.modules[__name__], lambda m: inspect.isclass(m) and m.__module__ == __name__):
+ Tester(scene_tested, CONFIG, module_name).test()
diff --git a/tests/test_transform.py b/tests/test_transform.py
new file mode 100644
index 000000000..f8b3b5148
--- /dev/null
+++ b/tests/test_transform.py
@@ -0,0 +1,138 @@
+from manim import *
+
+
+class TransformTest(Scene):
+ def construct(self):
+ square = Square()
+ circle = Circle()
+
+ self.play(Transform(square, circle))
+
+
+class TransformFromCopyTest(Scene):
+ def construct(self):
+ square = Square()
+ circle = Circle()
+
+ self.play(TransformFromCopy(square, circle))
+
+
+class ClockwiseTransformTest(Scene):
+ def construct(self):
+ square = Square()
+ circle = Circle()
+
+ self.play(ClockwiseTransform(square, circle))
+
+
+class CounterclockwiseTransformTest(Scene):
+ def construct(self):
+ square = Square()
+ circle = Circle()
+
+ self.play(CounterclockwiseTransform(square, circle))
+
+
+class MoveToTargetTest(Scene):
+ def construct(self):
+ square = Square()
+ square.generate_target()
+ square.target.shift(3*UP)
+
+ self.play(MoveToTarget(square))
+
+
+class ApplyPointwiseFunctionTest(Scene):
+ def construct(self):
+ square = Square()
+
+ def func(p):
+ return np.array([1.0, 1.0, 0.0])
+
+ self.play(
+ ApplyPointwiseFunction(func, square)
+ )
+
+
+class FadeToColortTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(FadeToColor(square, RED))
+
+
+class ScaleInPlaceTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(ScaleInPlace(square, scale_factor=0.1))
+
+
+class ShrinkToCenterTest(Scene):
+ def construct(self):
+ square = Square()
+
+ self.play(ShrinkToCenter(square))
+
+
+class RestoreTest(Scene):
+ def construct(self):
+ square = Square()
+ circle = Circle()
+
+ self.play(Transform(square, circle))
+ square.save_state()
+ self.play(square.shift, UP)
+ self.play(Restore(square))
+
+
+class ApplyFunctionTest(Scene):
+ def construct(self):
+ square = Square()
+ self.add(square)
+
+ def apply_function(mob):
+ mob.scale(2)
+ mob.to_corner(UR)
+ mob.rotate(PI/4)
+ mob.set_color(RED)
+ return mob
+ self.play(
+ ApplyFunction(
+ apply_function,
+ square
+ )
+ )
+
+
+class ApplyComplexFunctionTest(Scene):
+ def construct(self):
+ square = Square()
+ self.play(
+ ApplyComplexFunction(
+ lambda complex_num: complex_num + 2 * np.complex(0, 1), square
+ )
+ )
+
+
+class ApplyMatrixTest(Scene):
+ def construct(self):
+ square = Square()
+ matrice = [[1.0, 0.5], [1.0, 0.0]]
+ self.play(ApplyMatrix(matrice, square))
+
+
+class CyclicReplaceTest(Scene):
+ def construct(self):
+ square = Square()
+ circle = Circle()
+ circle.shift(3 * UP)
+ self.play(CyclicReplace(square, circle))
+
+
+def test_scenes(get_config_test, Tester):
+ CONFIG = get_config_test
+ module_name = os.path.splitext(os.path.basename(__file__))[
+ 0].replace('test_', '')
+ for _, scene_tested in inspect.getmembers(sys.modules[__name__], lambda m: inspect.isclass(m) and m.__module__ == __name__):
+ Tester(scene_tested, CONFIG, module_name).test()
diff --git a/tests/test_updaters.py b/tests/test_updaters.py
new file mode 100644
index 000000000..8f3895bff
--- /dev/null
+++ b/tests/test_updaters.py
@@ -0,0 +1,30 @@
+from manim import *
+
+
+class UpdaterTest(Scene):
+ def construct(self):
+ dot = Dot()
+ square = Square()
+ self.add(dot, square)
+ square.add_updater(lambda m: m.next_to(dot, RIGHT, buff=SMALL_BUFF))
+ self.add(square)
+
+ self.play(dot.shift, UP*2)
+ square.clear_updaters()
+
+
+class ValueTrackerTest(Scene):
+ def construct(self):
+ theta = ValueTracker(PI/2)
+ line_1 = Line(ORIGIN, RIGHT*3, color=RED)
+ line_2 = Line(ORIGIN, RIGHT*3, color=GREEN)
+
+ line_2.rotate(theta.get_value(), about_point=ORIGIN)
+
+
+def test_scenes(get_config_test, Tester):
+ CONFIG = get_config_test
+ module_name = os.path.splitext(os.path.basename(__file__))[
+ 0].replace('test_', '')
+ for _, scene_tested in inspect.getmembers(sys.modules[__name__], lambda m: inspect.isclass(m) and m.__module__ == __name__):
+ Tester(scene_tested, CONFIG, module_name).test()
diff --git a/tests/test_writing.py b/tests/test_writing.py
new file mode 100644
index 000000000..50dbb25aa
--- /dev/null
+++ b/tests/test_writing.py
@@ -0,0 +1,35 @@
+from manim import *
+
+#NOTE : All of those tests use cached data (in /test_cache)
+# Cache functionality is tested within test_CLI.
+
+class TextTest(Scene):
+ def construct(self):
+ t = Text('testing')
+
+ self.play(Animation(t))
+
+
+class TextMobjectTest(Scene):
+ def construct(self):
+ t = TextMobject('Hello world !')
+
+ self.play(Animation(t))
+
+
+class TexMobjectTest(Scene):
+ def construct(self):
+ t = TexMobject(
+ "\\sum_{n=1}^\\infty "
+ "\\frac{1}{n^2} = \\frac{\\pi^2}{6}"
+ )
+
+ self.play(Animation(t))
+
+
+def test_scenes(get_config_test, Tester):
+ CONFIG = get_config_test
+ module_name = os.path.splitext(os.path.basename(__file__))[
+ 0].replace('test_', '')
+ for name, scene_tested in inspect.getmembers(sys.modules[__name__], lambda m: inspect.isclass(m) and m.__module__ == __name__):
+ Tester(scene_tested, CONFIG, module_name, caching_needed=True).test()