Skip to content

Commit 6884db0

Browse files
Use pytest's tmp_path instead of tempfile module
Signed-off-by: Jean-Christophe Morin <jean_christophe_morin@hotmail.com>
1 parent ee7551e commit 6884db0

1 file changed

Lines changed: 64 additions & 64 deletions

File tree

tests/test_cmx_3600_adapter.py

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
# python
99
import os
10-
import tempfile
11-
from tempfile import TemporaryDirectory # noqa: F401
10+
from pathlib import Path
1211

1312
import pytest
1413
import opentimelineio as otio
@@ -223,60 +222,62 @@ def test_edl_round_trip_mem2disk2mem(cmx_adapter, assertJsonEqual):
223222
cmx_adapter.write_to_string(tl)
224223

225224

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+
):
227228
test_edl = SPEED_EFFECTS_TEST_SMALL
228229
timeline = cmx_adapter.read_from_file(test_edl)
229230

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+
)
234234

235-
cmx_adapter.write_to_file(timeline, tmp_path)
235+
cmx_adapter.write_to_file(timeline, tmp_path)
236236

237-
result = cmx_adapter.read_from_file(tmp_path)
237+
result = cmx_adapter.read_from_file(tmp_path)
238238

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")
243243

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))
246246

247-
# The in-memory OTIO representation should be the same
247+
# The in-memory OTIO representation should be the same
248248
assertJsonEqual(timeline, result)
249249

250250

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+
):
252254
timeline = cmx_adapter.read_from_file(SCREENING_EXAMPLE_PATH)
253255

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")
256257

257-
cmx_adapter.write_to_file(timeline, tmp_path)
258+
cmx_adapter.write_to_file(timeline, tmp_path)
258259

259-
result = cmx_adapter.read_from_file(tmp_path)
260+
result = cmx_adapter.read_from_file(tmp_path)
260261

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")
265266

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
269270

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)
272273

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))
275276

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()
280281

281282

282283
def test_regex_flexibility(cmx_adapter, assertIsOTIOEquivalentTo):
@@ -521,34 +522,33 @@ def test_fade_to_black(cmx_adapter):
521522
assert tl.tracks[0][2].source_range.start_time.value == 0
522523

523524

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
552552

553553

554554
def test_edl_25fps(cmx_adapter):

0 commit comments

Comments
 (0)