Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b35b82

Browse files
committed
Fix Image when passing only data, and add tests.
Closes ipython#9181
1 parent f34c720 commit 1b35b82

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

IPython/core/display.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import struct
1313
import warnings
1414

15-
from IPython.core.formatters import _safe_get_formatter_method
1615
from IPython.utils.py3compat import (string_types, cast_bytes_py2, cast_unicode,
1716
unicode_type)
1817
from IPython.testing.skipdoctest import skip_doctest
@@ -731,14 +730,14 @@ def __init__(self, data=None, url=None, filename=None, format=None,
731730
if data[:2] == _JPEG:
732731
format = self._FMT_JPEG
733732

734-
if format.lower() == 'jpg':
735-
# jpg->jpeg
736-
format = self._FMT_JPEG
737-
738733
# failed to detect format, default png
739734
if format is None:
740735
format = 'png'
741736

737+
if format.lower() == 'jpg':
738+
# jpg->jpeg
739+
format = self._FMT_JPEG
740+
742741
self.format = unicode_type(format).lower()
743742
self.embed = embed if embed is not None else (url is None)
744743

IPython/core/tests/test_display.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def test_retina_jpeg():
4343
nt.assert_equal(md['width'], 1)
4444
nt.assert_equal(md['height'], 1)
4545

46+
def test_base64image():
47+
display.Image("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BCRQnOqNu0b4AAAAKSURBVAjXY2AAAAACAAHiIbwzAAAAAElFTkSuQmCC")
48+
4649
def test_image_filename_defaults():
4750
'''test format constraint, and validity of jpeg and png'''
4851
tpath = ipath.get_ipython_package_dir()

0 commit comments

Comments
 (0)