Skip to content

Commit b9ddf7d

Browse files
friedfacebook-github-bot
authored andcommitted
pytorch/torchcodec - 3.12 fixes
Summary: Noticed the abandoned codemod and figured I would fix the test. importlib.resources.path has always returned a context manger, but I guess it was pathlike before so nobody bothered using it. So going back to the introduction of importlib.resources in 3.7 its been a context manager so this is safe. Differential Revision: D77327183
1 parent 1f8e02e commit b9ddf7d

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

test/test_ops.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import io
88
import os
9+
import contextlib
910
from functools import partial
1011

1112
os.environ["TORCH_LOGS"] = "output_code"
@@ -555,11 +556,8 @@ def test_color_conversion_library_with_dimension_order(
555556
def test_color_conversion_library_with_generated_videos(
556557
self, tmp_path, width, height, width_scaling_factor, height_scaling_factor
557558
):
558-
ffmpeg_cli = "ffmpeg"
559-
if os.environ.get("IN_FBCODE_TORCHCODEC") == "1":
560-
import importlib.resources
561-
562-
ffmpeg_cli = importlib.resources.path(__package__, "ffmpeg")
559+
560+
563561
# We consider filtergraph to be the reference color conversion library.
564562
# However the video decoder sometimes uses swscale as that is faster.
565563
# The exact color conversion library used is an implementation detail
@@ -573,22 +571,30 @@ def test_color_conversion_library_with_generated_videos(
573571
# We don't specify a particular encoder because the ffmpeg binary could
574572
# be configured with different encoders. For the purposes of this test,
575573
# the actual encoder is irrelevant.
576-
command = [
577-
ffmpeg_cli,
578-
"-y",
579-
"-f",
580-
"lavfi",
581-
"-i",
582-
"color=blue",
583-
"-pix_fmt",
584-
"yuv420p",
585-
"-s",
586-
f"{width}x{height}",
587-
"-frames:v",
588-
"1",
589-
video_path,
590-
]
591-
subprocess.check_call(command)
574+
with contextlib.ExitStack() as stack:
575+
ffmpeg_cli = "ffmpeg"
576+
577+
if os.environ.get("IN_FBCODE_TORCHCODEC") == "1":
578+
import importlib.resources
579+
580+
ffmpeg_cli = stack.enter_context(importlib.resources.path(__package__, "ffmpeg"))
581+
582+
command = [
583+
ffmpeg_cli,
584+
"-y",
585+
"-f",
586+
"lavfi",
587+
"-i",
588+
"color=blue",
589+
"-pix_fmt",
590+
"yuv420p",
591+
"-s",
592+
f"{width}x{height}",
593+
"-frames:v",
594+
"1",
595+
video_path,
596+
]
597+
subprocess.check_call(command)
592598

593599
decoder = create_from_file(str(video_path))
594600
add_video_stream(decoder)

0 commit comments

Comments
 (0)