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'
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')
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)