A community-maintained Python framework for creating mathematical animations.
Fix png format issue when using dry run (#1792)
Ryan McCauley4e38f95e2904
diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.pyindex 19e659ff2..cae0acff4 100644--- a/manim/scene/scene_file_writer.py+++ b/manim/scene/scene_file_writer.py@@ -83,9 +83,9 @@ class SceneFileWriter(object):image_dir = guarantee_existence(config.get_dir("images_dir", module_name=module_name))- self.image_file_path = os.path.join(- image_dir, add_extension_if_not_present(default_name, ".png")- )+ self.image_file_path = os.path.join(+ image_dir, add_extension_if_not_present(default_name, ".png")+ )if write_to_movie():movie_dir = guarantee_existence(@@ -288,7 +288,7 @@ class SceneFileWriter(object):frame = frame_or_rendererif write_to_movie():self.writing_process.stdin.write(frame.tobytes())- if is_png_format():+ if is_png_format() and not config["dry_run"]:target_dir, extension = os.path.splitext(self.image_file_path)Image.fromarray(frame).save(f"{target_dir}{self.frame_count}{extension}"@@ -305,6 +305,8 @@ class SceneFileWriter(object):image : np.arrayThe pixel array of the image to save."""+ if config["dry_run"]:+ returnif not config["output_file"]:self.image_file_path = add_version_before_extension(self.image_file_path)@@ -347,7 +349,7 @@ class SceneFileWriter(object):self.flush_cache_directory()else:self.clean_cache()- elif is_png_format():+ elif is_png_format() and not config["dry_run"]:target_dir, _ = os.path.splitext(self.image_file_path)logger.info("\n%i images ready at %s\n", self.frame_count, target_dir)diff --git a/tests/test_config.py b/tests/test_config.pyindex bd60072d4..9fa818a66 100644--- a/tests/test_config.py+++ b/tests/test_config.py@@ -137,3 +137,23 @@ def test_temporary_dry_run():assert config["write_to_movie"]assert not config["save_last_frame"]+++def test_dry_run_with_png_format():+ """Test that there are no exceptions when running a png without output"""+ with tempconfig(+ {"write_to_movie": False, "disable_caching": True, "format": "png"}+ ):+ assert config["dry_run"] is True+ scene = MyScene()+ scene.render()+++def test_dry_run_with_png_format_skipped_animations():+ """Test that there are no exceptions when running a png without output and skipped animations"""+ with tempconfig(+ {"write_to_movie": False, "disable_caching": True, "format": "png"}+ ):+ assert config["dry_run"] is True+ scene = MyScene(skip_animations=True)+ scene.render()