Show More
@@ -11,6 +11,12 b' import nose.tools as nt' | |||||
11 | # Our own imports |
|
11 | # Our own imports | |
12 | from IPython.lib import pretty |
|
12 | from IPython.lib import pretty | |
13 | from IPython.testing.decorators import skip_without |
|
13 | from IPython.testing.decorators import skip_without | |
|
14 | from IPython.utils.py3compat import PY3 | |||
|
15 | ||||
|
16 | if PY3: | |||
|
17 | from io import StringIO | |||
|
18 | else: | |||
|
19 | from StringIO import StringIO | |||
14 |
|
20 | |||
15 |
|
21 | |||
16 | class MyList(object): |
|
22 | class MyList(object): | |
@@ -230,3 +236,21 b" ClassWithMeta = MetaClass('ClassWithMeta')" | |||||
230 | def test_metaclass_repr(): |
|
236 | def test_metaclass_repr(): | |
231 | output = pretty.pretty(ClassWithMeta) |
|
237 | output = pretty.pretty(ClassWithMeta) | |
232 | nt.assert_equal(output, "[CUSTOM REPR FOR CLASS ClassWithMeta]") |
|
238 | nt.assert_equal(output, "[CUSTOM REPR FOR CLASS ClassWithMeta]") | |
|
239 | ||||
|
240 | ||||
|
241 | def test_basic_class(): | |||
|
242 | def type_pprint_wrapper(obj, p, cycle): | |||
|
243 | if obj is MyObj: | |||
|
244 | type_pprint_wrapper.called = True | |||
|
245 | return pretty._type_pprint(obj, p, cycle) | |||
|
246 | type_pprint_wrapper.called = False | |||
|
247 | ||||
|
248 | stream = StringIO() | |||
|
249 | printer = pretty.RepresentationPrinter(stream) | |||
|
250 | printer.type_pprinters[type] = type_pprint_wrapper | |||
|
251 | printer.pretty(MyObj) | |||
|
252 | printer.flush() | |||
|
253 | output = stream.getvalue() | |||
|
254 | ||||
|
255 | nt.assert_equal(output, '%s.MyObj' % __name__) | |||
|
256 | nt.assert_true(type_pprint_wrapper.called) |
General Comments 0
You need to be logged in to leave comments.
Login now