Download simulation/modules/IsaacLab/source/isaaclab/test/utils/test_version.py from hk239/v2d: direct link, hf CLI and curl.
- Browser
- Download file 4.52 kB
-
https://huggingface.co/datasets/hk239/v2d/resolve/main/simulation/modules/IsaacLab/source/isaaclab/test/utils/test_version.py
- Command line
-
hf download hf://datasets/hk239/v2d/simulation/modules/IsaacLab/source/isaaclab/test/utils/test_version.py
-
curl -L -o test_version.py https://huggingface.co/datasets/hk239/v2d/resolve/main/simulation/modules/IsaacLab/source/isaaclab/test/utils/test_version.py
4.52 kB
| # 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 version comparison utilities.""" | |
| """Launch Isaac Sim Simulator first.""" | |
| from isaaclab.app import AppLauncher | |
| # launch omniverse app | |
| simulation_app = AppLauncher(headless=True).app | |
| """Rest everything follows.""" | |
| import pytest | |
| from packaging.version import Version | |
| from isaaclab.utils.version import compare_versions, get_isaac_sim_version | |
| def test_get_isaac_sim_version(): | |
| """Test that get_isaac_sim_version returns cached Version object.""" | |
| # Call twice to ensure caching works | |
| version1 = get_isaac_sim_version() | |
| version2 = get_isaac_sim_version() | |
| # Should return the same object (cached) | |
| assert version1 is version2 | |
| # Should return a packaging.version.Version object | |
| assert isinstance(version1, Version) | |
| # Major version should be reasonable | |
| assert version1.major >= 4 | |
| # Minor and micro should be non-negative | |
| assert version1.minor >= 0 | |
| assert version1.micro >= 0 | |
| def test_get_isaac_sim_version_format(): | |
| """Test that get_isaac_sim_version returns correct format.""" | |
| isaac_version = get_isaac_sim_version() | |
| # Should be able to convert to string | |
| version_str = str(isaac_version) | |
| assert isinstance(version_str, str) | |
| # Should have proper format (e.g., "5.0.0") | |
| parts = version_str.split(".") | |
| assert len(parts) >= 3 | |
| # Can access components | |
| assert hasattr(isaac_version, "major") | |
| assert hasattr(isaac_version, "minor") | |
| assert hasattr(isaac_version, "micro") | |
| def test_version_caching_performance(): | |
| """Test that caching improves performance for version checks.""" | |
| # First call (will cache) | |
| version1 = get_isaac_sim_version() | |
| # Subsequent calls should be instant (from cache) | |
| for _ in range(100): | |
| version = get_isaac_sim_version() | |
| assert version == version1 | |
| assert version is version1 # Should be the exact same object | |
| def test_version_comparison_operators(): | |
| """Test that Version objects support natural comparisons.""" | |
| isaac_version = get_isaac_sim_version() | |
| # Should support comparison operators | |
| assert isaac_version >= Version("4.0.0") | |
| assert isaac_version == isaac_version | |
| # Test less than | |
| if isaac_version.major >= 5: | |
| assert isaac_version > Version("4.5.0") | |
| assert isaac_version >= Version("5.0.0") | |
| # Test not equal | |
| assert isaac_version != Version("0.0.1") | |
| def test_version_comparisons(v1, v2, expected): | |
| """Test version comparisons with various scenarios.""" | |
| assert compare_versions(v1, v2) == expected | |
| def test_symmetry(): | |
| """Test anti-symmetric property: if v1 < v2, then v2 > v1.""" | |
| test_pairs = [("1.0.0", "2.0.0"), ("1.5.3", "1.4.9"), ("1.0.0", "1.0.0")] | |
| for v1, v2 in test_pairs: | |
| result1 = compare_versions(v1, v2) | |
| result2 = compare_versions(v2, v1) | |
| if result1 == 0: | |
| assert result2 == 0 | |
| else: | |
| assert result1 == -result2 | |
| def test_transitivity(): | |
| """Test transitive property: if v1 < v2 < v3, then v1 < v3.""" | |
| v1, v2, v3 = "1.0.0", "2.0.0", "3.0.0" | |
| assert compare_versions(v1, v2) == -1 | |
| assert compare_versions(v2, v3) == -1 | |
| assert compare_versions(v1, v3) == -1 | |