Add unit tests for module-level color helpers in manim/utils/color/core.py - #4749
Merged
chopan050 merged 3 commits intoMay 29, 2026
Merged
Conversation
…re.py Adds tests/module/utils/test_color_helpers.py covering the standalone helper functions exported from manim.utils.color.core (color_to_rgb, color_to_rgba, color_to_int_rgb, color_to_int_rgba, rgb_to_color, rgba_to_color, rgb_to_hex, hex_to_rgb, invert_color, color_gradient, interpolate_color, average_color, random_bright_color, random_color) and the RandomColorGenerator class. Before this PR, only the ManimColor class itself was tested (via tests/module/utils/test_manim_color.py); the standalone helpers had zero direct test coverage. Coverage on manim/utils/color/core.py goes from 71% to 80% (line+branch), and 17 of the 18 testable symbols in the file's __all__ are now exercised. The only deferred symbol is get_shaded_rgb, which concerns lighting math rather than color conversion and is better suited to a follow-up. 42 tests, ~0.3s runtime, no new dependencies. Co-authored-by: LetMarq <LetMarq@users.noreply.github.com>
for more information, see https://pre-commit.ci
chopan050
requested changes
May 29, 2026
chopan050
left a comment
Member
There was a problem hiding this comment.
Thanks for these new tests! It's a very complete PR.
I just requested one change:
Increased assertion scheme to cover all colors. Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4740
Summary
Adds
tests/module/utils/test_color_helpers.pycovering the standalone helper functions exported frommanim.utils.color.core(color_to_rgb,color_to_rgba,color_to_int_rgb,color_to_int_rgba,rgb_to_color,rgba_to_color,rgb_to_hex,hex_to_rgb,invert_color,color_gradient,interpolate_color,average_color,random_bright_color,random_color) and theRandomColorGeneratorclass.Before this PR, only the
ManimColorclass itself was tested (viatests/module/utils/test_manim_color.py); the standalone helpers had zero direct test coverage.Coverage on
manim/utils/color/core.py+9 pp, 39 lines newly covered. Reproducible:
pytest tests/module/utils/test_manim_color.py tests/module/utils/test_color.py \ --cov=manim.utils.color.core --cov-branch --cov-report=term-missing \ -p no:xdist -o addopts="" -q # baseline pytest tests/module/utils/test_manim_color.py tests/module/utils/test_color.py \ tests/module/utils/test_color_helpers.py \ --cov=manim.utils.color.core --cov-branch --cov-report=term-missing \ -p no:xdist -o addopts="" -q # afterPublic-API coverage
Of the 18 testable symbols in
core.py's__all__, 17 are now exercised by tests (94%). The only deferred symbol isget_shaded_rgb, which concerns lighting math rather than color conversion and is a better fit for a follow-up.Test plan
pytest tests/module/utils/test_color_helpers.py -v— 42 tests, ~0.3s, all green.test_manim_color.py:numpy.testing as nt,pytest.mark.parametrizefor input-variety cases,ManimColor.__eq__for whole-color comparisons.The file is organized by function group (parsing, hex round-trips, inversion, interpolation, aggregation, random) with one parametrized test per "linearly independent concept" (e.g., one parametrize over the 7 parsable input forms for
color_to_rgb, one over the 4 corners of a hex round-trip, etc.).