Example #1
0
def test_write_image_string_bad_extension_failure(fig1):
    # Bad extension
    file_path = os.path.join(tmp_dir, "fig1.bogus")

    # Use file extension to infer image type.
    with pytest.raises(ValueError) as err:
        pio.write_image(fig1, file_path)

    assert "must be specified as one of the following" in str(err.value)
Example #2
0
def test_write_image_string_no_extension_failure(fig1):
    # No extension
    file_path = os.path.join(tmp_dir, "fig1")

    # Use file extension to infer image type.
    with pytest.raises(ValueError) as err:
        pio.write_image(fig1, file_path)

    assert "add a file extension or specify the type" in str(err.value)
Example #3
0
def test_write_image_writeable(fig1, format):

    file_name = "fig1." + format
    with open(os.path.join(images_dir, file_name), "rb") as f:
        expected_bytes = f.read()

    mock_file = MagicMock()
    pio.write_image(fig1, mock_file, format=format, width=700, height=500)

    mock_file.write.assert_called_once_with(expected_bytes)
 def render(self, fig_dict):
     stack = inspect.stack()
     # Name of script from which plot function was called is retrieved
     try:
         filename = stack[3].filename  # let's hope this is robust...
     except:  # python 2
         filename = stack[3][1]
     filename_root, _ = os.path.splitext(filename)
     filename_html = filename_root + ".html"
     filename_png = filename_root + ".png"
     figure = return_figure_from_figure_or_data(fig_dict, True)
     _ = write_html(fig_dict, file=filename_html)
     write_image(figure, filename_png)
Example #5
0
def test_write_image_string_bad_extension_override(fig1):
    # Bad extension
    file_name = "fig1.bogus"
    tmp_path = os.path.join(tmp_dir, file_name)

    pio.write_image(fig1, tmp_path, format="eps", width=700, height=500)

    with open(tmp_path, "rb") as f:
        written_bytes = f.read()

    with open(os.path.join(images_dir, "fig1.eps"), "rb") as f:
        expected_bytes = f.read()

    assert written_bytes == expected_bytes
Example #6
0
def test_write_image_string_format_inference(fig1, format):
    # Build file paths
    file_name = "fig1." + format
    file_path = os.path.join(tmp_dir, file_name)

    # Use file extension to infer image type.
    pio.write_image(fig1,
                    os.path.join(tmp_dir, file_name),
                    width=700,
                    height=500)

    with open(file_path, "rb") as f:
        written_bytes = f.read()

    with open(os.path.join(images_dir, file_name), "rb") as f:
        expected_bytes = f.read()

    assert written_bytes == expected_bytes
Example #7
0
def test_write_image_string(fig1, format):

    # Build file paths
    file_name = "fig1." + format
    file_path = tmp_dir + file_name

    pio.write_image(fig1,
                    os.path.join(tmp_dir, file_name),
                    format=format,
                    width=700,
                    height=500)

    with open(file_path, "rb") as f:
        written_bytes = f.read()

    with open(os.path.join(images_dir, file_name), "rb") as f:
        expected_bytes = f.read()

    assert written_bytes == expected_bytes