diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-03-23 19:30:39 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-03-23 19:30:39 (GMT) |
commit | 64c16c3311d6ef8077498096e8874756477027de (patch) | |
tree | ba260cf3e542da7d488e71e472893b63050a3181 /Lib/test/test_pprint.py | |
parent | 4a8ea9e2a6d07bb069419274fb4dd75cfb6e3e55 (diff) | |
download | cpython-64c16c3311d6ef8077498096e8874756477027de.zip cpython-64c16c3311d6ef8077498096e8874756477027de.tar.gz cpython-64c16c3311d6ef8077498096e8874756477027de.tar.bz2 |
Issue #17150: pprint now uses line continuations to wrap long string literals.
Diffstat (limited to 'Lib/test/test_pprint.py')
-rw-r--r-- | Lib/test/test_pprint.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index d492d75..bf136de 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import pprint import test.support import unittest @@ -475,6 +477,42 @@ class QueryTestCase(unittest.TestCase): self.assertEqual(pprint.pformat(dict.fromkeys(keys, 0)), '{%r: 0, %r: 0}' % tuple(sorted(keys, key=id))) + def test_str_wrap(self): + # pprint tries to wrap strings intelligently + fox = 'the quick brown fox jumped over a lazy dog' + self.assertEqual(pprint.pformat(fox, width=20), """\ +'the quick brown ' +'fox jumped over ' +'a lazy dog'""") + self.assertEqual(pprint.pformat({'a': 1, 'b': fox, 'c': 2}, + width=26), """\ +{'a': 1, + 'b': 'the quick brown ' + 'fox jumped over ' + 'a lazy dog', + 'c': 2}""") + # With some special characters + # - \n always triggers a new line in the pprint + # - \t and \n are escaped + # - non-ASCII is allowed + # - an apostrophe doesn't disrupt the pprint + special = "Portons dix bons \"whiskys\"\nà l'avocat goujat\t qui fumait au zoo" + self.assertEqual(pprint.pformat(special, width=20), """\ +'Portons dix bons ' +'"whiskys"\\n' +"à l'avocat " +'goujat\\t qui ' +'fumait au zoo'""") + # An unwrappable string is formatted as its repr + unwrappable = "x" * 100 + self.assertEqual(pprint.pformat(unwrappable, width=80), repr(unwrappable)) + self.assertEqual(pprint.pformat(''), "''") + # Check that the pprint is a usable repr + special *= 10 + for width in range(3, 40): + formatted = pprint.pformat(special, width=width) + self.assertEqual(eval("(" + formatted + ")"), special) + class DottedPrettyPrinter(pprint.PrettyPrinter): |