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