From 196a1ae3a9bd95f14a5f72fa735681e89d7716c3 Mon Sep 17 00:00:00 2001 From: eeshsaxena Date: Wed, 8 Jul 2026 20:36:12 +0530 Subject: [PATCH 1/2] test: add unit tests for rgb/hex color conversion helpers --- .../test_colors/test_color_conversions.py | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/test_core/test_colors/test_color_conversions.py diff --git a/tests/test_core/test_colors/test_color_conversions.py b/tests/test_core/test_colors/test_color_conversions.py new file mode 100644 index 00000000000..5cf08db101a --- /dev/null +++ b/tests/test_core/test_colors/test_color_conversions.py @@ -0,0 +1,49 @@ +import pytest + +from _plotly_utils.colors import ( + find_intermediate_color, + hex_to_rgb, + label_rgb, + unlabel_rgb, +) + + +def test_hex_to_rgb_basic_values(): + assert hex_to_rgb("#ffffff") == (255, 255, 255) + assert hex_to_rgb("#000000") == (0, 0, 0) + assert hex_to_rgb("#aabbcc") == (170, 187, 204) + + +def test_label_rgb_formats_tuple(): + assert label_rgb((255, 0, 0)) == "rgb(255, 0, 0)" + assert label_rgb((1, 2, 3)) == "rgb(1, 2, 3)" + + +def test_unlabel_rgb_parses_string(): + assert unlabel_rgb("rgb(255, 0, 0)") == (255.0, 0.0, 0.0) + assert unlabel_rgb("rgb(1, 2, 3)") == (1.0, 2.0, 3.0) + + +def test_label_and_unlabel_are_inverses(): + assert unlabel_rgb(label_rgb((10, 20, 30))) == (10.0, 20.0, 30.0) + + +def test_find_intermediate_color_tuple_midpoint(): + assert find_intermediate_color((0, 0, 0), (1, 1, 1), 0.5) == (0.5, 0.5, 0.5) + + +def test_find_intermediate_color_endpoints(): + low, high = (0.0, 0.0, 0.0), (1.0, 1.0, 1.0) + assert find_intermediate_color(low, high, 0.0) == low + assert find_intermediate_color(low, high, 1.0) == high + + +def test_find_intermediate_color_rgb_colortype(): + result = find_intermediate_color( + "rgb(0, 0, 0)", "rgb(10, 20, 30)", 0.5, colortype="rgb" + ) + assert result == "rgb(5.0, 10.0, 15.0)" + + +if __name__ == "__main__": + raise SystemExit(pytest.main([__file__, "-v"])) From d8ea605118baf34255978dd97dab9456af696b70 Mon Sep 17 00:00:00 2001 From: eeshsaxena Date: Fri, 17 Jul 2026 00:10:40 +0530 Subject: [PATCH 2/2] test: move color conversion tests to tests/test_plotly_utils/ Address review: _plotly_utils tests live under tests/test_plotly_utils/, so move the file to tests/test_plotly_utils/colors/ and add the package __init__.py to match the sibling validators/ directory. Also drop the unused pytest import and the __main__ runner block. --- tests/test_plotly_utils/colors/__init__.py | 0 .../colors}/test_color_conversions.py | 6 ------ 2 files changed, 6 deletions(-) create mode 100644 tests/test_plotly_utils/colors/__init__.py rename tests/{test_core/test_colors => test_plotly_utils/colors}/test_color_conversions.py (92%) diff --git a/tests/test_plotly_utils/colors/__init__.py b/tests/test_plotly_utils/colors/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/test_core/test_colors/test_color_conversions.py b/tests/test_plotly_utils/colors/test_color_conversions.py similarity index 92% rename from tests/test_core/test_colors/test_color_conversions.py rename to tests/test_plotly_utils/colors/test_color_conversions.py index 5cf08db101a..282a81ce562 100644 --- a/tests/test_core/test_colors/test_color_conversions.py +++ b/tests/test_plotly_utils/colors/test_color_conversions.py @@ -1,5 +1,3 @@ -import pytest - from _plotly_utils.colors import ( find_intermediate_color, hex_to_rgb, @@ -43,7 +41,3 @@ def test_find_intermediate_color_rgb_colortype(): "rgb(0, 0, 0)", "rgb(10, 20, 30)", 0.5, colortype="rgb" ) assert result == "rgb(5.0, 10.0, 15.0)" - - -if __name__ == "__main__": - raise SystemExit(pytest.main([__file__, "-v"]))