-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[torchcodec] refactor test utils into its own library (#25)
Summary: Pull Request resolved: #25 Refactors utility functions that were defined directly in test source files into a library that can be shared among tests. This diff: 1. Creates a Python test utility library that can be imported by Python tests. 2. Moves the test resources to the test top-level. 3. Defines a C++ target for those resources. This is in preparation for adding new tests that will need this library. Reviewed By: NicolasHug Differential Revision: D58530481
- Loading branch information
1 parent
473e20e
commit 34f86ca
Showing
17 changed files
with
72 additions
and
69 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import importlib | ||
import os | ||
import pathlib | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
import torch | ||
|
||
|
||
def in_fbcode() -> bool: | ||
return os.environ.get("IN_FBCODE_TORCHCODEC") == "1" | ||
|
||
|
||
def assert_equal(*args, **kwargs): | ||
torch.testing.assert_close(*args, **kwargs, atol=0, rtol=0) | ||
|
||
|
||
def get_video_path(filename: str) -> pathlib.Path: | ||
if in_fbcode(): | ||
resource = ( | ||
importlib.resources.files(__spec__.parent) | ||
.joinpath("resources") | ||
.joinpath(filename) | ||
) | ||
with importlib.resources.as_file(resource) as path: | ||
return path | ||
else: | ||
return pathlib.Path(__file__).parent / "resources" / filename | ||
|
||
|
||
def get_reference_video_path() -> pathlib.Path: | ||
return get_video_path("nasa_13013.mp4") | ||
|
||
|
||
def get_reference_audio_path() -> pathlib.Path: | ||
return get_video_path("nasa_13013.mp4.audio.mp3") | ||
|
||
|
||
def load_tensor_from_file(filename: str) -> torch.Tensor: | ||
file_path = get_video_path(filename) | ||
return torch.load(file_path) | ||
|
||
|
||
def get_reference_video_tensor() -> torch.Tensor: | ||
arr = np.fromfile(get_reference_video_path(), dtype=np.uint8) | ||
video_tensor = torch.from_numpy(arr) | ||
return video_tensor | ||
|
||
|
||
@pytest.fixture() | ||
def reference_video_tensor() -> torch.Tensor: | ||
return get_reference_video_tensor() |