|
12 | 12 | import nose.tools as nt |
13 | 13 |
|
14 | 14 | from IPython.lib import pretty |
15 | | -from IPython.testing.decorators import (skip_without, py2_only, py3_only) |
16 | | - |
17 | | -from IPython.utils.py3compat import PY3, unicode_to_str |
| 15 | +from IPython.testing.decorators import skip_without |
18 | 16 |
|
19 | | -if PY3: |
20 | | - from io import StringIO |
21 | | -else: |
22 | | - from StringIO import StringIO |
| 17 | +from io import StringIO |
23 | 18 |
|
24 | 19 |
|
25 | 20 | class MyList(object): |
@@ -245,7 +240,7 @@ def test_metaclass_repr(): |
245 | 240 |
|
246 | 241 | def test_unicode_repr(): |
247 | 242 | u = u"üniçodé" |
248 | | - ustr = unicode_to_str(u) |
| 243 | + ustr = u |
249 | 244 |
|
250 | 245 | class C(object): |
251 | 246 | def __repr__(self): |
@@ -276,83 +271,6 @@ def type_pprint_wrapper(obj, p, cycle): |
276 | 271 | nt.assert_true(type_pprint_wrapper.called) |
277 | 272 |
|
278 | 273 |
|
279 | | -# This is only run on Python 2 because in Python 3 the language prevents you |
280 | | -# from setting a non-unicode value for __qualname__ on a metaclass, and it |
281 | | -# doesn't respect the descriptor protocol if you subclass unicode and implement |
282 | | -# __get__. |
283 | | -@py2_only |
284 | | -def test_fallback_to__name__on_type(): |
285 | | - # Test that we correctly repr types that have non-string values for |
286 | | - # __qualname__ by falling back to __name__ |
287 | | - |
288 | | - class Type(object): |
289 | | - __qualname__ = 5 |
290 | | - |
291 | | - # Test repring of the type. |
292 | | - stream = StringIO() |
293 | | - printer = pretty.RepresentationPrinter(stream) |
294 | | - |
295 | | - printer.pretty(Type) |
296 | | - printer.flush() |
297 | | - output = stream.getvalue() |
298 | | - |
299 | | - # If __qualname__ is malformed, we should fall back to __name__. |
300 | | - expected = '.'.join([__name__, Type.__name__]) |
301 | | - nt.assert_equal(output, expected) |
302 | | - |
303 | | - # Clear stream buffer. |
304 | | - stream.buf = '' |
305 | | - |
306 | | - # Test repring of an instance of the type. |
307 | | - instance = Type() |
308 | | - printer.pretty(instance) |
309 | | - printer.flush() |
310 | | - output = stream.getvalue() |
311 | | - |
312 | | - # Should look like: |
313 | | - # <IPython.lib.tests.test_pretty.Type at 0x7f7658ae07d0> |
314 | | - prefix = '<' + '.'.join([__name__, Type.__name__]) + ' at 0x' |
315 | | - nt.assert_true(output.startswith(prefix)) |
316 | | - |
317 | | - |
318 | | -@py2_only |
319 | | -def test_fail_gracefully_on_bogus__qualname__and__name__(): |
320 | | - # Test that we correctly repr types that have non-string values for both |
321 | | - # __qualname__ and __name__ |
322 | | - |
323 | | - class Meta(type): |
324 | | - __name__ = 5 |
325 | | - |
326 | | - class Type(object): |
327 | | - __metaclass__ = Meta |
328 | | - __qualname__ = 5 |
329 | | - |
330 | | - stream = StringIO() |
331 | | - printer = pretty.RepresentationPrinter(stream) |
332 | | - |
333 | | - printer.pretty(Type) |
334 | | - printer.flush() |
335 | | - output = stream.getvalue() |
336 | | - |
337 | | - # If we can't find __name__ or __qualname__ just use a sentinel string. |
338 | | - expected = '.'.join([__name__, '<unknown type>']) |
339 | | - nt.assert_equal(output, expected) |
340 | | - |
341 | | - # Clear stream buffer. |
342 | | - stream.buf = '' |
343 | | - |
344 | | - # Test repring of an instance of the type. |
345 | | - instance = Type() |
346 | | - printer.pretty(instance) |
347 | | - printer.flush() |
348 | | - output = stream.getvalue() |
349 | | - |
350 | | - # Should look like: |
351 | | - # <IPython.lib.tests.test_pretty.<unknown type> at 0x7f7658ae07d0> |
352 | | - prefix = '<' + '.'.join([__name__, '<unknown type>']) + ' at 0x' |
353 | | - nt.assert_true(output.startswith(prefix)) |
354 | | - |
355 | | - |
356 | 274 | def test_collections_defaultdict(): |
357 | 275 | # Create defaultdicts with cycles |
358 | 276 | a = defaultdict() |
@@ -441,7 +359,6 @@ class MyCounter(Counter): |
441 | 359 | for obj, expected in cases: |
442 | 360 | nt.assert_equal(pretty.pretty(obj), expected) |
443 | 361 |
|
444 | | -@py3_only |
445 | 362 | def test_mappingproxy(): |
446 | 363 | MP = types.MappingProxyType |
447 | 364 | underlying_dict = {} |
|
0 commit comments