1111
1212import opentimelineio as otio
1313from opentimelineio import test_utils as otio_test_utils
14- from opentimelineio .adapters import file_bundle_utils
1514
1615SAMPLE_DATA_DIR = os .path .join (os .path .dirname (__file__ ), "sample_data" )
17- SCREENING_EXAMPLE_PATH = os .path .join (SAMPLE_DATA_DIR , "screening_example.otio" )
18-
19- MEDIA_EXAMPLE_PATH_REL = os .path .relpath (
20- os .path .join (
21- SAMPLE_DATA_DIR ,
22- 23- )
24- )
25- MEDIA_EXAMPLE_PATH_URL_REL = otio .url_utils .url_from_filepath (
26- MEDIA_EXAMPLE_PATH_REL
27- )
28- MEDIA_EXAMPLE_PATH_ABS = os .path .abspath (
29- MEDIA_EXAMPLE_PATH_REL .replace (
30- "3xDark" ,
31- "3xLight"
32- )
33- )
34- MEDIA_EXAMPLE_PATH_URL_ABS = otio .url_utils .url_from_filepath (
35- MEDIA_EXAMPLE_PATH_ABS
36- )
16+ IMAGE0_EXAMPLE = "[email protected] " 17+ IMAGE0_EXAMPLE_PATH = os .path .join (SAMPLE_DATA_DIR , IMAGE0_EXAMPLE )
18+ IMAGE1_EXAMPLE = "[email protected] " 19+ IMAGE1_EXAMPLE_PATH = os .path .join (SAMPLE_DATA_DIR , IMAGE1_EXAMPLE )
3720
3821
3922class OTIODTester (unittest .TestCase , otio_test_utils .OTIOAssertions ):
4023 def setUp (self ):
41- tl = otio .adapters .read_from_file (SCREENING_EXAMPLE_PATH )
42-
43- # convert to contrived local reference
44- last_rel = False
45- for cl in tl .find_clips ():
46- # vary the relative and absolute paths, make sure that both work
47- next_rel = (
48- MEDIA_EXAMPLE_PATH_URL_REL if last_rel else MEDIA_EXAMPLE_PATH_URL_ABS
49- )
50- last_rel = not last_rel
51- cl .media_reference = otio .schema .ExternalReference (
52- target_url = next_rel
53- )
54-
55- self .tl = tl
56-
57- def test_file_bundle_manifest_missing_reference (self ):
58- # all missing should be empty
59- result_otio , manifest = (
60- file_bundle_utils ._prepped_otio_for_bundle_and_manifest (
61- input_otio = self .tl ,
62- media_policy = file_bundle_utils .MediaReferencePolicy .AllMissing ,
63- adapter_name = "TEST_NAME" ,
64- )
24+ track = otio .schema .Track (name = "track" )
25+ mr0 = otio .schema .ExternalReference (
26+ available_range = otio .opentime .TimeRange (
27+ duration = otio .opentime .RationalTime (1 , 24 )
28+ ),
29+ target_url = IMAGE0_EXAMPLE_PATH
6530 )
66-
67- self .assertEqual (manifest , {})
68- for cl in result_otio .find_clips ():
69- self .assertIsInstance (
70- cl .media_reference ,
71- otio .schema .MissingReference ,
72- "{} is of type {}, not an instance of {}." .format (
73- cl .media_reference ,
74- type (cl .media_reference ),
75- type (otio .schema .MissingReference )
76- )
77- )
78-
79- def test_file_bundle_manifest (self ):
80- result_otio , manifest = (
81- file_bundle_utils ._prepped_otio_for_bundle_and_manifest (
82- input_otio = self .tl ,
83- media_policy = (
84- file_bundle_utils .MediaReferencePolicy .ErrorIfNotFile
85- ),
86- adapter_name = "TEST_NAME" ,
87- )
31+ cl0 = otio .schema .Clip (
32+ name = "clip 0" ,
33+ media_reference = mr0 ,
34+ source_range = otio .opentime .TimeRange (
35+ duration = otio .opentime .RationalTime (24 , 24 )
36+ ),
8837 )
89-
90- self .assertEqual (len (manifest .keys ()), 2 )
91-
92- files_in_manifest = set (manifest .keys ())
93- known_files = {
94- MEDIA_EXAMPLE_PATH_ABS : 5 ,
95- os .path .abspath (MEDIA_EXAMPLE_PATH_REL ): 4
96- }
97-
98- # should only contain absolute paths
99- self .assertEqual (files_in_manifest , set (known_files .keys ()))
100-
101- for fname , count in known_files .items ():
102- self .assertEqual (len (manifest [fname ]), count )
103-
38+ track .append (cl0 )
39+ mr1 = otio .schema .ExternalReference (
40+ available_range = otio .opentime .TimeRange (
41+ duration = otio .opentime .RationalTime (1 , 24 )
42+ ),
43+ target_url = IMAGE1_EXAMPLE_PATH
44+ )
45+ cl1 = otio .schema .Clip (
46+ name = "clip 1" ,
47+ media_reference = mr1 ,
48+ source_range = otio .opentime .TimeRange (
49+ duration = otio .opentime .RationalTime (24 , 24 )
50+ ),
51+ )
52+ track .append (cl1 )
53+ self .tl = otio .schema .Timeline ("test_round_trip" , tracks = [track ])
54+
10455 def test_round_trip (self ):
56+
10557 with tempfile .NamedTemporaryFile (suffix = ".otiod" ) as bogusfile :
10658 tmp_path = bogusfile .name
10759 otio .adapters .write_to_file (self .tl , tmp_path )
10860 self .assertTrue (os .path .exists (tmp_path ))
10961
110- # by default will provide relative paths
111- result = otio .adapters .read_from_file (
112- tmp_path ,
113- )
62+ result = otio .adapters .read_from_file (tmp_path )
11463
115- for cl in result .find_clips ():
116- self .assertNotEqual (
117- cl .media_reference .target_url ,
118- MEDIA_EXAMPLE_PATH_URL_REL
119- )
120-
121- # conform media references in input to what they should be in the output
122- for cl in self .tl .find_clips ():
123- # construct an absolute file path to the result
124- cl .media_reference .target_url = (
125- otio .url_utils .url_from_filepath (
126- os .path .join (
127- otio .adapters .file_bundle_utils .BUNDLE_DIR_NAME ,
128- os .path .basename (cl .media_reference .target_url )
129- )
130- )
131- )
132-
133- self .assertJsonEqual (result , self .tl )
64+ clips = result .find_clips ()
65+ self .assertEqual (
66+ clips [0 ].media_reference .target_url ,
67+ os .path .join ("media" , IMAGE0_EXAMPLE )
68+ )
69+ self .assertEqual (
70+ clips [1 ].media_reference .target_url ,
71+ os .path .join ("media" , IMAGE1_EXAMPLE )
72+ )
13473
13574 def test_round_trip_all_missing_references (self ):
75+
13676 with tempfile .NamedTemporaryFile (suffix = ".otiod" ) as bogusfile :
13777 tmp_path = bogusfile .name
13878 otio .adapters .write_to_file (
13979 self .tl ,
14080 tmp_path ,
14181 media_policy = (
142- otio .adapters . file_bundle_utils .MediaReferencePolicy .AllMissing
82+ otio ._otio . bundle .MediaReferencePolicy .AllMissing
14383 )
14484 )
14585
146- # ...but can be optionally told to generate absolute paths
14786 result = otio .adapters .read_from_file (
14887 tmp_path ,
14988 absolute_media_reference_paths = True
@@ -156,36 +95,25 @@ def test_round_trip_all_missing_references(self):
15695 )
15796
15897 def test_round_trip_absolute_paths (self ):
98+
15999 with tempfile .NamedTemporaryFile (suffix = ".otiod" ) as bogusfile :
160100 tmp_path = bogusfile .name
161101 otio .adapters .write_to_file (self .tl , tmp_path )
162102
163- # ...but can be optionally told to generate absolute paths
164103 result = otio .adapters .read_from_file (
165104 tmp_path ,
166105 absolute_media_reference_paths = True
167106 )
168107
169- for cl in result .find_clips ():
170- self .assertNotEqual (
171- cl .media_reference .target_url ,
172- MEDIA_EXAMPLE_PATH_URL_REL
173- )
174-
175- # conform media references in input to what they should be in the output
176- for cl in self .tl .find_clips ():
177- # should be only field that changed
178- cl .media_reference .target_url = (
179- otio .url_utils .url_from_filepath (
180- os .path .join (
181- tmp_path ,
182- otio .adapters .file_bundle_utils .BUNDLE_DIR_NAME ,
183- os .path .basename (cl .media_reference .target_url )
184- )
185- )
186- )
187-
188- self .assertJsonEqual (result , self .tl )
108+ clips = result .find_clips ()
109+ self .assertEqual (
110+ clips [0 ].media_reference .target_url ,
111+ "file://" + os .path .join (tmp_path , "media" , IMAGE0_EXAMPLE )
112+ )
113+ self .assertEqual (
114+ clips [1 ].media_reference .target_url ,
115+ "file://" + os .path .join (tmp_path , "media" , IMAGE1_EXAMPLE )
116+ )
189117
190118
191119if __name__ == "__main__" :
0 commit comments