|
7 | 7 |
|
8 | 8 | # python |
9 | 9 | import os |
10 | | -import tempfile |
11 | | -from tempfile import TemporaryDirectory # noqa: F401 |
| 10 | +from pathlib import Path |
12 | 11 |
|
13 | 12 | import pytest |
14 | 13 | import opentimelineio as otio |
@@ -223,60 +222,62 @@ def test_edl_round_trip_mem2disk2mem(cmx_adapter, assertJsonEqual): |
223 | 222 | cmx_adapter.write_to_string(tl) |
224 | 223 |
|
225 | 224 |
|
226 | | -def test_edl_round_trip_disk2mem2disk_speed_effects(cmx_adapter, assertJsonEqual): |
| 225 | +def test_edl_round_trip_disk2mem2disk_speed_effects( |
| 226 | + cmx_adapter, assertJsonEqual, tmp_path: Path |
| 227 | +): |
227 | 228 | test_edl = SPEED_EFFECTS_TEST_SMALL |
228 | 229 | timeline = cmx_adapter.read_from_file(test_edl) |
229 | 230 |
|
230 | | - with tempfile.TemporaryDirectory() as temp_dir: |
231 | | - tmp_path = os.path.join( |
232 | | - temp_dir, "test_edl_round_trip_disk2mem2disk_speed_effects.edl" |
233 | | - ) |
| 231 | + tmp_path = os.path.join( |
| 232 | + tmp_path, "test_edl_round_trip_disk2mem2disk_speed_effects.edl" |
| 233 | + ) |
234 | 234 |
|
235 | | - cmx_adapter.write_to_file(timeline, tmp_path) |
| 235 | + cmx_adapter.write_to_file(timeline, tmp_path) |
236 | 236 |
|
237 | | - result = cmx_adapter.read_from_file(tmp_path) |
| 237 | + result = cmx_adapter.read_from_file(tmp_path) |
238 | 238 |
|
239 | | - # When debugging, you can use this to see the difference in the OTIO |
240 | | - # cmx_3600.otio_json.write_to_file(timeline, "/tmp/original.otio") |
241 | | - # cmx_3600.otio_json.write_to_file(result, "/tmp/output.otio") |
242 | | - # os.system("xxdiff /tmp/{original,output}.otio") |
| 239 | + # When debugging, you can use this to see the difference in the OTIO |
| 240 | + # cmx_3600.otio_json.write_to_file(timeline, "/tmp/original.otio") |
| 241 | + # cmx_3600.otio_json.write_to_file(result, "/tmp/output.otio") |
| 242 | + # os.system("xxdiff /tmp/{original,output}.otio") |
243 | 243 |
|
244 | | - # When debugging, use this to see the difference in the EDLs on disk |
245 | | - # os.system("xxdiff {} {}&".format(test_edl, tmp_path)) |
| 244 | + # When debugging, use this to see the difference in the EDLs on disk |
| 245 | + # os.system("xxdiff {} {}&".format(test_edl, tmp_path)) |
246 | 246 |
|
247 | | - # The in-memory OTIO representation should be the same |
| 247 | + # The in-memory OTIO representation should be the same |
248 | 248 | assertJsonEqual(timeline, result) |
249 | 249 |
|
250 | 250 |
|
251 | | -def test_edl_round_trip_disk2mem2disk(cmx_adapter, assertIsOTIOEquivalentTo): |
| 251 | +def test_edl_round_trip_disk2mem2disk( |
| 252 | + cmx_adapter, assertIsOTIOEquivalentTo, tmp_path: Path |
| 253 | +): |
252 | 254 | timeline = cmx_adapter.read_from_file(SCREENING_EXAMPLE_PATH) |
253 | 255 |
|
254 | | - with tempfile.TemporaryDirectory() as temp_dir: |
255 | | - tmp_path = os.path.join(temp_dir, "test_edl_round_trip_disk2mem2disk.edl") |
| 256 | + tmp_path = os.path.join(tmp_path, "test_edl_round_trip_disk2mem2disk.edl") |
256 | 257 |
|
257 | | - cmx_adapter.write_to_file(timeline, tmp_path) |
| 258 | + cmx_adapter.write_to_file(timeline, tmp_path) |
258 | 259 |
|
259 | | - result = cmx_adapter.read_from_file(tmp_path) |
| 260 | + result = cmx_adapter.read_from_file(tmp_path) |
260 | 261 |
|
261 | | - # When debugging, you can use this to see the difference in the OTIO |
262 | | - # cmx_3600.otio_json.write_to_file(timeline, "/tmp/original.otio") |
263 | | - # cmx_3600.otio_json.write_to_file(result, "/tmp/output.otio") |
264 | | - # os.system("opendiff /tmp/{original,output}.otio") |
| 262 | + # When debugging, you can use this to see the difference in the OTIO |
| 263 | + # cmx_3600.otio_json.write_to_file(timeline, "/tmp/original.otio") |
| 264 | + # cmx_3600.otio_json.write_to_file(result, "/tmp/output.otio") |
| 265 | + # os.system("opendiff /tmp/{original,output}.otio") |
265 | 266 |
|
266 | | - original_json = otio.adapters.write_to_string(timeline, "otio_json") |
267 | | - output_json = otio.adapters.write_to_string(result, "otio_json") |
268 | | - assert original_json == output_json |
| 267 | + original_json = otio.adapters.write_to_string(timeline, "otio_json") |
| 268 | + output_json = otio.adapters.write_to_string(result, "otio_json") |
| 269 | + assert original_json == output_json |
269 | 270 |
|
270 | | - # The in-memory OTIO representation should be the same |
271 | | - assertIsOTIOEquivalentTo(timeline, result) |
| 271 | + # The in-memory OTIO representation should be the same |
| 272 | + assertIsOTIOEquivalentTo(timeline, result) |
272 | 273 |
|
273 | | - # When debugging, use this to see the difference in the EDLs on disk |
274 | | - # os.system("opendiff {} {}".format(SCREENING_EXAMPLE_PATH, tmp_path)) |
| 274 | + # When debugging, use this to see the difference in the EDLs on disk |
| 275 | + # os.system("opendiff {} {}".format(SCREENING_EXAMPLE_PATH, tmp_path)) |
275 | 276 |
|
276 | | - # But the EDL text on disk are *not* byte-for-byte identical |
277 | | - with open(SCREENING_EXAMPLE_PATH) as original_file: |
278 | | - with open(tmp_path) as output_file: |
279 | | - assert original_file.read() != output_file.read() |
| 277 | + # But the EDL text on disk are *not* byte-for-byte identical |
| 278 | + with open(SCREENING_EXAMPLE_PATH) as original_file: |
| 279 | + with open(tmp_path) as output_file: |
| 280 | + assert original_file.read() != output_file.read() |
280 | 281 |
|
281 | 282 |
|
282 | 283 | def test_regex_flexibility(cmx_adapter, assertIsOTIOEquivalentTo): |
@@ -521,34 +522,33 @@ def test_fade_to_black(cmx_adapter): |
521 | 522 | assert tl.tracks[0][2].source_range.start_time.value == 0 |
522 | 523 |
|
523 | 524 |
|
524 | | -def test_edl_round_trip_with_transitions(cmx_adapter): |
525 | | - with tempfile.TemporaryDirectory() as temp_dir: |
526 | | - # Notes: |
527 | | - # - the writer does not handle wipes, only dissolves |
528 | | - # - the writer can generate invalid EDLs if spaces are in reel names. |
529 | | - for edl_file in [ |
530 | | - DISSOLVE_TEST, |
531 | | - DISSOLVE_TEST_2, |
532 | | - DISSOLVE_TEST_3, |
533 | | - DISSOLVE_TEST_4, |
534 | | - ]: |
535 | | - edl_name = os.path.basename(edl_file) |
536 | | - timeline = cmx_adapter.read_from_file(edl_file) |
537 | | - tmp_path = os.path.join(temp_dir, f"test_edl_round_trip_{edl_name}") |
538 | | - cmx_adapter.write_to_file(timeline, tmp_path) |
539 | | - |
540 | | - result = cmx_adapter.read_from_file(tmp_path) |
541 | | - assert len(timeline.tracks) == len(result.tracks) |
542 | | - for track, res_track in zip(timeline.tracks, result.tracks): |
543 | | - assert len(track) == len(res_track) |
544 | | - for child, res_child in zip(track, res_track): |
545 | | - assert type(child) is type(res_child) |
546 | | - if isinstance(child, otio.schema.Transition): |
547 | | - assert child.in_offset == res_child.in_offset |
548 | | - assert child.out_offset == res_child.out_offset |
549 | | - assert child.transition_type == res_child.transition_type |
550 | | - else: |
551 | | - assert child.source_range == res_child.source_range |
| 525 | +DISSOLVE_TESTS = [DISSOLVE_TEST, DISSOLVE_TEST_2, DISSOLVE_TEST_3, DISSOLVE_TEST_4] |
| 526 | + |
| 527 | + |
| 528 | +@pytest.mark.parametrize( |
| 529 | + "edl_file", DISSOLVE_TESTS, ids=[os.path.basename(path) for path in DISSOLVE_TESTS] |
| 530 | +) |
| 531 | +def test_edl_round_trip_with_transitions(cmx_adapter, tmp_path: Path, edl_file): |
| 532 | + # Notes: |
| 533 | + # - the writer does not handle wipes, only dissolves |
| 534 | + # - the writer can generate invalid EDLs if spaces are in reel names. |
| 535 | + edl_name = os.path.basename(edl_file) |
| 536 | + timeline = cmx_adapter.read_from_file(edl_file) |
| 537 | + tmp_path = os.path.join(tmp_path, f"test_edl_round_trip_{edl_name}") |
| 538 | + cmx_adapter.write_to_file(timeline, tmp_path) |
| 539 | + |
| 540 | + result = cmx_adapter.read_from_file(tmp_path) |
| 541 | + assert len(timeline.tracks) == len(result.tracks) |
| 542 | + for track, res_track in zip(timeline.tracks, result.tracks): |
| 543 | + assert len(track) == len(res_track) |
| 544 | + for child, res_child in zip(track, res_track): |
| 545 | + assert type(child) is type(res_child) |
| 546 | + if isinstance(child, otio.schema.Transition): |
| 547 | + assert child.in_offset == res_child.in_offset |
| 548 | + assert child.out_offset == res_child.out_offset |
| 549 | + assert child.transition_type == res_child.transition_type |
| 550 | + else: |
| 551 | + assert child.source_range == res_child.source_range |
552 | 552 |
|
553 | 553 |
|
554 | 554 | def test_edl_25fps(cmx_adapter): |
|
0 commit comments