Skip to content

Add unit tests for module-level color helpers in manim/utils/color/core.py - #4749

Merged
chopan050 merged 3 commits into
ManimCommunity:mainfrom
THE-RAF:add-tests-for-color-helpers
May 29, 2026
Merged

Add unit tests for module-level color helpers in manim/utils/color/core.py#4749
chopan050 merged 3 commits into
ManimCommunity:mainfrom
THE-RAF:add-tests-for-color-helpers

Conversation

@THE-RAF

@THE-RAF THE-RAF commented May 28, 2026

Copy link
Copy Markdown
Contributor

Closes #4740

Summary

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

Stmts Miss Branch BrPart Cover
Before 407 107 88 16 71%
After 407 68 88 15 80%

+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   # after

Public-API coverage

Of the 18 testable symbols in core.py's __all__, 17 are now exercised by tests (94%). The only deferred symbol is get_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 -v42 tests, ~0.3s, all green.
  • No new runtime or dev dependencies.
  • Tests follow the conventions in test_manim_color.py: numpy.testing as nt, pytest.mark.parametrize for 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.).

THE-RAF and others added 2 commits May 28, 2026 18:01
…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>

@chopan050 chopan050 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these new tests! It's a very complete PR.

I just requested one change:

Comment thread tests/module/utils/test_color_helpers.py Outdated
Increased assertion scheme to cover all colors.

Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>

@chopan050 chopan050 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@chopan050
chopan050 merged commit cfb5c68 into ManimCommunity:main May 29, 2026
15 checks passed
@behackl behackl added the testing Anything related to testing the library label Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Anything related to testing the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increasing Coverage in Color Testing

3 participants