Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpret empty VIDEO_CACHE_DIR as None #245

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/test_load_video_frames.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
import pytest
import shutil
import subprocess
Expand Down Expand Up @@ -583,3 +584,14 @@ def test_caching(tmp_path, caplog, train_metadata):
).__getitem__(index=0)[0]

assert np.array_equal(no_config, config_with_nones)


def test_validate_video_cache_dir():
with mock.patch.dict(os.environ, {"VIDEO_CACHE_DIR": "example_cache_dir"}):
config = VideoLoaderConfig()
assert config.cache_dir == Path("example_cache_dir")

for cache in ["", 0]:
with mock.patch.dict(os.environ, {"VIDEO_CACHE_DIR": str(cache)}):
config = VideoLoaderConfig()
assert config.cache_dir is None
3 changes: 3 additions & 0 deletions zamba/data/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ def validate_video_cache_dir(cls, cache_dir):
if cache_dir is None:
cache_dir = os.getenv("VIDEO_CACHE_DIR", None)

if cache_dir in ["", "0"]:
cache_dir = None

if cache_dir is not None:
cache_dir = Path(cache_dir)
cache_dir.mkdir(parents=True, exist_ok=True)
Expand Down