def test_ipython_display_formatter():
 f = get_ipython().display_formatter
 catcher = []
 class SelfDisplaying(object, ):
  def _ipython_display_(self):
   catcher.append(self)
 class NotSelfDisplaying(object, ):
  def __repr__(self):
   return 'NotSelfDisplaying'
  def _ipython_display_(self):
   raise NotImplementedError
 yes = SelfDisplaying()
 no = NotSelfDisplaying()
 (d, md) = f.format(no)
 nt.assert_equal(d, {'text/plain': repr(no)})
 nt.assert_equal(md, {})
 nt.assert_equal(catcher, [])
 (d, md) = f.format(yes)
 nt.assert_equal(d, {})
 nt.assert_equal(md, {})
 nt.assert_equal(catcher, [yes])

def test_ipython_display_formatter ( ) : f = get_ipython ( ) . display_formatter catcher = [ ] class SelfDisplaying ( object , ) : def _ipython_display_ ( self ) : catcher . append ( self ) class NotSelfDisplaying ( object , ) : def __repr__ ( self ) : return 'NotSelfDisplaying' def _ipython_display_ ( self ) : raise NotImplementedError yes = SelfDisplaying ( ) no = NotSelfDisplaying ( ) ( d , md ) = f . format ( no ) nt . assert_equal ( d , { 'text/plain' : repr ( no ) } ) nt . assert_equal ( md , { } ) nt . assert_equal ( catcher , [ ] ) ( d , md ) = f . format ( yes ) nt . assert_equal ( d , { } ) nt . assert_equal ( md , { } ) nt . assert_equal ( catcher , [ yes ] )
objects with _ipython_display_ defined bypass other formatters .