[Tests] Add unit tests for memory2 formatting helpers#3064
[Tests] Add unit tests for memory2 formatting helpers#3064xiaoyaoqilan wants to merge 2 commits into
Conversation
## Summary - `dimos/memory2/utils/formatting.py` (rich rendering helpers `render_text` / `_colorize` / `FilterRepr` mixin) has no test coverage. This adds `dimos/memory2/utils/test_formatting.py` covering: rendered text keeps its plain content, `_colorize` preserves the plain string while wrapping names in the cyan style, and the `FilterRepr` mixin renders its `__str__` via the colored repr. ## Why Pure rich-only helper (no torch/ros); a cheap coverage win that matches the repo's per-module `test_*.py` convention. ## Test plan - `uv run pytest dimos/memory2/utils/test_formatting.py` (verified locally with rich installed). ## AI disclosure AI-assisted: drafted with WorkBuddy (Claude) and reviewed by a human before submission, per the AI Usage Policy.
Greptile SummaryThis PR adds unit coverage for the
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "Merge branch 'main' into add-memory2-for..." | Re-trigger Greptile |
| def test_colorize_preserves_plain_and_colors() -> None: | ||
| t = _colorize("a | b") | ||
| # plain text is preserved, and the names are wrapped with the cyan style | ||
| assert t.plain == "a | b" | ||
| styles = [span.style for span in t.spans] | ||
| assert "cyan" in styles | ||
|
|
||
|
|
||
| def test_colorize_pipeline_with_arrow() -> None: | ||
| t = _colorize("a -> b") | ||
| assert t.plain == "a -> b" | ||
| assert "cyan" in [span.style for span in t.spans] |
There was a problem hiding this comment.
Both tests pass when any part of the result has a cyan span, including a separator or only one name. A regression that stops styling one endpoint or styles | / -> as cyan would still satisfy these assertions, so the tests do not verify the stated name-coloring behavior.
| def test_colorize_preserves_plain_and_colors() -> None: | |
| t = _colorize("a | b") | |
| # plain text is preserved, and the names are wrapped with the cyan style | |
| assert t.plain == "a | b" | |
| styles = [span.style for span in t.spans] | |
| assert "cyan" in styles | |
| def test_colorize_pipeline_with_arrow() -> None: | |
| t = _colorize("a -> b") | |
| assert t.plain == "a -> b" | |
| assert "cyan" in [span.style for span in t.spans] | |
| def test_colorize_preserves_plain_and_colors() -> None: | |
| t = _colorize("a | b") | |
| assert t.plain == "a | b" | |
| assert [(span.start, span.end, span.style) for span in t.spans] == [ | |
| (0, 1, "cyan"), | |
| (1, 4, "dim"), | |
| (4, 5, "cyan"), | |
| ] | |
| def test_colorize_pipeline_with_arrow() -> None: | |
| t = _colorize("a -> b") | |
| assert t.plain == "a -> b" | |
| assert [(span.start, span.end, span.style) for span in t.spans] == [ | |
| (0, 1, "cyan"), | |
| (1, 5, "dim"), | |
| (5, 6, "cyan"), | |
| ] |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| plain = re.sub(r"\x1b\[[0-9;]*m", "", rendered) | ||
| assert plain == "foo(a | b)" | ||
| assert isinstance(rendered, str) |
There was a problem hiding this comment.
This only verifies that removing ANSI sequences yields the original text. If FilterRepr.__repr__ regresses to returning unstyled plain text, the regex is a no-op and this test still passes, despite the test's purpose being to cover colored rendering.
| plain = re.sub(r"\x1b\[[0-9;]*m", "", rendered) | |
| assert plain == "foo(a | b)" | |
| assert isinstance(rendered, str) | |
| plain = re.sub(r"\x1b\[[0-9;]*m", "", rendered) | |
| assert plain == "foo(a | b)" | |
| assert "\x1b[" in rendered | |
| assert isinstance(rendered, str) |
Summary
dimos/memory2/utils/formatting.py(rich rendering helpersrender_text/_colorize/FilterReprmixin) has no test coverage. This addsdimos/memory2/utils/test_formatting.pycovering: rendered text keeps its plain content,_colorizepreserves the plain string while wrapping names in the cyan style, and theFilterReprmixin renders its__str__via the colored repr.Why
Pure rich-only helper (no torch/ros); a cheap coverage win that matches the repo's per-module
test_*.pyconvention.Test plan
uv run pytest dimos/memory2/utils/test_formatting.py(verified locally with rich installed).AI disclosure
AI-assisted: drafted with WorkBuddy (Claude) and reviewed by a human before submission, per the AI Usage Policy.