3
3
from __future__ import annotations
4
4
5
5
import json
6
- import os
7
- import pathlib
6
+ from pathlib import Path
8
7
from typing import Any
9
8
10
9
from manim import get_dir_layout , get_video_metadata , logger
11
10
12
11
13
- def get_section_dir_layout (dirpath : str ) -> list [str ]:
12
+ def get_section_dir_layout (dirpath : Path ) -> list [str ]:
14
13
"""Return a list of all files in the sections directory."""
15
14
# 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 ( ):
17
16
return []
18
- files = get_dir_layout (dirpath )
17
+ files = list ( get_dir_layout (dirpath ) )
19
18
# indicate that the sections directory has been created
20
19
files .append ("." )
21
20
return files
22
21
23
22
24
- def get_section_index (metapath : str ) -> list [dict [str , Any ]]:
23
+ def get_section_index (metapath : Path ) -> list [dict [str , Any ]]:
25
24
"""Return content of sections index file."""
26
- parent_folder = pathlib . Path ( metapath ) .parent .absolute ()
25
+ parent_folder = metapath .parent .absolute ()
27
26
# 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 ( ):
29
28
return []
30
- with open (metapath ) as file :
29
+ with metapath . open () as file :
31
30
index = json .load (file )
32
31
return index
33
32
@@ -51,28 +50,27 @@ def save_control_data_from_video(path_to_video: str, name: str) -> None:
51
50
52
51
See Also
53
52
--------
53
+
54
54
tests/utils/video_tester.py : read control data and compare with output of test
55
55
"""
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"
61
60
# 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
63
62
64
63
movie_metadata = get_video_metadata (path_to_video )
65
64
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
+
69
67
data = {
70
68
"name" : name ,
71
69
"movie_metadata" : movie_metadata ,
72
70
"section_dir_layout" : section_dir_layout ,
73
71
"section_index" : section_index ,
74
72
}
75
- path_saved = os . path . join (path_control_data , f"{ name } .json" )
73
+ path_saved = Path (path_control_data ) / f"{ name } .json"
76
74
with open (path_saved , "w" ) as f :
77
75
json .dump (data , f , indent = 4 )
78
76
logger .info (f"Data for { name } saved in { path_saved } " )
0 commit comments