Skip to content

Commit e774d3f

Browse files
committed
Adds tests
A simple test that checks the consistency of sampling a colorscale on the actual definition points, as well as sampling a very simple scale at simple points.
1 parent 1b419ad commit e774d3f

File tree

1 file changed

+19
-0
lines changed
  • packages/python/plotly/plotly/tests/test_core/test_colors

1 file changed

+19
-0
lines changed

packages/python/plotly/plotly/tests/test_core/test_colors/test_colors.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,22 @@ def test_make_colorscale(self):
137137
self.assertRaisesRegexp(
138138
PlotlyError, pattern2, colors.make_colorscale, color_list2, scale
139139
)
140+
141+
def test_sample_colorscale(self):
142+
143+
# test that sampling a colorscale at the defined points returns the same
144+
defined_colors = colors.sequential.Inferno
145+
sampled_colors = colors.sample_colorscale(defined_colors, len(defined_colors), colortype="rgb")
146+
defined_colors_rgb = colors.convert_colors_to_same_type(defined_colors, colortype='rgb')[0]
147+
self.assertEqual(sampled_colors, defined_colors_rgb)
148+
149+
# test sampling an easy colorscale that goes [red, green, blue]
150+
defined_colors = ['rgb(255,0,0)', 'rgb(0,255,0)', 'rgb(0,0,255)']
151+
samplepoints = [0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0]
152+
expected_output = [
153+
(1.0, 0.0, 0.0), (0.75, 0.25, 0.0), (0.5, 0.5, 0.0),
154+
(0.25, 0.75, 0.0), (0.0, 1.0, 0.0), (0.0, 0.75, 0.25),
155+
(0.0, 0.5, 0.5), (0.0, 0.25, 0.75), (0.0, 0.0, 1.0)
156+
]
157+
output = colors.sample_colorscale(defined_colors, samplepoints, colortype="tuple")
158+
self.assertEqual(expected_output, output)

0 commit comments

Comments
 (0)