Exemplo n.º 1
0
def test_save_cmap():
    """This test covers _save_cmap as well as _bytesIO_to_base64
    """

    # Save the cmap using BytesIO
    cmap_io = BytesIO()
    html_stat_map._save_cm(cmap_io, 'cold_hot', format='raw', n_colors=2)

    # Load the colormap back in base64
    cmap_base64 = html_stat_map._bytesIO_to_base64(cmap_io)

    # Check the colormap is correct
    assert cmap_base64 == '//////////8=\n'
Exemplo n.º 2
0
def test_save_cmap():
    """This test covers _save_cmap as well as _bytesIO_to_base64
    """

    # Save the cmap using BytesIO
    cmap_io = BytesIO()
    html_stat_map._save_cm(cmap_io, 'cold_hot', format='raw', n_colors=2)

    # Load the colormap back in base64
    cmap_base64 = html_stat_map._bytesIO_to_base64(cmap_io)

    # Check the colormap is correct
    assert cmap_base64 == '//////////8=\n'
Exemplo n.º 3
0
def test_save_cmap():
    """This test covers _save_cmap as well as _bytesIO_to_base64
    """

    # Save the cmap using BytesIO
    cmap_io = BytesIO()
    html_stat_map._save_cm(cmap_io, 'cold_hot', format='png', n_colors=2)

    # Load the colormap back in base64
    cmap_base64 = html_stat_map._bytesIO_to_base64(cmap_io)

    # Check the colormap is correct
    assert cmap_base64.startswith('iVBORw0KG')
    assert cmap_base64.endswith('ElFTkSuQmCC')
Exemplo n.º 4
0
def test_save_cmap(cmap, n_colors):
    """This test covers _save_cmap as well as _bytesIO_to_base64
    """
    # Save the cmap using BytesIO
    cmap_io = BytesIO()
    html_stat_map._save_cm(cmap_io, cmap, format='png', n_colors=n_colors)

    # Load the colormap back in base64
    cmap_base64 = html_stat_map._bytesIO_to_base64(cmap_io)

    decoded_io = BytesIO()
    decoded_io.write(base64.b64decode(cmap_base64))
    decoded_io.seek(0)
    img = plt.imread(decoded_io, format="png")
    expected = plt.get_cmap(cmap)(np.linspace(0, 1, n_colors))
    assert np.allclose(img, expected, atol=.1)