Skip to content

Commit

Permalink
add new download_test_assets.py script
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Sep 11, 2024
1 parent 2d0e9f3 commit 05b0c38
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
video
52 changes: 52 additions & 0 deletions tests/assets/download_test_assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Downloads test assets used by tests.
Usage:
pixi run python ./tests/assets/download_assets.py
"""

from __future__ import annotations

import os
from pathlib import Path
from typing import Final

import requests
import tqdm

test_assets = ["video/Big_Buck_Bunny_1080_10s_av1.mp4"]

test_asset_base_url = "https://storage.googleapis.com/rerun-test-assets/"


def download_file(url: str, dst_file_path: Path) -> None:
"""Download file from url to dst_fpath."""
dst_file_path.parent.mkdir(parents=True, exist_ok=True)
print(f"Downloading {url} to {dst_file_path}")
response = requests.get(url, stream=True)
with tqdm.tqdm.wrapattr(
open(dst_file_path, "wb"),
"write",
miniters=1,
total=int(response.headers.get("content-length", 0)),
desc=f"Downloading {dst_file_path.name}",
) as f:
for chunk in response.iter_content(chunk_size=4096):
f.write(chunk)


def main() -> None:
"""Downloads all test assets."""

test_asset_dir: Final = Path(os.path.dirname(__file__))

for asset in test_assets:
target_file = test_asset_dir / asset
if not target_file.exists():
download_file(test_asset_base_url + asset, target_file)
else:
print(f'Skipping "{asset}" because it already exists.')


if __name__ == "__main__":
main()

0 comments on commit 05b0c38

Please sign in to comment.