Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_pprint.py @ 28646:193b8aec00ce legacy-trunk
Changes from Jonathan Riehl to allow his pgen extension (PEP 269) to
work. This includes some more code that used to be part of pgen in
the main parser; I'm okay with that. I'll see if the Windows build
needs work next.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Apr 2003 14:55:42 +0000 |
| parents | 32e4c7753416 |
| children | e3025fe70d8b |
| rev | line source |
|---|---|
|
17820
4bcf88e4abff
SF bug[ #423781: pprint.isrecursive() broken.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1 import pprint |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
2 import test.test_support |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
3 import unittest |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
4 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17829
diff
changeset
|
5 try: |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17829
diff
changeset
|
6 uni = unicode |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17829
diff
changeset
|
7 except NameError: |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
8 def uni(x): |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
9 return x |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17829
diff
changeset
|
10 |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
11 |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
12 class QueryTestCase(unittest.TestCase): |
|
17820
4bcf88e4abff
SF bug[ #423781: pprint.isrecursive() broken.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
13 |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
14 def setUp(self): |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
15 self.a = range(100) |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
16 self.b = range(200) |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
17 self.a[-12] = self.b |
|
17820
4bcf88e4abff
SF bug[ #423781: pprint.isrecursive() broken.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
18 |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
19 def test_basic(self): |
|
24957
dc66eb4cd17a
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
20 # Verify .isrecursive() and .isreadable() w/o recursion |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
21 verify = self.assert_ |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
22 pp = pprint.PrettyPrinter() |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17829
diff
changeset
|
23 for safe in (2, 2.0, 2j, "abc", [3], (2,2), {3: 3}, uni("yaddayadda"), |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
24 self.a, self.b): |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
25 # module-level convenience functions |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
26 verify(not pprint.isrecursive(safe), |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
27 "expected not isrecursive for " + `safe`) |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
28 verify(pprint.isreadable(safe), |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
29 "expected isreadable for " + `safe`) |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
30 # PrettyPrinter methods |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
31 verify(not pp.isrecursive(safe), |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
32 "expected not isrecursive for " + `safe`) |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
33 verify(pp.isreadable(safe), |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
34 "expected isreadable for " + `safe`) |
|
17820
4bcf88e4abff
SF bug[ #423781: pprint.isrecursive() broken.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
35 |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
36 def test_knotted(self): |
|
24957
dc66eb4cd17a
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
37 # Verify .isrecursive() and .isreadable() w/ recursion |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
38 # Tie a knot. |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
39 self.b[67] = self.a |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
40 # Messy dict. |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
41 self.d = {} |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
42 self.d[0] = self.d[1] = self.d[2] = self.d |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
43 |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
44 verify = self.assert_ |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
45 pp = pprint.PrettyPrinter() |
|
17820
4bcf88e4abff
SF bug[ #423781: pprint.isrecursive() broken.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
46 |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
47 for icky in self.a, self.b, self.d, (self.d, self.d): |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
48 verify(pprint.isrecursive(icky), "expected isrecursive") |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
49 verify(not pprint.isreadable(icky), "expected not isreadable") |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
50 verify(pp.isrecursive(icky), "expected isrecursive") |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
51 verify(not pp.isreadable(icky), "expected not isreadable") |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
52 |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
53 # Break the cycles. |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
54 self.d.clear() |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
55 del self.a[:] |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
56 del self.b[:] |
|
17820
4bcf88e4abff
SF bug[ #423781: pprint.isrecursive() broken.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
57 |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
58 for safe in self.a, self.b, self.d, (self.d, self.d): |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
59 # module-level convenience functions |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
60 verify(not pprint.isrecursive(safe), |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
61 "expected not isrecursive for " + `safe`) |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
62 verify(pprint.isreadable(safe), |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
63 "expected isreadable for " + `safe`) |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
64 # PrettyPrinter methods |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
65 verify(not pp.isrecursive(safe), |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
66 "expected not isrecursive for " + `safe`) |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
67 verify(pp.isreadable(safe), |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
68 "expected isreadable for " + `safe`) |
|
17820
4bcf88e4abff
SF bug[ #423781: pprint.isrecursive() broken.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
69 |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
70 def test_unreadable(self): |
|
24957
dc66eb4cd17a
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
71 # Not recursive but not readable anyway |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
72 verify = self.assert_ |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
73 pp = pprint.PrettyPrinter() |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
74 for unreadable in type(3), pprint, pprint.isrecursive: |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
75 # module-level convenience functions |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
76 verify(not pprint.isrecursive(unreadable), |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
77 "expected not isrecursive for " + `unreadable`) |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
78 verify(not pprint.isreadable(unreadable), |
|
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
79 "expected not isreadable for " + `unreadable`) |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
80 # PrettyPrinter methods |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
81 verify(not pp.isrecursive(unreadable), |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
82 "expected not isrecursive for " + `unreadable`) |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
83 verify(not pp.isreadable(unreadable), |
|
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
84 "expected not isreadable for " + `unreadable`) |
|
17820
4bcf88e4abff
SF bug[ #423781: pprint.isrecursive() broken.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
85 |
|
17828
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
86 def test_same_as_repr(self): |
|
24957
dc66eb4cd17a
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
87 # Simple objects and small containers that should be same as repr() |
|
17828
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
88 verify = self.assert_ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17829
diff
changeset
|
89 for simple in (0, 0L, 0+0j, 0.0, "", uni(""), (), [], {}, verify, pprint, |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17829
diff
changeset
|
90 -6, -6L, -6-6j, -1.5, "x", uni("x"), (3,), [3], {3: 6}, |
|
17828
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
91 (1,2), [3,4], {5: 6, 7: 8}, |
|
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
92 {"xy\tab\n": (3,), 5: [[]], (): {}}, |
|
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
93 range(10, -11, -1) |
|
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
94 ): |
|
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
95 native = repr(simple) |
|
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
96 for function in "pformat", "saferepr": |
|
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
97 f = getattr(pprint, function) |
|
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
98 got = f(simple) |
|
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
99 verify(native == got, "expected %s got %s from pprint.%s" % |
|
26745053f840
pprint's workhorse _safe_repr() function took time quadratic in the # of
Tim Peters <tim.peters@gmail.com>
parents:
17827
diff
changeset
|
100 (native, got, function)) |
|
17827
0b3da99824c7
Convert the pprint test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
17820
diff
changeset
|
101 |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19343
diff
changeset
|
102 |
|
21061
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
103 def test_basic_line_wrap(self): |
|
24957
dc66eb4cd17a
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
104 # verify basic line-wrapping operation |
|
21061
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
105 o = {'RPM_cal': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
106 'RPM_cal2': 48059, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
107 'Speed_cal': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
108 'controldesk_runtime_us': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
109 'main_code_runtime_us': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
110 'read_io_runtime_us': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
111 'write_io_runtime_us': 43690} |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
112 exp = """\ |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
113 {'RPM_cal': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
114 'RPM_cal2': 48059, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
115 'Speed_cal': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
116 'controldesk_runtime_us': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
117 'main_code_runtime_us': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
118 'read_io_runtime_us': 0, |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
119 'write_io_runtime_us': 43690}""" |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
120 self.assertEqual(pprint.pformat(o), exp) |
|
1802a9edb4ee
__format(): Applied SF patch #482003 by Skip to fix multiline dict
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
121 |
|
22766
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
122 def test_subclassing(self): |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
123 o = {'names with spaces': 'should be presented using repr()', |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
124 'others.should.not.be': 'like.this'} |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
125 exp = """\ |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
126 {'names with spaces': 'should be presented using repr()', |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
127 others.should.not.be: like.this}""" |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
128 self.assertEqual(DottedPrettyPrinter().pformat(o), exp) |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
129 |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
130 |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
131 class DottedPrettyPrinter(pprint.PrettyPrinter): |
|
24957
dc66eb4cd17a
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
132 |
|
22766
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
133 def format(self, object, context, maxlevels, level): |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
134 if isinstance(object, str): |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
135 if ' ' in object: |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
136 return `object`, 1, 0 |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
137 else: |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
138 return object, 0, 0 |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
139 else: |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
140 return pprint.PrettyPrinter.format( |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
141 self, object, context, maxlevels, level) |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
142 |
|
d26d8575ac62
Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents:
21061
diff
changeset
|
143 |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19343
diff
changeset
|
144 def test_main(): |
|
26930
32e4c7753416
Make sure PrettyPrinter methods that mirror the module-level
Fred Drake <fdrake@acm.org>
parents:
24957
diff
changeset
|
145 test.test_support.run_unittest(QueryTestCase) |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19343
diff
changeset
|
146 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19343
diff
changeset
|
147 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19343
diff
changeset
|
148 if __name__ == "__main__": |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19343
diff
changeset
|
149 test_main() |
