Repository: ManimCommunity/manim
File: tests/test_config.py (Python)

Code before:
            "video_dir": "{media_dir}/test_video",
            "partial_movie_dir": "{media_dir}/test_partial_movie_dir",
            "images_dir": "{media_dir}/test_images",
            "text_dir": "{media_dir}/test_text",
            "tex_dir": "{media_dir}/test_tex",
            "log_dir": "{media_dir}/test_log",
        }
    ):
        scene = MyScene()
        scene.render()

        assert_dir_filled(Path(tmp_path).joinpath("test_sections"))
        assert_file_exists(Path(tmp_path).joinpath("test_sections", "MyScene.json"))

        assert_dir_filled(Path(tmp_path).joinpath("test_video"))
        assert_file_exists(Path(tmp_path).joinpath("test_video", "MyScene.mp4"))

        assert_dir_filled(Path(tmp_path).joinpath("test_partial_movie_dir"))
        assert_file_exists(
            Path(tmp_path).joinpath(
                "test_partial_movie_dir", "partial_movie_file_list.txt"
            )
        )

        # TODO: another example with image output would be nice
        assert_dir_exists(Path(tmp_path).joinpath("test_images"))

        assert_dir_filled(Path(tmp_path).joinpath("test_text"))
        assert_dir_filled(Path(tmp_path).joinpath("test_tex"))
        assert_dir_filled(Path(tmp_path).joinpath("test_log"))


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)

Review comment (suggestion):
There is an easier way to join paths in pathlib with the "/" operator: https://docs.python.org/3/library/pathlib.html#operators.
`Path(tmp_path).joinpath("test_images")` would then become `tmp_path / "test_images"`
Also, I suggest that you first make tmp_path a pathlib object, and then you can use  tmp_path directly, and you don't need to use Path(tmp_path) anymore

Code after:
            "video_dir": "{media_dir}/test_video",
            "partial_movie_dir": "{media_dir}/test_partial_movie_dir",
            "images_dir": "{media_dir}/test_images",
            "text_dir": "{media_dir}/test_text",
            "tex_dir": "{media_dir}/test_tex",
            "log_dir": "{media_dir}/test_log",
        }
    ):
        scene = MyScene()
        scene.render()
        tmp_path = Path(tmp_path)
        assert_dir_filled(tmp_path / "test_sections")
        assert_file_exists(tmp_path / "test_sections/MyScene.json")

        assert_dir_filled(tmp_path / "test_video")
        assert_file_exists(tmp_path / "test_video/MyScene.mp4")

        assert_dir_filled(tmp_path / "test_partial_movie_dir")
        assert_file_exists(
            tmp_path / "test_partial_movie_dir/partial_movie_file_list.txt"
        )

        # TODO: another example with image output would be nice
        assert_dir_exists(tmp_path / "test_images")

        assert_dir_filled(tmp_path / "test_text")
        assert_dir_filled(tmp_path / "test_tex")
        assert_dir_filled(tmp_path / "test_log")


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)