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

Code before:

    Refer to the documentation for more information.

    Parameters
    ----------
    path_to_video : :class:`str`
        Path to the video to extract information from.
    name : :class:`str`
        Name of the test. The .json file will be named with it.

    See Also
    --------

    tests/utils/video_tester.py : read control data and compare with output of test
    """
    orig_path_to_sections = Path(path_to_video)
    path_to_sections = orig_path_to_sections.parent.absolute().joinpath("sections")
    tests_directory = Path(__file__).absolute().parent.parent
    path_control_data = Path(tests_directory).joinpath("control_data", "videos_data")
    # this is the name of the section used in the test, not the name of the test itself, it can be found as a parameter of this function
    scene_name = orig_path_to_sections.stem

    movie_metadata = get_video_metadata(path_to_video)
    section_dir_layout = get_section_dir_layout(str(path_to_sections))
    section_index = get_section_index(
        str(Path(path_to_sections).joinpath(f"{scene_name}.json"))
    )
    data = {
        "name": name,
        "movie_metadata": movie_metadata,
        "section_dir_layout": section_dir_layout,
        "section_index": section_index,
    }
    path_saved = Path(path_control_data).joinpath(f"{name}.json")
    with open(path_saved, "w") as f:
        json.dump(data, f, indent=4)
    logger.info(f"Data for {name} saved in {path_saved}")


Review comment (suggestion):
You seem to have taken the migration a bit too seriously I suppose.

Make sure you aren't doing things like this where you make a `Path` and then immediately cast to a `str`.
Make `Path`s at places only where you can see it makes sense to do so.

Code after:
    Refer to the documentation for more information.

    Parameters
    ----------
    path_to_video : :class:`str`
        Path to the video to extract information from.
    name : :class:`str`
        Name of the test. The .json file will be named with it.

    See Also
    --------

    tests/utils/video_tester.py : read control data and compare with output of test
    """
    orig_path_to_sections = Path(path_to_video)
    path_to_sections = orig_path_to_sections.parent.absolute() / "sections"
    tests_directory = Path(__file__).absolute().parent.parent
    path_control_data = Path(tests_directory) / "control_data" / "videos_data"
    # this is the name of the section used in the test, not the name of the test itself, it can be found as a parameter of this function
    scene_name = orig_path_to_sections.stem

    movie_metadata = get_video_metadata(path_to_video)
    section_dir_layout = get_section_dir_layout(path_to_sections)
    section_index = get_section_index(path_to_sections / f"{scene_name}.json")

    data = {
        "name": name,
        "movie_metadata": movie_metadata,
        "section_dir_layout": section_dir_layout,
        "section_index": section_index,
    }
    path_saved = Path(path_control_data) / f"{name}.json"
    with open(path_saved, "w") as f:
        json.dump(data, f, indent=4)
    logger.info(f"Data for {name} saved in {path_saved}")