33from __future__ import annotations
44
55import json
6- import os
7- import pathlib
6+ from pathlib import Path
87from typing import Any
98
109from manim import get_dir_layout , get_video_metadata , logger
1110
1211
13- def get_section_dir_layout (dirpath : str ) -> list [str ]:
12+ def get_section_dir_layout (dirpath : Path ) -> list [str ]:
1413 """Return a list of all files in the sections directory."""
1514 # test if sections have been created in the first place, doesn't work with multiple scene but this isn't an issue with tests
16- if not os . path . isdir ( dirpath ):
15+ if not dirpath . is_dir ( ):
1716 return []
18- files = get_dir_layout (dirpath )
17+ files = list ( get_dir_layout (dirpath ) )
1918 # indicate that the sections directory has been created
2019 files .append ("." )
2120 return files
2221
2322
24- def get_section_index (metapath : str ) -> list [dict [str , Any ]]:
23+ def get_section_index (metapath : Path ) -> list [dict [str , Any ]]:
2524 """Return content of sections index file."""
26- parent_folder = pathlib . Path ( metapath ) .parent .absolute ()
25+ parent_folder = metapath .parent .absolute ()
2726 # test if sections have been created in the first place
28- if not os . path . isdir ( parent_folder ):
27+ if not parent_folder . is_dir ( ):
2928 return []
30- with open (metapath ) as file :
29+ with metapath . open () as file :
3130 index = json .load (file )
3231 return index
3332
@@ -51,28 +50,27 @@ def save_control_data_from_video(path_to_video: str, name: str) -> None:
5150
5251 See Also
5352 --------
53+
5454 tests/utils/video_tester.py : read control data and compare with output of test
5555 """
56- path_to_sections = os .path .join (
57- pathlib .Path (path_to_video ).parent .absolute (), "sections"
58- )
59- tests_directory = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
60- path_control_data = os .path .join (tests_directory , "control_data" , "videos_data" )
56+ orig_path_to_sections = Path (path_to_video )
57+ path_to_sections = orig_path_to_sections .parent .absolute () / "sections"
58+ tests_directory = Path (__file__ ).absolute ().parent .parent
59+ path_control_data = Path (tests_directory ) / "control_data" / "videos_data"
6160 # 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
62- scene_name = "" . join ( os . path . basename ( path_to_video ). split ( "." )[: - 1 ])
61+ scene_name = orig_path_to_sections . stem
6362
6463 movie_metadata = get_video_metadata (path_to_video )
6564 section_dir_layout = get_section_dir_layout (path_to_sections )
66- section_index = get_section_index (
67- os .path .join (path_to_sections , f"{ scene_name } .json" )
68- )
65+ section_index = get_section_index (path_to_sections / f"{ scene_name } .json" )
66+
6967 data = {
7068 "name" : name ,
7169 "movie_metadata" : movie_metadata ,
7270 "section_dir_layout" : section_dir_layout ,
7371 "section_index" : section_index ,
7472 }
75- path_saved = os . path . join (path_control_data , f"{ name } .json" )
73+ path_saved = Path (path_control_data ) / f"{ name } .json"
7674 with open (path_saved , "w" ) as f :
7775 json .dump (data , f , indent = 4 )
7876 logger .info (f"Data for { name } saved in { path_saved } " )
0 commit comments