From 2d0e9f386e33c08067759678584dd4bd0f1f07e1 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 11 Sep 2024 13:51:36 +0200 Subject: [PATCH 1/3] move doc assets to test assets folder --- docs/snippets/snippets.toml | 6 +++--- rerun_py/tests/unit/test_asset3d.py | 2 +- {docs => tests}/assets/cube.glb | Bin {docs => tests}/assets/empty.mp4 | Bin 4 files changed, 4 insertions(+), 4 deletions(-) rename {docs => tests}/assets/cube.glb (100%) rename {docs => tests}/assets/empty.mp4 (100%) diff --git a/docs/snippets/snippets.toml b/docs/snippets/snippets.toml index 3beb648328f9..c9c75ab6e988 100644 --- a/docs/snippets/snippets.toml +++ b/docs/snippets/snippets.toml @@ -185,6 +185,6 @@ quick_start = [ # These examples don't have exactly the same implementation. # `$config_dir` will be replaced with the absolute path of `docs/snippets`. [extra_args] -"archetypes/asset3d_simple" = ["$config_dir/../assets/cube.glb"] -"archetypes/asset3d_out_of_tree" = ["$config_dir/../assets/cube.glb"] -"archetypes/video_simple" = ["$config_dir/../assets/empty.mp4"] +"archetypes/asset3d_simple" = ["$config_dir/../../tests/assets/cube.glb"] +"archetypes/asset3d_out_of_tree" = ["$config_dir/../../tests/assets/cube.glb"] +"archetypes/video_simple" = ["$config_dir/../../tests/assets/empty.mp4"] diff --git a/rerun_py/tests/unit/test_asset3d.py b/rerun_py/tests/unit/test_asset3d.py index e50beae90f03..b132c5a1547d 100644 --- a/rerun_py/tests/unit/test_asset3d.py +++ b/rerun_py/tests/unit/test_asset3d.py @@ -5,7 +5,7 @@ import numpy as np import rerun as rr -CUBE_FILEPATH = pathlib.Path(__file__).parent.parent.parent.parent / "docs" / "assets" / "cube.glb" +CUBE_FILEPATH = pathlib.Path(__file__).parent.parent.parent.parent / "tests" / "assets" / "cube.glb" assert CUBE_FILEPATH.is_file() diff --git a/docs/assets/cube.glb b/tests/assets/cube.glb similarity index 100% rename from docs/assets/cube.glb rename to tests/assets/cube.glb diff --git a/docs/assets/empty.mp4 b/tests/assets/empty.mp4 similarity index 100% rename from docs/assets/empty.mp4 rename to tests/assets/empty.mp4 From 05b0c38dd63afcef28d01c928ef88741e0b2c6aa Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 11 Sep 2024 14:34:09 +0200 Subject: [PATCH 2/3] add new download_test_assets.py script --- tests/assets/.gitignore | 1 + tests/assets/download_test_assets.py | 52 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/assets/.gitignore create mode 100644 tests/assets/download_test_assets.py diff --git a/tests/assets/.gitignore b/tests/assets/.gitignore new file mode 100644 index 000000000000..2b68b5238a0f --- /dev/null +++ b/tests/assets/.gitignore @@ -0,0 +1 @@ +video diff --git a/tests/assets/download_test_assets.py b/tests/assets/download_test_assets.py new file mode 100644 index 000000000000..0c341570cbe8 --- /dev/null +++ b/tests/assets/download_test_assets.py @@ -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() From 75ec2eaa468899e57a80bc6f820e31229e55857b Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 11 Sep 2024 15:01:29 +0200 Subject: [PATCH 3/3] snippet comparision script now downloads test assets --- docs/snippets/compare_snippet_output.py | 6 ++++++ docs/snippets/snippets.toml | 1 + 2 files changed, 7 insertions(+) diff --git a/docs/snippets/compare_snippet_output.py b/docs/snippets/compare_snippet_output.py index 122f829dcd86..2d3d66f7d906 100755 --- a/docs/snippets/compare_snippet_output.py +++ b/docs/snippets/compare_snippet_output.py @@ -136,6 +136,12 @@ def main() -> None: print("----------------------------------------------------------") + print("Downloading test assets…") + run(["pixi", "run", "python", "./tests/assets/download_test_assets.py"]) + print("") + + print("----------------------------------------------------------") + active_languages = ["rust"] if not args.no_cpp: active_languages.append("cpp") diff --git a/docs/snippets/snippets.toml b/docs/snippets/snippets.toml index c9c75ab6e988..535a82f4ca31 100644 --- a/docs/snippets/snippets.toml +++ b/docs/snippets/snippets.toml @@ -184,6 +184,7 @@ quick_start = [ # These examples don't have exactly the same implementation. # `$config_dir` will be replaced with the absolute path of `docs/snippets`. +# Note that the snippet comparison tool will automatically run `/tests/assets/download_test_assets.py` before running the snippets. [extra_args] "archetypes/asset3d_simple" = ["$config_dir/../../tests/assets/cube.glb"] "archetypes/asset3d_out_of_tree" = ["$config_dir/../../tests/assets/cube.glb"]