File tree 2 files changed +20
-8
lines changed
2 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,20 @@ def test_format_inference_overridable():
130
130
assert img .format == 'gif'
131
131
132
132
133
+ def test_value_repr_length ():
134
+ with get_logo_png () as LOGO_PNG :
135
+ with open (LOGO_PNG , 'rb' ) as f :
136
+ img = Image .from_file (f )
137
+ assert len (img .__repr__ ()) < 120
138
+ assert img .__repr__ ().endswith ("...')" )
139
+
140
+
141
+ def test_value_repr_url ():
142
+ img = Image .from_url (b'https://jupyter.org/assets/main-logo.svg' )
143
+
144
+ assert 'https://jupyter.org/assets/main-logo.svg' in img .__repr__ ()
145
+
146
+
133
147
# Helper functions
134
148
def get_hash_hex (byte_str ):
135
149
m = hashlib .new ('sha256' )
Original file line number Diff line number Diff line change @@ -133,18 +133,16 @@ def _guess_format(cls, filename):
133
133
def __repr__ (self ):
134
134
# Truncate the value in the repr, since it will
135
135
# typically be very, very large.
136
-
137
- def hash_string (s ):
138
- return hashlib .md5 (s .encode ("utf8" )).hexdigest ()
139
-
140
136
class_name = self .__class__ .__name__
141
137
142
138
# Return value first like a ValueWidget
143
139
signature = []
144
- sig_value = str (self .value )
145
- if len (str (self .value )) > 100 :
146
- sig_value = '<base64, hash={}...>' .format (hash_string (sig_value )[:16 ])
147
- signature .append ('%s=%r' % ('value' , sig_value ))
140
+ sig_value = repr (self .value )
141
+ prefix , rest = sig_value .split ("'" , 1 )
142
+ content = rest [:- 1 ]
143
+ if len (content ) > 100 :
144
+ sig_value = "{}'{}...'" .format (prefix , content [0 :100 ])
145
+ signature .append ('%s=%s' % ('value' , sig_value ))
148
146
149
147
for key in super (Image , self )._repr_keys ():
150
148
if key == 'value' :
You can’t perform that action at this time.
0 commit comments