-
Notifications
You must be signed in to change notification settings - Fork 8
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. Differential Revision: D58530481
- Loading branch information
1 parent
067e18b
commit 9771c23
Showing
14 changed files
with
65 additions
and
60 deletions.
There are no files selected for viewing
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
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.
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,52 @@ | ||
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" | ||
|
||
|
||
IN_FBCODE = in_fbcode() | ||
|
||
|
||
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) | ||
|
||
|
||
@pytest.fixture() | ||
def nasa_13013() -> torch.Tensor: | ||
arr = np.fromfile(get_reference_video_path(), dtype=np.uint8) | ||
video_tensor = torch.from_numpy(arr) | ||
return video_tensor |