forked from isaac-sim/IsaacLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_renderer_cache_inventory.py
More file actions
46 lines (34 loc) · 1.66 KB
/
Copy pathtest_renderer_cache_inventory.py
File metadata and controls
46 lines (34 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
"""Tests for renderer cache inventory and change detection."""
import importlib.util
from pathlib import Path
def _load_inventory_module():
module_path = Path(__file__).with_name("renderer_cache_inventory.py")
spec = importlib.util.spec_from_file_location("renderer_cache_inventory", module_path)
assert spec is not None
assert spec.loader is not None
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def test_inventory_groups_cache_files_by_top_level_directory(tmp_path: Path) -> None:
"""Inventory should report every cache file without reading its contents."""
inventory_module = _load_inventory_module()
(tmp_path / "home").mkdir()
(tmp_path / "isaac-sim").mkdir()
(tmp_path / "home" / "shader.bin").write_bytes(b"123")
(tmp_path / "isaac-sim" / "kit.bin").write_bytes(b"12345")
total_bytes, file_count, groups = inventory_module.inventory(tmp_path)
assert total_bytes == 8
assert file_count == 2
assert groups == {"home": 3, "isaac-sim": 5}
def test_fingerprint_changes_when_cache_file_changes(tmp_path: Path) -> None:
"""A writer must publish a new snapshot when a cache artifact changes."""
inventory_module = _load_inventory_module()
artifact = tmp_path / "shader.bin"
artifact.write_bytes(b"before")
before = inventory_module.fingerprint(tmp_path)
artifact.write_bytes(b"after-content")
assert inventory_module.fingerprint(tmp_path) != before