mjlab/tests/test_reward_bar_panel.py
Upstream Snapshot 32a241c28f
Some checks failed
nightly / Test against latest dependencies (py3.10) (push) Has been cancelled
nightly / Test against latest dependencies (py3.13) (push) Has been cancelled
tests / tests (3.13, locked) (push) Has been cancelled
tests / tests (3.13, unlocked) (push) Has been cancelled
tests / pyright (3.10) (push) Has been cancelled
tests / lint-format (push) Has been cancelled
tests / tests (3.10, locked) (push) Has been cancelled
tests / tests (3.11, locked) (push) Has been cancelled
tests / tests (3.12, locked) (push) Has been cancelled
tests / pyright (3.11) (push) Has been cancelled
tests / pyright (3.12) (push) Has been cancelled
tests / pyright (3.13) (push) Has been cancelled
tests / ty-check (3.10) (push) Has been cancelled
tests / ty-check (3.11) (push) Has been cancelled
tests / ty-check (3.12) (push) Has been cancelled
tests / ty-check (3.13) (push) Has been cancelled
tests / stubs (push) Has been cancelled
tests / smoke-test (push) Has been cancelled
Docker / check_paths (push) Has been cancelled
docs / build (push) Has been cancelled
Docker / build (push) Has been cancelled
Import upstream snapshot c19f713c415a699a79d71cd96aa13c3104a05047
Upstream: https://github.com/michaelgillett/mjlab
Upstream-Commit: c19f713c415a699a79d71cd96aa13c3104a05047
Upstream-Branch: main
2026-08-28 15:42:17 +08:00

35 lines
1.2 KiB
Python

"""Tests for the Viser reward bar panel term cap."""
from unittest.mock import Mock
import pytest
from mjlab.viewer.viser.reward_bar_panel import RewardBarPanel
def _term_names(n: int) -> list[str]:
return [f"term_{i}" for i in range(n)]
def test_warns_and_truncates_over_cap():
"""More terms than the cap warns and keeps only the first ``max_terms``."""
server = Mock()
with pytest.warns(UserWarning, match="exceed max_terms"):
panel = RewardBarPanel(server, _term_names(21), update_dt=1 / 30, max_terms=20)
assert panel._term_names == _term_names(21)[:20]
def test_no_warning_at_or_below_cap(recwarn):
"""At or below the cap, all terms are kept and no truncation warning fires."""
server = Mock()
panel = RewardBarPanel(server, _term_names(20), update_dt=1 / 30, max_terms=20)
assert panel._term_names == _term_names(20)
assert not [w for w in recwarn if "exceed max_terms" in str(w.message)]
def test_raised_cap_shows_all_terms():
"""Raising ``max_terms`` (the fix for #1079) surfaces the overflow terms."""
server = Mock()
panel = RewardBarPanel(server, _term_names(24), update_dt=1 / 30, max_terms=32)
assert panel._term_names == _term_names(24)