Show More
@@ -0,0 +1,49 b'' | |||||
|
1 | """Tests for IPython.lib.pretty. | |||
|
2 | """ | |||
|
3 | #----------------------------------------------------------------------------- | |||
|
4 | # Copyright (c) 2011, the IPython Development Team. | |||
|
5 | # | |||
|
6 | # Distributed under the terms of the Modified BSD License. | |||
|
7 | # | |||
|
8 | # The full license is in the file COPYING.txt, distributed with this software. | |||
|
9 | #----------------------------------------------------------------------------- | |||
|
10 | ||||
|
11 | #----------------------------------------------------------------------------- | |||
|
12 | # Imports | |||
|
13 | #----------------------------------------------------------------------------- | |||
|
14 | from __future__ import print_function | |||
|
15 | ||||
|
16 | # Third-party imports | |||
|
17 | import nose.tools as nt | |||
|
18 | ||||
|
19 | # Our own imports | |||
|
20 | from IPython.lib import pretty | |||
|
21 | ||||
|
22 | #----------------------------------------------------------------------------- | |||
|
23 | # Classes and functions | |||
|
24 | #----------------------------------------------------------------------------- | |||
|
25 | ||||
|
26 | class MyList(object): | |||
|
27 | def __init__(self, content): | |||
|
28 | self.content = content | |||
|
29 | def _repr_pretty_(self, p, cycle): | |||
|
30 | if cycle: | |||
|
31 | p.text("MyList(...)") | |||
|
32 | else: | |||
|
33 | with p.group(3, "MyList(", ")"): | |||
|
34 | for (i, child) in enumerate(self.content): | |||
|
35 | if i: | |||
|
36 | p.text(",") | |||
|
37 | p.breakable() | |||
|
38 | else: | |||
|
39 | p.breakable("") | |||
|
40 | p.pretty(child) | |||
|
41 | ||||
|
42 | ||||
|
43 | def test_indentation(): | |||
|
44 | """Test correct indentation in groups""" | |||
|
45 | count = 40 | |||
|
46 | gotoutput = pretty.pretty(MyList(range(count))) | |||
|
47 | expectedoutput = "MyList(\n" + ",\n".join(" %d" % i for i in range(count)) + ")" | |||
|
48 | ||||
|
49 | nt.assert_equals(gotoutput, expectedoutput) |
@@ -155,7 +155,6 b' class _PrettyPrinterBase(object):' | |||||
155 | """like begin_group / end_group but for the with statement.""" |
|
155 | """like begin_group / end_group but for the with statement.""" | |
156 | self.begin_group(indent, open) |
|
156 | self.begin_group(indent, open) | |
157 | try: |
|
157 | try: | |
158 | with self.indent(indent): |
|
|||
159 |
|
|
158 | yield | |
160 | finally: |
|
159 | finally: | |
161 | self.end_group(indent, close) |
|
160 | self.end_group(indent, close) |
General Comments 0
You need to be logged in to leave comments.
Login now