Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

update tests wo new config system

leotrse4837b40a5ca
diff --git a/manim/__main__.py b/manim/__main__.py
index 50dbb1cbb..d1536e26f 100644
--- a/manim/__main__.py
+++ b/manim/__main__.py
@@ -1,5 +1,4 @@
import inspect
-import itertools as it
import os
import platform
import subprocess as sp
diff --git a/manim/config.py b/manim/config.py
index db153bf4a..6b86fc5f2 100644
--- a/manim/config.py
+++ b/manim/config.py
@@ -114,9 +114,15 @@ def _parse_file_writer_config(config_parser, args):
attr = getattr(args, boolean_opt)
config[boolean_opt] = (default.getboolean(boolean_opt)
if attr is None else attr)
- for str_opt in ['media_dir', 'video_dir', 'tex_dir', 'text_dir']:
+ # for str_opt in ['media_dir', 'video_dir', 'tex_dir', 'text_dir']:
+ for str_opt in ['media_dir']:
attr = getattr(args, str_opt)
config[str_opt] = (default[str_opt] if attr is None else attr)
+ dir_names = {'video_dir': 'videos',
+ 'tex_dir': 'Tex',
+ 'text_dir': 'texts'}
+ for name in dir_names:
+ config[name] = os.path.join(config['media_dir'], dir_names[name])
# Handle the -s (--save_last_frame) flag: invalidate the -w flag
# At this point the save_last_frame option has already been set by
@@ -270,19 +276,19 @@ def _parse_cli(arg_list, input=True):
"--media_dir",
help="directory to write media",
)
- video_group = parser.add_mutually_exclusive_group()
- video_group.add_argument(
- "--video_dir",
- help="directory to write file tree for video",
- )
- parser.add_argument(
- "--tex_dir",
- help="directory to write tex",
- )
- parser.add_argument(
- "--text_dir",
- help="directory to write text",
- )
+ # video_group = parser.add_mutually_exclusive_group()
+ # video_group.add_argument(
+ # "--video_dir",
+ # help="directory to write file tree for video",
+ # )
+ # parser.add_argument(
+ # "--tex_dir",
+ # help="directory to write tex",
+ # )
+ # parser.add_argument(
+ # "--text_dir",
+ # help="directory to write text",
+ # )
parser.add_argument(
"--tex_template",
help="Specify a custom TeX template file",
@@ -390,6 +396,9 @@ config_files = [
if _from_command_line():
args = _parse_cli(sys.argv[1:])
+ file_config = os.path.join(os.path.dirname(args.file), 'manim.cfg')
+ if os.path.exists(file_config):
+ config_files.append(file_config)
if args.config_file is not None:
config_files.append(args.config_file)
diff --git a/manim/default.cfg b/manim/default.cfg
index 3ef6ae3b9..c2cf10295 100644
--- a/manim/default.cfg
+++ b/manim/default.cfg
@@ -67,14 +67,14 @@ upto_animation_number = -1
# --media_dir
media_dir = ./media
-# --video_dir
-video_dir = %(MEDIA_DIR)s/videos
+# # --video_dir
+# video_dir = %(MEDIA_DIR)s/videos
-# --tex_dir
-tex_dir = %(MEDIA_DIR)s/Tex
+# # --tex_dir
+# tex_dir = %(MEDIA_DIR)s/Tex
-# --text_dir
-text_dir = %(MEDIA_DIR)s/texts
+# # --text_dir
+# text_dir = %(MEDIA_DIR)s/texts
# If the -t (--transparent) flag is used, these will be replaced with the
# values specified in the [TRANSPARENT] section later in this file.
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index b992de86a..bb5866af5 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -433,7 +433,7 @@ class Mobject(Container):
return self
def shift_onto_screen(self, **kwargs):
- space_lengths = [FRAME_X_RADIUS, FRAME_Y_RADIUS]
+ space_lengths = [config['frame_x_radius'], config['frame_y_radius']]
for vect in UP, DOWN, LEFT, RIGHT:
dim = np.argmax(np.abs(vect))
buff = kwargs.get("buff", DEFAULT_MOBJECT_TO_EDGE_BUFFER)
@@ -444,13 +444,13 @@ class Mobject(Container):
return self
def is_off_screen(self):
- if self.get_left()[0] > FRAME_X_RADIUS:
+ if self.get_left()[0] > config['frame_x_radius']:
return True
- if self.get_right()[0] < -FRAME_X_RADIUS:
+ if self.get_right()[0] < -config['frame_x_radius']:
return True
- if self.get_bottom()[1] > FRAME_Y_RADIUS:
+ if self.get_bottom()[1] > config['frame_y_radius']:
return True
- if self.get_top()[1] < -FRAME_Y_RADIUS:
+ if self.get_top()[1] < -config['frame_y_radius']:
return True
return False
diff --git a/manim/scene/graph_scene.py b/manim/scene/graph_scene.py
index a1f456d02..23a0b42bc 100644
--- a/manim/scene/graph_scene.py
+++ b/manim/scene/graph_scene.py
@@ -1,5 +1,6 @@
import itertools as it
+from ..config import config
from ..animation.creation import Write, DrawBorderThenFill, ShowCreation
from ..animation.transform import Transform
from ..animation.update import UpdateFromAlphaFunc
@@ -421,7 +422,7 @@ class GraphScene(Scene):
# Search from right to left
for x in np.linspace(self.x_max, self.x_min, 100):
point = self.input_to_graph_point(x, graph)
- if point[1] < FRAME_Y_RADIUS:
+ if point[1] < config['frame_y_radius']:
break
x_val = x
label.next_to(
diff --git a/tests/conftest.py b/tests/conftest.py
index bac45335b..c07ad705c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,6 +1,4 @@
-from manim import dirs
from manim import config
-
import pytest
import numpy as np
import os
@@ -32,32 +30,3 @@ def pytest_collection_modifyitems(config, items):
@pytest.fixture(scope="module")
def python_version():
return "python3" if sys.platform == "darwin" else "python"
-
-
-def get_config_test():
- """Function used internally by pytest as a fixture. Return the Configuration for the scenes rendered. The config is the one used when
- calling the flags -s -l -dry_run
- """
- CONFIG = {
- 'camera_config': {
- 'frame_rate': 15,
- 'pixel_height': 480,
- 'pixel_width': 854
- },
- 'end_at_animation_number': None,
- 'file_writer_config': {
- 'file_name': None,
- 'input_file_path': 'test.py',
- 'movie_file_extension': '.mp4',
- 'png_mode': 'RGB',
- 'save_as_gif': False,
- 'save_last_frame': False,
- 'save_pngs': False,
- 'write_to_movie': False
- },
- 'leave_progress_bars': False,
- 'skip_animations': True,
- 'start_at_animation_number': None
- }
- return CONFIG
diff --git a/tests/test_CLI.py b/tests/test_cli/test_cli.py
similarity index 91%
rename from tests/test_CLI.py
rename to tests/test_cli/test_cli.py
index 9bb48fc8a..1bd6cb271 100644
--- a/tests/test_CLI.py
+++ b/tests/test_cli/test_cli.py
@@ -16,14 +16,14 @@ def capture(command):
def test_help(python_version):
command = [python_version, "-m", "manim", "--help"]
out, err, exitcode = capture(command)
- assert exitcode == 0, f"Manim has been installed incorrectly. Please refer to the troubleshooting section on the wiki. Error: {err}"
+ assert exitcode == 0, f"Manim has been installed incorrectly. Please refer to the troubleshooting section on the wiki. Error:\n{err}"
@pytest.mark.skip_end_to_end
def test_basicScene(python_version):
""" 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("tests", "tests_data", "basic_scenes.py")
- path_output = os.path.join("tests", "tests_cache", "media_temp")
+ path_basic_scene = os.path.join("tests_data", "basic_scenes.py")
+ path_output = os.path.join("tests_cache", "media_temp")
command = [python_version, "-m", "manim", path_basic_scene,
"SquareToCircle", "-l", "--media_dir", path_output]
out, err, exitcode = capture(command)
@@ -42,5 +42,5 @@ def test_WriteStuff(python_version):
out, err, exitcode = capture(command)
assert exitcode == 0, err
assert os.path.exists(os.path.join(
- path_output, "videos", "basic_scenes", "480p15", "WriteStuff.mp4")), err
+ path_output, "videos", "basic_scenes", "480p15", "WriteStuff.mp4")), err
rmtree(path_output)
diff --git a/tests/test_geometry.py b/tests/test_geometry.py
index 5fbd9aa89..5e7a812a5 100644
--- a/tests/test_geometry.py
+++ b/tests/test_geometry.py
@@ -1,11 +1,11 @@
from manim import *
+import numpy as np
from testing_utils import utils_test_scenes, get_scenes_to_test
class CoordinatesTest(Scene):
def construct(self):
dots = [Dot(np.array([x, y, 0])) for x in range(-7, 8) for y in range(-4, 5)]
-
self.play(Animation(VGroup(*dots)))
@@ -99,10 +99,12 @@ class RectangleTest(Scene):
a = Rectangle()
self.play(Animation(a))
+
class RoundedRectangleTest(Scene):
def construct(self):
a = RoundedRectangle()
self.play(Animation(a))
-def test_scenes(get_config_test):
- utils_test_scenes(get_scenes_to_test(__name__), get_config_test, "geometry")
+
+def test_scenes():
+ utils_test_scenes(get_scenes_to_test(__name__), "geometry")
diff --git a/tests/test_graph.py b/tests/test_graph.py
index e2ae2eccb..a4783ef78 100644
--- a/tests/test_graph.py
+++ b/tests/test_graph.py
@@ -11,15 +11,15 @@ class PlotFunctions(GraphScene):
"graph_origin": ORIGIN,
"function_color": RED,
"axes_color": GREEN,
- "x_labeled_nums": range(-10,12,2),
+ "x_labeled_nums": range(-10,12,2),
}
- def construct(self):
+ def construct(self):
constants.TEX_TEMPLATE = TexTemplate()
self.setup_axes()
f = self.get_graph(lambda x: x**2)
self.play(Animation(f))
-def test_scenes(get_config_test):
- utils_test_scenes(get_scenes_to_test(__name__), get_config_test, "graph", caching_needed=True)
+def test_scenes():
+ utils_test_scenes(get_scenes_to_test(__name__), "graph", caching_needed=True)
diff --git a/tests/test_writing.py b/tests/test_writing.py
index 2b53a7059..6a2a6869d 100644
--- a/tests/test_writing.py
+++ b/tests/test_writing.py
@@ -20,7 +20,7 @@ class TextMobjectTest(Scene):
class TexMobjectTest(Scene):
def construct(self):
- #IMPORTANT NOTE : This won't test the abitilty of manim to write/cache latex.
+ #IMPORTANT NOTE : This won't test the abitilty of manim to write/cache latex.
# i.e It will pass even if latex is not installed.
# This is due to the fact that the latex used here has been cached (see test_cache directory)
constants.TEX_TEMPLATE = TexTemplate()
@@ -32,5 +32,5 @@ class TexMobjectTest(Scene):
-def test_scenes(get_config_test):
- utils_test_scenes(get_scenes_to_test(__name__), get_config_test, "writing", caching_needed=True)
+def test_scenes():
+ utils_test_scenes(get_scenes_to_test(__name__), "writing", caching_needed=True)
diff --git a/tests/testing_utils.py b/tests/testing_utils.py
index a5b668d59..6159c43b1 100644
--- a/tests/testing_utils.py
+++ b/tests/testing_utils.py
@@ -6,14 +6,13 @@ import logging
import pytest
from manim import logger
-from manim import dirs
from manim import config
class SceneTester:
"""Class used to test the animations.
- Parameters
+ Parameters
----------
scene_object : :class:`~.Scene`
The scene to be tested
@@ -25,40 +24,31 @@ class SceneTester:
Attributes
-----------
path_tests_medias_cache : : class:`str`
- Path to 'media' folder generated by manim. This folder contains cached data used by some tests.
+ Path to 'media' folder generated by manim. This folder contains cached data used by some tests.
path_tests_data : : class:`str`
Path to the data used for the tests (i.e the pre-rendered frames).
scene : :class:`Scene`
The scene tested
"""
- def __init__(self, scene_object, config_scene, module_tested, caching_needed=False):
+ def __init__(self, scene_object, module_tested, caching_needed=False):
# Disable the the logs, (--quiet is broken) TODO
logging.disable(logging.CRITICAL)
- self.path_tests_medias_cache = os.path.join(
- 'tests', 'tests_cache', module_tested)
- self.path_tests_data = os.path.join(
- 'tests', 'tests_data', module_tested)
+ self.path_tests_medias_cache = os.path.join('tests_cache', module_tested)
+ self.path_tests_data = os.path.join('tests_data', module_tested)
- tex_dir, text_dir = None, None
if caching_needed:
- text_dir = os.path.join(
+ config['text_dir'] = os.path.join(
self.path_tests_medias_cache, scene_object.__name__, 'Text')
- tex_dir = os.path.join(self.path_tests_medias_cache,
- scene_object.__name__, 'Tex')
- conf_dirs = {'media_dir': None,
- 'video_dir': None,
- 'tex_dir': tex_dir,
- 'text_dir': text_dir,
- }
- # PROVISIONAL. To change when #98 is merged. TODO
- config.initialize_directories(conf_dirs)
+ config['tex_dir'] = os.path.join(
+ self.path_tests_medias_cache, scene_object.__name__, 'Tex')
+
# By invoking this, the scene is rendered.
- self.scene = scene_object(**config_scene)
+ self.scene = scene_object()
def load_data(self):
"""Load the np.array of the last frame of a pre-rendered scene. If not found, throw FileNotFoundError.
-
+
Returns
-------
:class:`numpy.array`
@@ -73,7 +63,7 @@ class SceneTester:
return data_loaded
def test(self):
- """ Core of the test. Will compare the pre-rendered frame (get with load_data()) with the frame rendered during the test (get with scene.get_frame())"""
+ """Compare pre-rendered frame to the frame rendered during the test."""
test_result = np.array_equal(self.scene.get_frame(), self.load_data())
assert(
test_result), f"The frames don't match. {str(self.scene).replace('Test', '')} has been modified. Please ignore if it was intended"
@@ -81,34 +71,34 @@ class SceneTester:
def get_scenes_to_test(module_name):
"""Get all Test classes of the module from which it is called. Used to fetch all the SceneTest of the module.
-
+
Parameters
----------
module_name : :class:`str`
- The name of the module tested.
+ The name of the module tested.
Returns
-------
:class:`list`
- The list of all the classes of the module.
+ The list of all the classes of the module.
"""
return inspect.getmembers(sys.modules[module_name], lambda m: inspect.isclass(m) and m.__module__ == module_name)
-def utils_test_scenes(scenes_to_test, CONFIG, module_name, caching_needed=False):
+def utils_test_scenes(scenes_to_test, module_name, caching_needed=False):
for _, scene_tested in scenes_to_test:
- SceneTester(scene_tested, CONFIG, module_name,
+ SceneTester(scene_tested, module_name,
caching_needed=caching_needed).test()
def set_test_scene(scene_object, module_name):
- """Function used to set up the test data for a new feature. This will basically set up a pre-rendered frame for a scene. This is meant to be used only
+ """Function used to set up the test data for a new feature. This will basically set up a pre-rendered frame for a scene. This is meant to be used only
when setting up tests. Please refer to the wiki.
-
+
Parameters
----------
scene_object : :class:`~.Scene`
- The scene with wich we want to set up a new test.
+ The scene with wich we want to set up a new test.
module_name : :class:`str`
The name of the module in which the functionnality tested is contained. For example, 'Write' is contained in the module 'creation'. This will be used in the folder architecture
of '/tests_data'.