Show More
@@ -81,7 +81,7 b' def test_indentation():' | |||||
81 | gotoutput = pretty.pretty(MyList(range(count))) |
|
81 | gotoutput = pretty.pretty(MyList(range(count))) | |
82 | expectedoutput = "MyList(\n" + ",\n".join(" %d" % i for i in range(count)) + ")" |
|
82 | expectedoutput = "MyList(\n" + ",\n".join(" %d" % i for i in range(count)) + ")" | |
83 |
|
83 | |||
84 |
|
|
84 | assert gotoutput == expectedoutput | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | def test_dispatch(): |
|
87 | def test_dispatch(): | |
@@ -92,7 +92,7 b' def test_dispatch():' | |||||
92 | gotoutput = pretty.pretty(MyDict()) |
|
92 | gotoutput = pretty.pretty(MyDict()) | |
93 | expectedoutput = "MyDict(...)" |
|
93 | expectedoutput = "MyDict(...)" | |
94 |
|
94 | |||
95 |
|
|
95 | assert gotoutput == expectedoutput | |
96 |
|
96 | |||
97 |
|
97 | |||
98 | def test_callability_checking(): |
|
98 | def test_callability_checking(): | |
@@ -103,7 +103,7 b' def test_callability_checking():' | |||||
103 | gotoutput = pretty.pretty(Dummy2()) |
|
103 | gotoutput = pretty.pretty(Dummy2()) | |
104 | expectedoutput = "Dummy1(...)" |
|
104 | expectedoutput = "Dummy1(...)" | |
105 |
|
105 | |||
106 |
|
|
106 | assert gotoutput == expectedoutput | |
107 |
|
107 | |||
108 |
|
108 | |||
109 | @pytest.mark.parametrize( |
|
109 | @pytest.mark.parametrize( | |
@@ -135,7 +135,7 b' def test_sets(obj, expected_output):' | |||||
135 | Test that set and frozenset use Python 3 formatting. |
|
135 | Test that set and frozenset use Python 3 formatting. | |
136 | """ |
|
136 | """ | |
137 | got_output = pretty.pretty(obj) |
|
137 | got_output = pretty.pretty(obj) | |
138 |
|
|
138 | assert got_output == expected_output | |
139 |
|
139 | |||
140 |
|
140 | |||
141 | @skip_without('xxlimited') |
|
141 | @skip_without('xxlimited') | |
@@ -145,14 +145,16 b' def test_pprint_heap_allocated_type():' | |||||
145 | """ |
|
145 | """ | |
146 | import xxlimited |
|
146 | import xxlimited | |
147 | output = pretty.pretty(xxlimited.Null) |
|
147 | output = pretty.pretty(xxlimited.Null) | |
148 |
|
|
148 | assert output == "xxlimited.Null" | |
|
149 | ||||
149 |
|
150 | |||
150 | def test_pprint_nomod(): |
|
151 | def test_pprint_nomod(): | |
151 | """ |
|
152 | """ | |
152 | Test that pprint works for classes with no __module__. |
|
153 | Test that pprint works for classes with no __module__. | |
153 | """ |
|
154 | """ | |
154 | output = pretty.pretty(NoModule) |
|
155 | output = pretty.pretty(NoModule) | |
155 |
|
|
156 | assert output == "NoModule" | |
|
157 | ||||
156 |
|
158 | |||
157 | def test_pprint_break(): |
|
159 | def test_pprint_break(): | |
158 | """ |
|
160 | """ | |
@@ -160,7 +162,7 b' def test_pprint_break():' | |||||
160 | """ |
|
162 | """ | |
161 | output = pretty.pretty(Breaking()) |
|
163 | output = pretty.pretty(Breaking()) | |
162 | expected = "TG: Breaking(\n ):" |
|
164 | expected = "TG: Breaking(\n ):" | |
163 |
|
|
165 | assert output == expected | |
164 |
|
166 | |||
165 | def test_pprint_break_repr(): |
|
167 | def test_pprint_break_repr(): | |
166 | """ |
|
168 | """ | |
@@ -168,11 +170,11 b' def test_pprint_break_repr():' | |||||
168 | """ |
|
170 | """ | |
169 | output = pretty.pretty([[BreakingRepr()]]) |
|
171 | output = pretty.pretty([[BreakingRepr()]]) | |
170 | expected = "[[Breaking(\n )]]" |
|
172 | expected = "[[Breaking(\n )]]" | |
171 |
|
|
173 | assert output == expected | |
172 |
|
174 | |||
173 | output = pretty.pretty([[BreakingRepr()]*2]) |
|
175 | output = pretty.pretty([[BreakingRepr()]*2]) | |
174 | expected = "[[Breaking(\n ),\n Breaking(\n )]]" |
|
176 | expected = "[[Breaking(\n ),\n Breaking(\n )]]" | |
175 |
|
|
177 | assert output == expected | |
176 |
|
178 | |||
177 | def test_bad_repr(): |
|
179 | def test_bad_repr(): | |
178 | """Don't catch bad repr errors""" |
|
180 | """Don't catch bad repr errors""" | |
@@ -258,7 +260,7 b" ClassWithMeta = MetaClass('ClassWithMeta')" | |||||
258 |
|
260 | |||
259 | def test_metaclass_repr(): |
|
261 | def test_metaclass_repr(): | |
260 | output = pretty.pretty(ClassWithMeta) |
|
262 | output = pretty.pretty(ClassWithMeta) | |
261 |
|
|
263 | assert output == "[CUSTOM REPR FOR CLASS ClassWithMeta]" | |
262 |
|
264 | |||
263 |
|
265 | |||
264 | def test_unicode_repr(): |
|
266 | def test_unicode_repr(): | |
@@ -271,9 +273,9 b' def test_unicode_repr():' | |||||
271 |
|
273 | |||
272 | c = C() |
|
274 | c = C() | |
273 | p = pretty.pretty(c) |
|
275 | p = pretty.pretty(c) | |
274 |
|
|
276 | assert p == u | |
275 | p = pretty.pretty([c]) |
|
277 | p = pretty.pretty([c]) | |
276 |
|
|
278 | assert p == u"[%s]" % u | |
277 |
|
279 | |||
278 |
|
280 | |||
279 | def test_basic_class(): |
|
281 | def test_basic_class(): | |
@@ -290,10 +292,11 b' def test_basic_class():' | |||||
290 | printer.flush() |
|
292 | printer.flush() | |
291 | output = stream.getvalue() |
|
293 | output = stream.getvalue() | |
292 |
|
294 | |||
293 |
|
|
295 | assert output == "%s.MyObj" % __name__ | |
294 | nt.assert_true(type_pprint_wrapper.called) |
|
296 | nt.assert_true(type_pprint_wrapper.called) | |
295 |
|
297 | |||
296 |
|
298 | |||
|
299 | # TODO : pytest.mark.parametrise once nose is gone. | |||
297 | def test_collections_defaultdict(): |
|
300 | def test_collections_defaultdict(): | |
298 | # Create defaultdicts with cycles |
|
301 | # Create defaultdicts with cycles | |
299 | a = defaultdict() |
|
302 | a = defaultdict() | |
@@ -311,9 +314,10 b' def test_collections_defaultdict():' | |||||
311 | (b, "defaultdict(list, {'key': defaultdict(...)})"), |
|
314 | (b, "defaultdict(list, {'key': defaultdict(...)})"), | |
312 | ] |
|
315 | ] | |
313 | for obj, expected in cases: |
|
316 | for obj, expected in cases: | |
314 |
|
|
317 | assert pretty.pretty(obj) == expected | |
315 |
|
318 | |||
316 |
|
319 | |||
|
320 | # TODO : pytest.mark.parametrise once nose is gone. | |||
317 | def test_collections_ordereddict(): |
|
321 | def test_collections_ordereddict(): | |
318 | # Create OrderedDict with cycle |
|
322 | # Create OrderedDict with cycle | |
319 | a = OrderedDict() |
|
323 | a = OrderedDict() | |
@@ -335,9 +339,10 b' def test_collections_ordereddict():' | |||||
335 | (a, "OrderedDict([('key', OrderedDict(...))])"), |
|
339 | (a, "OrderedDict([('key', OrderedDict(...))])"), | |
336 | ] |
|
340 | ] | |
337 | for obj, expected in cases: |
|
341 | for obj, expected in cases: | |
338 |
|
|
342 | assert pretty.pretty(obj) == expected | |
339 |
|
343 | |||
340 |
|
344 | |||
|
345 | # TODO : pytest.mark.parametrise once nose is gone. | |||
341 | def test_collections_deque(): |
|
346 | def test_collections_deque(): | |
342 | # Create deque with cycle |
|
347 | # Create deque with cycle | |
343 | a = deque() |
|
348 | a = deque() | |
@@ -369,8 +374,10 b' def test_collections_deque():' | |||||
369 | (a, 'deque([deque(...)])'), |
|
374 | (a, 'deque([deque(...)])'), | |
370 | ] |
|
375 | ] | |
371 | for obj, expected in cases: |
|
376 | for obj, expected in cases: | |
372 |
|
|
377 | assert pretty.pretty(obj) == expected | |
373 |
|
378 | |||
|
379 | ||||
|
380 | # TODO : pytest.mark.parametrise once nose is gone. | |||
374 | def test_collections_counter(): |
|
381 | def test_collections_counter(): | |
375 | class MyCounter(Counter): |
|
382 | class MyCounter(Counter): | |
376 | pass |
|
383 | pass | |
@@ -380,8 +387,9 b' def test_collections_counter():' | |||||
380 | (MyCounter(a=1), "MyCounter({'a': 1})"), |
|
387 | (MyCounter(a=1), "MyCounter({'a': 1})"), | |
381 | ] |
|
388 | ] | |
382 | for obj, expected in cases: |
|
389 | for obj, expected in cases: | |
383 |
|
|
390 | assert pretty.pretty(obj) == expected | |
384 |
|
391 | |||
|
392 | # TODO : pytest.mark.parametrise once nose is gone. | |||
385 | def test_mappingproxy(): |
|
393 | def test_mappingproxy(): | |
386 | MP = types.MappingProxyType |
|
394 | MP = types.MappingProxyType | |
387 | underlying_dict = {} |
|
395 | underlying_dict = {} | |
@@ -424,9 +432,10 b' def test_mappingproxy():' | |||||
424 | "{2: mappingproxy({2: {...}, 3: {...}}), 3: {...}}"), |
|
432 | "{2: mappingproxy({2: {...}, 3: {...}}), 3: {...}}"), | |
425 | ] |
|
433 | ] | |
426 | for obj, expected in cases: |
|
434 | for obj, expected in cases: | |
427 |
|
|
435 | assert pretty.pretty(obj) == expected | |
428 |
|
436 | |||
429 |
|
437 | |||
|
438 | # TODO : pytest.mark.parametrise once nose is gone. | |||
430 | def test_simplenamespace(): |
|
439 | def test_simplenamespace(): | |
431 | SN = types.SimpleNamespace |
|
440 | SN = types.SimpleNamespace | |
432 |
|
441 | |||
@@ -444,7 +453,7 b' def test_simplenamespace():' | |||||
444 | (sn_recursive, "namespace(first=namespace(...), second=namespace(...))"), |
|
453 | (sn_recursive, "namespace(first=namespace(...), second=namespace(...))"), | |
445 | ] |
|
454 | ] | |
446 | for obj, expected in cases: |
|
455 | for obj, expected in cases: | |
447 |
|
|
456 | assert pretty.pretty(obj) == expected | |
448 |
|
457 | |||
449 |
|
458 | |||
450 | def test_pretty_environ(): |
|
459 | def test_pretty_environ(): | |
@@ -452,7 +461,7 b' def test_pretty_environ():' | |||||
452 | # reindent to align with 'environ' prefix |
|
461 | # reindent to align with 'environ' prefix | |
453 | dict_indented = dict_repr.replace('\n', '\n' + (' ' * len('environ'))) |
|
462 | dict_indented = dict_repr.replace('\n', '\n' + (' ' * len('environ'))) | |
454 | env_repr = pretty.pretty(os.environ) |
|
463 | env_repr = pretty.pretty(os.environ) | |
455 |
|
|
464 | assert env_repr == "environ" + dict_indented | |
456 |
|
465 | |||
457 |
|
466 | |||
458 | def test_function_pretty(): |
|
467 | def test_function_pretty(): | |
@@ -460,7 +469,8 b' def test_function_pretty():' | |||||
460 | # posixpath is a pure python module, its interface is consistent |
|
469 | # posixpath is a pure python module, its interface is consistent | |
461 | # across Python distributions |
|
470 | # across Python distributions | |
462 | import posixpath |
|
471 | import posixpath | |
463 | nt.assert_equal(pretty.pretty(posixpath.join), '<function posixpath.join(a, *p)>') |
|
472 | ||
|
473 | assert pretty.pretty(posixpath.join) == "<function posixpath.join(a, *p)>" | |||
464 |
|
474 | |||
465 | # custom function |
|
475 | # custom function | |
466 | def meaning_of_life(question=None): |
|
476 | def meaning_of_life(question=None): | |
@@ -489,4 +499,4 b' def test_custom_repr():' | |||||
489 | oc = OrderedCounter("abracadabra") |
|
499 | oc = OrderedCounter("abracadabra") | |
490 | nt.assert_in("OrderedCounter(OrderedDict", pretty.pretty(oc)) |
|
500 | nt.assert_in("OrderedCounter(OrderedDict", pretty.pretty(oc)) | |
491 |
|
501 | |||
492 |
|
|
502 | assert pretty.pretty(MySet()) == "mine" |
General Comments 0
You need to be logged in to leave comments.
Login now