From 508eee16835df5eafd120830a1b8faeb6155dde4 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 8 Jul 2024 07:02:06 -0700 Subject: [PATCH] Remove reference_video_tensor() fixture (#62) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: This PR removes `reference_video_tensor()` because its unnecessary. I assume the use of this fixture was used to cache the corresponding returned value. This is unnecessary for 2 reasons: - The fixture wasn't even cached anyway, because its scope wasn't set to `"session"`. You can verify that by printing something within the fixture, and running tests with `pytest -s`. You'll see the print statement being executed each time, proving that no caching was involved. - Getting the return value is dead cheap and doesn't need to be cached in the first place. Proof: ```py [ins] In [1]: import test_utils tes [nav] In [2]: %timeit test_utils.NASA_VIDEO.to_tensor() 55.8 µs ± 3.76 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each) ``` Pull Request resolved: https://github.com/pytorch-labs/torchcodec/pull/62 Reviewed By: scotts Differential Revision: D59449321 Pulled By: NicolasHug fbshipit-source-id: a848654115054e1526204d697d1d14748808ef91 --- test/samplers/video_clip_sampler_test.py | 12 +++--------- test/test_utils.py | 6 ------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/test/samplers/video_clip_sampler_test.py b/test/samplers/video_clip_sampler_test.py index 64c8e04e..c5bc4951 100644 --- a/test/samplers/video_clip_sampler_test.py +++ b/test/samplers/video_clip_sampler_test.py @@ -10,10 +10,7 @@ VideoClipSampler, ) -from ..test_utils import ( # noqa: F401; see use in test_sampler - assert_tensor_equal, - reference_video_tensor, -) +from ..test_utils import assert_tensor_equal, NASA_VIDEO @pytest.mark.parametrize( @@ -33,15 +30,12 @@ ), ], ) -def test_sampler( - sampler_args, - reference_video_tensor, # noqa: F811; linter does not see this as a use -): +def test_sampler(sampler_args): torch.manual_seed(0) desired_width, desired_height = 320, 240 video_args = VideoArgs(desired_width=desired_width, desired_height=desired_height) sampler = VideoClipSampler(video_args, sampler_args) - clips = sampler(reference_video_tensor) + clips = sampler(NASA_VIDEO.to_tensor()) assert_tensor_equal(len(clips), sampler_args.clips_per_video) clip = clips[0] if isinstance(sampler_args, TimeBasedSamplerArgs): diff --git a/test/test_utils.py b/test/test_utils.py index 999f20ec..a1345f58 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -5,7 +5,6 @@ from dataclasses import dataclass import numpy as np -import pytest import torch @@ -36,11 +35,6 @@ def _load_tensor_from_file(filename: str) -> torch.Tensor: return torch.load(file_path, weights_only=True) -@pytest.fixture() -def reference_video_tensor() -> torch.Tensor: - return NASA_VIDEO.to_tensor() - - @dataclass class TestContainerFile: filename: str