Ejemplo n.º 1
0
def test_color_range_to_from_dict():
    """Test the to/from dict methods."""
    color_range = ColorRange(
        [Color(0, 100, 0), Color(100, 200, 100)], [0, 1000])
    color_range_dict = color_range.to_dict()
    new_color = ColorRange.from_dict(color_range_dict)
    assert new_color.to_dict() == color_range_dict
Ejemplo n.º 2
0
def test_legend_value_colors():
    """Test the color_range, value_colors, and segment_colors property."""
    legend = Legend(range(5), LegendParameters(segment_count=10))

    for i, color in enumerate(legend.color_range):
        assert color == ColorRange()[i]
    assert legend.color_range.domain == ColorRange(domain=(0, 4)).domain

    assert len(legend.values) == 5
    assert len(legend.value_colors) == 5
    assert legend.value_colors[0] == Colorset.original()[0]
    assert legend.segment_colors == Colorset.original()
Ejemplo n.º 3
0
def test_init_color_range():
    """Test the initialization of color range objects."""
    color_range = ColorRange(
        [Color(75, 107, 169),
         Color(245, 239, 103),
         Color(234, 38, 0)])
    str(color_range)  # Test the color representation

    assert len(color_range) == 3
    assert isinstance(color_range.colors, tuple)
    assert isinstance(color_range.domain, tuple)
    assert color_range[0] == Color(75, 107, 169)
Ejemplo n.º 4
0
def test_color_range_discontinuous():
    """Test color range objects with discontinuous colors."""
    color_range = ColorRange(continuous_colors=False)
    color_range.domain = [100, 2000]
    color_range.colors = [
        Color(75, 107, 169),
        Color(245, 239, 103),
        Color(234, 38, 0)
    ]

    assert color_range.color(99) == Color(75, 107, 169)
    assert color_range.color(100) == Color(245, 239, 103)
    assert color_range.color(2000) == Color(245, 239, 103)
    assert color_range.color(2001) == Color(234, 38, 0)
Ejemplo n.º 5
0
def test_color_range_continuous():
    """Test color range objects with continuous colors."""
    color_range = ColorRange(
        [Color(0, 100, 0), Color(100, 200, 100)], [0, 1000])

    assert color_range.color(-100) == Color(0, 100, 0)
    assert color_range.color(0) == Color(0, 100, 0)
    assert color_range.color(500) == Color(50, 150, 50)
    assert color_range.color(250) == Color(25, 125, 25)
    assert color_range.color(1000) == Color(100, 200, 100)
    assert color_range.color(1100) == Color(100, 200, 100)
Ejemplo n.º 6
0
def test_color_range_from_dict():
    """Test the from_dict method."""
    sample_dict = {
        'colors': [{
            'r': '0',
            'g': '0',
            'b': '0'
        }, {
            'r': '0',
            'g': '255',
            'b': '100'
        }]
    }
    color_range = ColorRange.from_dict(sample_dict)
    assert isinstance(color_range, ColorRange)
    assert color_range[0] == Color(0, 0, 0)
    assert color_range[1] == Color(0, 255, 100)