Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

run black and add a test

leotrs43decec40686
diff --git a/manim/_config/utils.py b/manim/_config/utils.py
index 4e1d317d7..87b80af47 100644
--- a/manim/_config/utils.py
+++ b/manim/_config/utils.py
@@ -544,10 +544,10 @@ class ManimConfig(MutableMapping):
# float keys
for key in [
- "background_opacity",
- # the next two are floats but have their own logic, applied later
- # "frame_width",
- # "frame_height",
+ "background_opacity",
+ # the next two are floats but have their own logic, applied later
+ # "frame_width",
+ # "frame_height",
]:
setattr(self, key, parser["CLI"].getfloat(key))
diff --git a/tests/test_config.py b/tests/test_config.py
index f18880d09..65f2c446f 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -72,6 +72,7 @@ def test_digest_file(tmp_path):
[CLI]
media_dir = this_is_my_favorite_path
video_dir = {media_dir}/videos
+ frame_height = 10
"""
)
tmp_cfg.close()
@@ -81,6 +82,49 @@ def test_digest_file(tmp_path):
assert config.get_dir("video_dir") == Path("this_is_my_favorite_path/videos")
+def test_frame_size(tmp_path):
+ """Test that the frame size can be set via config file."""
+ assert np.allclose(config.aspect_ratio, config.pixel_width / config.pixel_height)
+ assert np.allclose(config.frame_height, 8.0)
+
+ with tempconfig({}):
+ tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
+ tmp_cfg.write(
+ """
+ [CLI]
+ pixel_height = 10
+ pixel_width = 10
+ """
+ )
+ tmp_cfg.close()
+ config.digest_file(tmp_cfg.name)
+
+ # aspect ratio is set using pixel measurements
+ assert np.allclose(config.aspect_ratio, 1.0)
+ # if not specified in the cfg file, frame_width is set using the aspect ratio
+ assert np.allclose(config.frame_height, 8.0)
+ assert np.allclose(config.frame_width, 8.0)
+
+ with tempconfig({}):
+ tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
+ tmp_cfg.write(
+ """
+ [CLI]
+ pixel_height = 10
+ pixel_width = 10
+ frame_height = 10
+ frame_width = 10
+ """
+ )
+ tmp_cfg.close()
+ config.digest_file(tmp_cfg.name)
+
+ assert np.allclose(config.aspect_ratio, 1.0)
+ # if both are specified in the cfg file, the aspect ratio is ignored
+ assert np.allclose(config.frame_height, 10.0)
+ assert np.allclose(config.frame_width, 10.0)
+
+
def test_temporary_dry_run():
"""Test that tempconfig correctly restores after setting dry_run."""
assert config["write_to_movie"]