Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_unicode.py @ 79691:05c8928362ee
Merge __next__ method link fixes with 3.3.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 12 Oct 2012 13:46:37 +0300 |
| parents | e16ec3b468d1 |
| children | 22c8e6d71529 |
| rev | line source |
|---|---|
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 """ Test script for the Unicode implementation. |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 Written by Marc-Andre Lemburg (mal@lemburg.com). |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
15957
c1a8deb15f0e
This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents:
15910
diff
changeset
|
7 """#" |
|
73579
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
8 import _string |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
9 import codecs |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
10 import struct |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
11 import sys |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
12 import unittest |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
13 import warnings |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46307
diff
changeset
|
14 from test import support, string_tests |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
15 |
|
35938
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
16 # Error handling (bad decoder return) |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
17 def search_function(encoding): |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
18 def decode1(input, errors="strict"): |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
19 return 42 # not a tuple |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
20 def encode1(input, errors="strict"): |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
21 return 42 # not a tuple |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
22 def encode2(input, errors="strict"): |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
23 return (42, 42) # no unicode |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
24 def decode2(input, errors="strict"): |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
25 return (42, 42) # no unicode |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
26 if encoding=="test.unicode1": |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
27 return (encode1, decode1, None, None) |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
28 elif encoding=="test.unicode2": |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
29 return (encode2, decode2, None, None) |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
30 else: |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
31 return None |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
32 codecs.register(search_function) |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
33 |
|
59775
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
34 class UnicodeTest(string_tests.CommonTest, |
|
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
35 string_tests.MixinStrUnicodeUserStringTest, |
|
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
36 string_tests.MixinStrUnicodeTest): |
|
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
37 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
38 type2test = str |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
39 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
40 def checkequalnofix(self, result, object, methodname, *args): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
41 method = getattr(object, methodname) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
42 realresult = method(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
43 self.assertEqual(realresult, result) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54484
diff
changeset
|
44 self.assertTrue(type(realresult) is type(result)) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
45 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
46 # if the original is returned make sure that |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
47 # this doesn't happen with subclasses |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
48 if realresult is object: |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
49 class usub(str): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
50 def __repr__(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
51 return 'usub(%r)' % str.__repr__(self) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
52 object = usub(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
53 method = getattr(object, methodname) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
54 realresult = method(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
55 self.assertEqual(realresult, result) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54484
diff
changeset
|
56 self.assertTrue(object is not realresult) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 |
|
30653
3b47d6057151
Fix for SF bug [ 817156 ] invalid \U escape gives 0=length unistr.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30059
diff
changeset
|
58 def test_literals(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
59 self.assertEqual('\xff', '\u00ff') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
60 self.assertEqual('\uffff', '\U0000ffff') |
|
42324
4bbbe0c55fa2
Merged revisions 56443-56466 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42313
diff
changeset
|
61 self.assertRaises(SyntaxError, eval, '\'\\Ufffffffe\'') |
|
4bbbe0c55fa2
Merged revisions 56443-56466 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42313
diff
changeset
|
62 self.assertRaises(SyntaxError, eval, '\'\\Uffffffff\'') |
|
4bbbe0c55fa2
Merged revisions 56443-56466 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42313
diff
changeset
|
63 self.assertRaises(SyntaxError, eval, '\'\\U%08x\'' % 0x110000) |
|
46307
c3dcc0c7bfd9
Added a test to make sure raw strings don't get unicode escapes
Benjamin Peterson <benjamin@python.org>
parents:
46306
diff
changeset
|
64 # raw strings should not have unicode escapes |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65661
diff
changeset
|
65 self.assertNotEqual(r"\u0020", " ") |
|
30653
3b47d6057151
Fix for SF bug [ 817156 ] invalid \U escape gives 0=length unistr.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30059
diff
changeset
|
66 |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
67 def test_ascii(self): |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
68 if not sys.platform.startswith('java'): |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
69 # Test basic sanity of repr() |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
70 self.assertEqual(ascii('abc'), "'abc'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
71 self.assertEqual(ascii('ab\\c'), "'ab\\\\c'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
72 self.assertEqual(ascii('ab\\'), "'ab\\\\'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
73 self.assertEqual(ascii('\\c'), "'\\\\c'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
74 self.assertEqual(ascii('\\'), "'\\\\'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
75 self.assertEqual(ascii('\n'), "'\\n'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
76 self.assertEqual(ascii('\r'), "'\\r'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
77 self.assertEqual(ascii('\t'), "'\\t'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
78 self.assertEqual(ascii('\b'), "'\\x08'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
79 self.assertEqual(ascii("'\""), """'\\'"'""") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
80 self.assertEqual(ascii("'\""), """'\\'"'""") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
81 self.assertEqual(ascii("'"), '''"'"''') |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
82 self.assertEqual(ascii('"'), """'"'""") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
83 latin1repr = ( |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
84 "'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
85 "\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
86 "\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHI" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
87 "JKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
88 "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
89 "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
90 "\\x9c\\x9d\\x9e\\x9f\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
91 "\\xaa\\xab\\xac\\xad\\xae\\xaf\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
92 "\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
93 "\\xc6\\xc7\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\\xd0\\xd1\\xd2\\xd3" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
94 "\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\\xe0\\xe1" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
95 "\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
96 "\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
97 "\\xfe\\xff'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
98 testrepr = ascii(''.join(map(chr, range(256)))) |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
99 self.assertEqual(testrepr, latin1repr) |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
100 # Test ascii works on wide unicode escapes without overflow. |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
101 self.assertEqual(ascii("\U00010000" * 39 + "\uffff" * 4096), |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
102 ascii("\U00010000" * 39 + "\uffff" * 4096)) |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
103 |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
104 class WrongRepr: |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
105 def __repr__(self): |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
106 return b'byte-repr' |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
107 self.assertRaises(TypeError, ascii, WrongRepr()) |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
108 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
109 def test_repr(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
110 if not sys.platform.startswith('java'): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
111 # Test basic sanity of repr() |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
112 self.assertEqual(repr('abc'), "'abc'") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
113 self.assertEqual(repr('ab\\c'), "'ab\\\\c'") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
114 self.assertEqual(repr('ab\\'), "'ab\\\\'") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
115 self.assertEqual(repr('\\c'), "'\\\\c'") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
116 self.assertEqual(repr('\\'), "'\\\\'") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
117 self.assertEqual(repr('\n'), "'\\n'") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
118 self.assertEqual(repr('\r'), "'\\r'") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
119 self.assertEqual(repr('\t'), "'\\t'") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
120 self.assertEqual(repr('\b'), "'\\x08'") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
121 self.assertEqual(repr("'\""), """'\\'"'""") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
122 self.assertEqual(repr("'\""), """'\\'"'""") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
123 self.assertEqual(repr("'"), '''"'"''') |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
124 self.assertEqual(repr('"'), """'"'""") |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
125 latin1repr = ( |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
126 "'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r" |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
127 "\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
128 "\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHI" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
129 "JKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
130 "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
131 "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b" |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
132 "\\x9c\\x9d\\x9e\\x9f\\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
133 "\xaa\xab\xac\\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
134 "\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
135 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
136 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
137 "\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
138 "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd" |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
139 "\xfe\xff'") |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41620
diff
changeset
|
140 testrepr = repr(''.join(map(chr, range(256)))) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
141 self.assertEqual(testrepr, latin1repr) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39544
diff
changeset
|
142 # Test repr works on wide unicode escapes without overflow. |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
143 self.assertEqual(repr("\U00010000" * 39 + "\uffff" * 4096), |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
144 repr("\U00010000" * 39 + "\uffff" * 4096)) |
|
20017
08446a986a56
Test basic functioning of unicode repr(). (If this breaks Jython,
Guido van Rossum <guido@python.org>
parents:
19999
diff
changeset
|
145 |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
146 class WrongRepr: |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
147 def __repr__(self): |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
148 return b'byte-repr' |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
149 self.assertRaises(TypeError, repr, WrongRepr()) |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
150 |
|
39544
01034018e8b2
Make the it_index field in the str/unicode iterators Py_ssize_t's.
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
151 def test_iterators(self): |
|
01034018e8b2
Make the it_index field in the str/unicode iterators Py_ssize_t's.
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
152 # Make sure unicode objects have an __iter__ method |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
153 it = "\u1111\u2222\u3333".__iter__() |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
154 self.assertEqual(next(it), "\u1111") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
155 self.assertEqual(next(it), "\u2222") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
156 self.assertEqual(next(it), "\u3333") |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41480
diff
changeset
|
157 self.assertRaises(StopIteration, next, it) |
|
39544
01034018e8b2
Make the it_index field in the str/unicode iterators Py_ssize_t's.
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
158 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
159 def test_count(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
160 string_tests.CommonTest.test_count(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
161 # check mixed argument types |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
162 self.checkequalnofix(3, 'aaa', 'count', 'a') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
163 self.checkequalnofix(0, 'aaa', 'count', 'b') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
164 self.checkequalnofix(3, 'aaa', 'count', 'a') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
165 self.checkequalnofix(0, 'aaa', 'count', 'b') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
166 self.checkequalnofix(0, 'aaa', 'count', 'b') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
167 self.checkequalnofix(1, 'aaa', 'count', 'a', -1) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
168 self.checkequalnofix(3, 'aaa', 'count', 'a', -10) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
169 self.checkequalnofix(2, 'aaa', 'count', 'a', 0, -1) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
170 self.checkequalnofix(0, 'aaa', 'count', 'a', 0, -10) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
172 def test_find(self): |
|
72813
5ae50a57dd91
test_unicode was forgetting to run the common string tests for str.find()
Antoine Pitrou <solipsis@pitrou.net>
parents:
72040
diff
changeset
|
173 string_tests.CommonTest.test_find(self) |
|
72859
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
174 # test implementation details of the memchr fast path |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
175 self.checkequal(100, 'a' * 100 + '\u0102', 'find', '\u0102') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
176 self.checkequal(-1, 'a' * 100 + '\u0102', 'find', '\u0201') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
177 self.checkequal(-1, 'a' * 100 + '\u0102', 'find', '\u0120') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
178 self.checkequal(-1, 'a' * 100 + '\u0102', 'find', '\u0220') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
179 self.checkequal(100, 'a' * 100 + '\U00100304', 'find', '\U00100304') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
180 self.checkequal(-1, 'a' * 100 + '\U00100304', 'find', '\U00100204') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
181 self.checkequal(-1, 'a' * 100 + '\U00100304', 'find', '\U00102004') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
182 # check mixed argument types |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
183 self.checkequalnofix(0, 'abcdefghiabc', 'find', 'abc') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
184 self.checkequalnofix(9, 'abcdefghiabc', 'find', 'abc', 1) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
185 self.checkequalnofix(-1, 'abcdefghiabc', 'find', 'def', 4) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
186 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
187 self.assertRaises(TypeError, 'hello'.find) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
188 self.assertRaises(TypeError, 'hello'.find, 42) |
|
15910
f7f3be3d00b9
Added checks to prevent PyUnicode_Count() from dumping core
Marc-André Lemburg <mal@egenix.com>
parents:
15706
diff
changeset
|
189 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
190 def test_rfind(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
191 string_tests.CommonTest.test_rfind(self) |
|
72859
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
192 # test implementation details of the memrchr fast path |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
193 self.checkequal(0, '\u0102' + 'a' * 100 , 'rfind', '\u0102') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
194 self.checkequal(-1, '\u0102' + 'a' * 100 , 'rfind', '\u0201') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
195 self.checkequal(-1, '\u0102' + 'a' * 100 , 'rfind', '\u0120') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
196 self.checkequal(-1, '\u0102' + 'a' * 100 , 'rfind', '\u0220') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
197 self.checkequal(0, '\U00100304' + 'a' * 100, 'rfind', '\U00100304') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
198 self.checkequal(-1, '\U00100304' + 'a' * 100, 'rfind', '\U00100204') |
|
af4a89f4f466
Issue #13134: optimize finding single-character strings using memchr
Antoine Pitrou <solipsis@pitrou.net>
parents:
72814
diff
changeset
|
199 self.checkequal(-1, '\U00100304' + 'a' * 100, 'rfind', '\U00102004') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
200 # check mixed argument types |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
201 self.checkequalnofix(9, 'abcdefghiabc', 'rfind', 'abc') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
202 self.checkequalnofix(12, 'abcdefghiabc', 'rfind', '') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
203 self.checkequalnofix(12, 'abcdefghiabc', 'rfind', '') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
205 def test_index(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
206 string_tests.CommonTest.test_index(self) |
|
41592
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
207 self.checkequalnofix(0, 'abcdefghiabc', 'index', '') |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
208 self.checkequalnofix(3, 'abcdefghiabc', 'index', 'def') |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
209 self.checkequalnofix(0, 'abcdefghiabc', 'index', 'abc') |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
210 self.checkequalnofix(9, 'abcdefghiabc', 'index', 'abc', 1) |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
211 self.assertRaises(ValueError, 'abcdefghiabc'.index, 'hib') |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
212 self.assertRaises(ValueError, 'abcdefghiab'.index, 'abc', 1) |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
213 self.assertRaises(ValueError, 'abcdefghi'.index, 'ghi', 8) |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
214 self.assertRaises(ValueError, 'abcdefghi'.index, 'ghi', -1) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
216 def test_rindex(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
217 string_tests.CommonTest.test_rindex(self) |
|
41592
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
218 self.checkequalnofix(12, 'abcdefghiabc', 'rindex', '') |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
219 self.checkequalnofix(3, 'abcdefghiabc', 'rindex', 'def') |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
220 self.checkequalnofix(9, 'abcdefghiabc', 'rindex', 'abc') |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
221 self.checkequalnofix(0, 'abcdefghiabc', 'rindex', 'abc', 0, -1) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 |
|
41592
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
223 self.assertRaises(ValueError, 'abcdefghiabc'.rindex, 'hib') |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
224 self.assertRaises(ValueError, 'defghiabc'.rindex, 'def', 1) |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
225 self.assertRaises(ValueError, 'defghiabc'.rindex, 'abc', 0, -1) |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
226 self.assertRaises(ValueError, 'abcdefghi'.rindex, 'ghi', 0, 8) |
|
1e5a2a2b18ee
Fix various spots where int/long and str/unicode unification
Walter Dörwald <walter@livinglogic.de>
parents:
41585
diff
changeset
|
227 self.assertRaises(ValueError, 'abcdefghi'.rindex, 'ghi', 0, -1) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
228 |
|
44039
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
229 def test_maketrans_translate(self): |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
230 # these work with plain translate() |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
231 self.checkequalnofix('bbbc', 'abababc', 'translate', |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
232 {ord('a'): None}) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
233 self.checkequalnofix('iiic', 'abababc', 'translate', |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
234 {ord('a'): None, ord('b'): ord('i')}) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
235 self.checkequalnofix('iiix', 'abababc', 'translate', |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
236 {ord('a'): None, ord('b'): ord('i'), ord('c'): 'x'}) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
237 self.checkequalnofix('c', 'abababc', 'translate', |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
238 {ord('a'): None, ord('b'): ''}) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
239 self.checkequalnofix('xyyx', 'xzx', 'translate', |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
240 {ord('z'): 'yy'}) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
241 # this needs maketrans() |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
242 self.checkequalnofix('abababc', 'abababc', 'translate', |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
243 {'b': '<i>'}) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
244 tbl = self.type2test.maketrans({'a': None, 'b': '<i>'}) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
245 self.checkequalnofix('<i><i><i>c', 'abababc', 'translate', tbl) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
246 # test alternative way of calling maketrans() |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
247 tbl = self.type2test.maketrans('abc', 'xyz', 'd') |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
248 self.checkequalnofix('xyzzy', 'abdcdcbdddd', 'translate', tbl) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
249 |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
250 self.assertRaises(TypeError, self.type2test.maketrans) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
251 self.assertRaises(ValueError, self.type2test.maketrans, 'abc', 'defg') |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
252 self.assertRaises(TypeError, self.type2test.maketrans, 2, 'def') |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
253 self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 2) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
254 self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 'def', 2) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
255 self.assertRaises(ValueError, self.type2test.maketrans, {'xy': 2}) |
|
12e728035e2c
#1496: revert str.translate() to the old version, and add
Georg Brandl <georg@python.org>
parents:
43947
diff
changeset
|
256 self.assertRaises(TypeError, self.type2test.maketrans, {(1,): 2}) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
257 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
258 self.assertRaises(TypeError, 'hello'.translate) |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
259 self.assertRaises(TypeError, 'abababc'.translate, 'abc', 'xyz') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
261 def test_split(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
262 string_tests.CommonTest.test_split(self) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
264 # Mixed arguments |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
265 self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
266 self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
267 self.checkequalnofix(['endcase ', ''], 'endcase test', 'split', 'test') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
269 def test_join(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
270 string_tests.MixinStrUnicodeUserStringTest.test_join(self) |
|
23225
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
23115
diff
changeset
|
271 |
|
43446
a7c48ab809ec
Patch # 1145 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents:
43241
diff
changeset
|
272 class MyWrapper: |
|
a7c48ab809ec
Patch # 1145 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents:
43241
diff
changeset
|
273 def __init__(self, sval): self.sval = sval |
|
a7c48ab809ec
Patch # 1145 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents:
43241
diff
changeset
|
274 def __str__(self): return self.sval |
|
a7c48ab809ec
Patch # 1145 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents:
43241
diff
changeset
|
275 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
276 # mixed arguments |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
277 self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd']) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
278 self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd')) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
279 self.checkequalnofix('w x y z', ' ', 'join', string_tests.Sequence('wxyz')) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
280 self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd']) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
281 self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd']) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
282 self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd')) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
283 self.checkequalnofix('w x y z', ' ', 'join', string_tests.Sequence('wxyz')) |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
284 self.checkraises(TypeError, ' ', 'join', ['1', '2', MyWrapper('foo')]) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
285 self.checkraises(TypeError, ' ', 'join', ['1', '2', '3', bytes()]) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
286 self.checkraises(TypeError, ' ', 'join', [1, 2, 3]) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
287 self.checkraises(TypeError, ' ', 'join', ['1', '2', 3]) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
289 def test_replace(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
290 string_tests.CommonTest.test_replace(self) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
291 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
292 # method call forwarded from str implementation because of unicode argument |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
293 self.checkequalnofix('one@two!three!', 'one!two!three!', 'replace', '!', '@', 1) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
294 self.assertRaises(TypeError, 'replace'.replace, "r", 42) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 |
|
72784
9c1b76936b79
str.replace(a, a) is now returning str unchanged if a is a
Victor Stinner <vstinner@wyplay.com>
parents:
72666
diff
changeset
|
296 @support.cpython_only |
|
9c1b76936b79
str.replace(a, a) is now returning str unchanged if a is a
Victor Stinner <vstinner@wyplay.com>
parents:
72666
diff
changeset
|
297 def test_replace_id(self): |
|
72788
e3d5b718f2e6
Mark 'abc'.expandtab() optimization as specific to CPython
Victor Stinner <vstinner@wyplay.com>
parents:
72784
diff
changeset
|
298 pattern = 'abc' |
|
e3d5b718f2e6
Mark 'abc'.expandtab() optimization as specific to CPython
Victor Stinner <vstinner@wyplay.com>
parents:
72784
diff
changeset
|
299 text = 'abc def' |
|
e3d5b718f2e6
Mark 'abc'.expandtab() optimization as specific to CPython
Victor Stinner <vstinner@wyplay.com>
parents:
72784
diff
changeset
|
300 self.assertIs(text.replace(pattern, pattern), text) |
|
72784
9c1b76936b79
str.replace(a, a) is now returning str unchanged if a is a
Victor Stinner <vstinner@wyplay.com>
parents:
72666
diff
changeset
|
301 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
302 def test_bytes_comparison(self): |
|
59775
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
303 with support.check_warnings(): |
|
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
304 warnings.simplefilter('ignore', BytesWarning) |
|
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
305 self.assertEqual('abc' == b'abc', False) |
|
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
306 self.assertEqual('abc' != b'abc', True) |
|
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
307 self.assertEqual('abc' == bytearray(b'abc'), False) |
|
e619047a2f36
Clean up the warnings filter use in test_unicode.
Brett Cannon <bcannon@gmail.com>
parents:
58415
diff
changeset
|
308 self.assertEqual('abc' != bytearray(b'abc'), True) |
|
43638
b10544827af7
Make str/str8 comparisons return True/False for !=/==.
Brett Cannon <bcannon@gmail.com>
parents:
43487
diff
changeset
|
309 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
310 def test_comparison(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
311 # Comparisons: |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
312 self.assertEqual('abc', 'abc') |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54484
diff
changeset
|
313 self.assertTrue('abcd' > 'abc') |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54484
diff
changeset
|
314 self.assertTrue('abc' < 'abcd') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
315 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
316 if 0: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
317 # Move these tests to a Unicode collation module test... |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
318 # Testing UTF-16 code point order comparisons... |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
319 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
320 # No surrogates, no fixup required. |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54484
diff
changeset
|
321 self.assertTrue('\u0061' < '\u20ac') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
322 # Non surrogate below surrogate value, no fixup required |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54484
diff
changeset
|
323 self.assertTrue('\u0061' < '\ud800\udc02') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
324 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
325 # Non surrogate above surrogate value, fixup required |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
326 def test_lecmp(s, s2): |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54484
diff
changeset
|
327 self.assertTrue(s < s2) |
|
13410
5157eb7be20d
Tests for new surrogate support in the UTF-8 codec. By Bill Tutt.
Marc-André Lemburg <mal@egenix.com>
parents:
13400
diff
changeset
|
328 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
329 def test_fixup(s): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
330 s2 = '\ud800\udc01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
331 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
332 s2 = '\ud900\udc01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
333 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
334 s2 = '\uda00\udc01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
335 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
336 s2 = '\udb00\udc01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
337 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
338 s2 = '\ud800\udd01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
339 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
340 s2 = '\ud900\udd01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
341 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
342 s2 = '\uda00\udd01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
343 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
344 s2 = '\udb00\udd01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
345 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
346 s2 = '\ud800\ude01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
347 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
348 s2 = '\ud900\ude01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
349 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
350 s2 = '\uda00\ude01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
351 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
352 s2 = '\udb00\ude01' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
353 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
354 s2 = '\ud800\udfff' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
355 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
356 s2 = '\ud900\udfff' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
357 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
358 s2 = '\uda00\udfff' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
359 test_lecmp(s, s2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
360 s2 = '\udb00\udfff' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
361 test_lecmp(s, s2) |
|
13410
5157eb7be20d
Tests for new surrogate support in the UTF-8 codec. By Bill Tutt.
Marc-André Lemburg <mal@egenix.com>
parents:
13400
diff
changeset
|
362 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
363 test_fixup('\ue000') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
364 test_fixup('\uff61') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
365 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
366 # Surrogates on both sides, no fixup required |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54484
diff
changeset
|
367 self.assertTrue('\ud800\udc02' < '\ud84d\udc56') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
369 def test_islower(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
370 string_tests.MixinStrUnicodeUserStringTest.test_islower(self) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
371 self.checkequalnofix(False, '\u1FFc', 'islower') |
|
74338
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
372 self.assertFalse('\u2167'.islower()) |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
373 self.assertTrue('\u2177'.islower()) |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
374 # non-BMP, uppercase |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
375 self.assertFalse('\U00010401'.islower()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
376 self.assertFalse('\U00010427'.islower()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
377 # non-BMP, lowercase |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
378 self.assertTrue('\U00010429'.islower()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
379 self.assertTrue('\U0001044E'.islower()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
380 # non-BMP, non-cased |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
381 self.assertFalse('\U0001F40D'.islower()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
382 self.assertFalse('\U0001F46F'.islower()) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
384 def test_isupper(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
385 string_tests.MixinStrUnicodeUserStringTest.test_isupper(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
386 if not sys.platform.startswith('java'): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
387 self.checkequalnofix(False, '\u1FFc', 'isupper') |
|
74338
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
388 self.assertTrue('\u2167'.isupper()) |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
389 self.assertFalse('\u2177'.isupper()) |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
390 # non-BMP, uppercase |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
391 self.assertTrue('\U00010401'.isupper()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
392 self.assertTrue('\U00010427'.isupper()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
393 # non-BMP, lowercase |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
394 self.assertFalse('\U00010429'.isupper()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
395 self.assertFalse('\U0001044E'.isupper()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
396 # non-BMP, non-cased |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
397 self.assertFalse('\U0001F40D'.isupper()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
398 self.assertFalse('\U0001F46F'.isupper()) |
|
13353
0b289e00d52a
Added tests for the new .isalpha() and .isalnum() methods.
Marc-André Lemburg <mal@egenix.com>
parents:
13189
diff
changeset
|
399 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
400 def test_istitle(self): |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
401 string_tests.MixinStrUnicodeUserStringTest.test_istitle(self) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
402 self.checkequalnofix(True, '\u1FFc', 'istitle') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
403 self.checkequalnofix(True, 'Greek \u1FFcitlecases ...', 'istitle') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
405 # non-BMP, uppercase + lowercase |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
406 self.assertTrue('\U00010401\U00010429'.istitle()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
407 self.assertTrue('\U00010427\U0001044E'.istitle()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
408 # apparently there are no titlecased (Lt) non-BMP chars in Unicode 6 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
409 for ch in ['\U00010429', '\U0001044E', '\U0001F40D', '\U0001F46F']: |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
410 self.assertFalse(ch.istitle(), '{!a} is not title'.format(ch)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
411 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
412 def test_isspace(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
413 string_tests.MixinStrUnicodeUserStringTest.test_isspace(self) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
414 self.checkequalnofix(True, '\u2000', 'isspace') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
415 self.checkequalnofix(True, '\u200a', 'isspace') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
416 self.checkequalnofix(False, '\u2014', 'isspace') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
417 # apparently there are no non-BMP spaces chars in Unicode 6 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
418 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
419 '\U0001F40D', '\U0001F46F']: |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
420 self.assertFalse(ch.isspace(), '{!a} is not space.'.format(ch)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
421 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
422 def test_isalnum(self): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
423 string_tests.MixinStrUnicodeUserStringTest.test_isalnum(self) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
424 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
425 '\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']: |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
426 self.assertTrue(ch.isalnum(), '{!a} is alnum.'.format(ch)) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
427 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
428 def test_isalpha(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
429 string_tests.MixinStrUnicodeUserStringTest.test_isalpha(self) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
430 self.checkequalnofix(True, '\u1FFc', 'isalpha') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
431 # non-BMP, cased |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
432 self.assertTrue('\U00010401'.isalpha()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
433 self.assertTrue('\U00010427'.isalpha()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
434 self.assertTrue('\U00010429'.isalpha()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
435 self.assertTrue('\U0001044E'.isalpha()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
436 # non-BMP, non-cased |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
437 self.assertFalse('\U0001F40D'.isalpha()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
438 self.assertFalse('\U0001F46F'.isalpha()) |
|
12001
e362f326048c
Marc-Andre Lemburg: Add tests for mixed use of char in string.
Guido van Rossum <guido@python.org>
parents:
11992
diff
changeset
|
439 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
440 def test_isdecimal(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
441 self.checkequalnofix(False, '', 'isdecimal') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
442 self.checkequalnofix(False, 'a', 'isdecimal') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
443 self.checkequalnofix(True, '0', 'isdecimal') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
444 self.checkequalnofix(False, '\u2460', 'isdecimal') # CIRCLED DIGIT ONE |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
445 self.checkequalnofix(False, '\xbc', 'isdecimal') # VULGAR FRACTION ONE QUARTER |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
446 self.checkequalnofix(True, '\u0660', 'isdecimal') # ARABIC-INDIC DIGIT ZERO |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
447 self.checkequalnofix(True, '0123456789', 'isdecimal') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
448 self.checkequalnofix(False, '0123456789a', 'isdecimal') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
449 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
450 self.checkraises(TypeError, 'abc', 'isdecimal', 42) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
451 |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
452 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
453 '\U0001F40D', '\U0001F46F', '\U00011065', '\U0001F107']: |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
454 self.assertFalse(ch.isdecimal(), '{!a} is not decimal.'.format(ch)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
455 for ch in ['\U0001D7F6', '\U00011066', '\U000104A0']: |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
456 self.assertTrue(ch.isdecimal(), '{!a} is decimal.'.format(ch)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
457 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
458 def test_isdigit(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
459 string_tests.MixinStrUnicodeUserStringTest.test_isdigit(self) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
460 self.checkequalnofix(True, '\u2460', 'isdigit') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
461 self.checkequalnofix(False, '\xbc', 'isdigit') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
462 self.checkequalnofix(True, '\u0660', 'isdigit') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
463 |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
464 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
465 '\U0001F40D', '\U0001F46F', '\U00011065']: |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
466 self.assertFalse(ch.isdigit(), '{!a} is not a digit.'.format(ch)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
467 for ch in ['\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']: |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
468 self.assertTrue(ch.isdigit(), '{!a} is a digit.'.format(ch)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
469 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
470 def test_isnumeric(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
471 self.checkequalnofix(False, '', 'isnumeric') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
472 self.checkequalnofix(False, 'a', 'isnumeric') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
473 self.checkequalnofix(True, '0', 'isnumeric') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
474 self.checkequalnofix(True, '\u2460', 'isnumeric') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
475 self.checkequalnofix(True, '\xbc', 'isnumeric') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
476 self.checkequalnofix(True, '\u0660', 'isnumeric') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
477 self.checkequalnofix(True, '0123456789', 'isnumeric') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
478 self.checkequalnofix(False, '0123456789a', 'isnumeric') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
479 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
480 self.assertRaises(TypeError, "abc".isnumeric, 42) |
|
12917
2a2caaee6797
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12897
diff
changeset
|
481 |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
482 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
483 '\U0001F40D', '\U0001F46F']: |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
484 self.assertFalse(ch.isnumeric(), '{!a} is not numeric.'.format(ch)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
485 for ch in ['\U00011065', '\U0001D7F6', '\U00011066', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
486 '\U000104A0', '\U0001F107']: |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
487 self.assertTrue(ch.isnumeric(), '{!a} is numeric.'.format(ch)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
488 |
|
42597
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
489 def test_isidentifier(self): |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
490 self.assertTrue("a".isidentifier()) |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
491 self.assertTrue("Z".isidentifier()) |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
492 self.assertTrue("_".isidentifier()) |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
493 self.assertTrue("b0".isidentifier()) |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
494 self.assertTrue("bc".isidentifier()) |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
495 self.assertTrue("b_".isidentifier()) |
|
65661
e9e3fe4c9e30
Merged revisions 85861 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63941
diff
changeset
|
496 self.assertTrue("µ".isidentifier()) |
|
71848
787ed1a7aba8
in narrow builds, make sure to test codepoints as identifier characters (closes #12732)
Benjamin Peterson <benjamin@python.org>
parents:
71409
diff
changeset
|
497 self.assertTrue("𝔘𝔫𝔦𝔠𝔬𝔡𝔢".isidentifier()) |
|
42597
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
498 |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
499 self.assertFalse(" ".isidentifier()) |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
500 self.assertFalse("[".isidentifier()) |
|
65661
e9e3fe4c9e30
Merged revisions 85861 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63941
diff
changeset
|
501 self.assertFalse("©".isidentifier()) |
|
48427
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
502 self.assertFalse("0".isidentifier()) |
|
42597
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42324
diff
changeset
|
503 |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
504 def test_isprintable(self): |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
505 self.assertTrue("".isprintable()) |
|
52345
07b6fcdf7f94
fix isprintable() on space characters #5126
Benjamin Peterson <benjamin@python.org>
parents:
52159
diff
changeset
|
506 self.assertTrue(" ".isprintable()) |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
507 self.assertTrue("abcdefg".isprintable()) |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
508 self.assertFalse("abcdefg\n".isprintable()) |
|
48427
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
509 # some defined Unicode character |
|
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
510 self.assertTrue("\u0374".isprintable()) |
|
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
511 # undefined character |
|
49142
51ff934562c2
The Unicode database was updated to 5.1, and some characters have become printable.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49032
diff
changeset
|
512 self.assertFalse("\u0378".isprintable()) |
|
48427
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
513 # single surrogate character |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
514 self.assertFalse("\ud800".isprintable()) |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
515 |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
516 self.assertTrue('\U0001F46F'.isprintable()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
517 self.assertFalse('\U000E0020'.isprintable()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
518 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
519 def test_surrogates(self): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
520 for s in ('a\uD800b\uDFFF', 'a\uDFFFb\uD800', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
521 'a\uD800b\uDFFFa', 'a\uDFFFb\uD800a'): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
522 self.assertTrue(s.islower()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
523 self.assertFalse(s.isupper()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
524 self.assertFalse(s.istitle()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
525 for s in ('A\uD800B\uDFFF', 'A\uDFFFB\uD800', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
526 'A\uD800B\uDFFFA', 'A\uDFFFB\uD800A'): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
527 self.assertFalse(s.islower()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
528 self.assertTrue(s.isupper()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
529 self.assertTrue(s.istitle()) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
530 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
531 for meth_name in ('islower', 'isupper', 'istitle'): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
532 meth = getattr(str, meth_name) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
533 for s in ('\uD800', '\uDFFF', '\uD800\uD800', '\uDFFF\uDFFF'): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
534 self.assertFalse(meth(s), '%a.%s() is False' % (s, meth_name)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
535 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
536 for meth_name in ('isalpha', 'isalnum', 'isdigit', 'isspace', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
537 'isdecimal', 'isnumeric', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
538 'isidentifier', 'isprintable'): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
539 meth = getattr(str, meth_name) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
540 for s in ('\uD800', '\uDFFF', '\uD800\uD800', '\uDFFF\uDFFF', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
541 'a\uD800b\uDFFF', 'a\uDFFFb\uD800', |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
542 'a\uD800b\uDFFFa', 'a\uDFFFb\uD800a'): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
543 self.assertFalse(meth(s), '%a.%s() is False' % (s, meth_name)) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
544 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
545 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
546 def test_lower(self): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
547 string_tests.CommonTest.test_lower(self) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
548 self.assertEqual('\U00010427'.lower(), '\U0001044F') |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
549 self.assertEqual('\U00010427\U00010427'.lower(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
550 '\U0001044F\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
551 self.assertEqual('\U00010427\U0001044F'.lower(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
552 '\U0001044F\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
553 self.assertEqual('X\U00010427x\U0001044F'.lower(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
554 'x\U0001044Fx\U0001044F') |
|
74338
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
555 self.assertEqual('fi'.lower(), 'fi') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
556 self.assertEqual('\u0130'.lower(), '\u0069\u0307') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
557 # Special case for GREEK CAPITAL LETTER SIGMA U+03A3 |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
558 self.assertEqual('\u03a3'.lower(), '\u03c3') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
559 self.assertEqual('\u0345\u03a3'.lower(), '\u0345\u03c3') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
560 self.assertEqual('A\u0345\u03a3'.lower(), 'a\u0345\u03c2') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
561 self.assertEqual('A\u0345\u03a3a'.lower(), 'a\u0345\u03c3a') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
562 self.assertEqual('A\u0345\u03a3'.lower(), 'a\u0345\u03c2') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
563 self.assertEqual('A\u03a3\u0345'.lower(), 'a\u03c2\u0345') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
564 self.assertEqual('\u03a3\u0345 '.lower(), '\u03c3\u0345 ') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
565 self.assertEqual('\U0008fffe'.lower(), '\U0008fffe') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
566 self.assertEqual('\u2177'.lower(), '\u2177') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
567 |
|
74405
d4669f43d05f
add str.casefold() (closes #13752)
Benjamin Peterson <benjamin@python.org>
parents:
74338
diff
changeset
|
568 def test_casefold(self): |
|
d4669f43d05f
add str.casefold() (closes #13752)
Benjamin Peterson <benjamin@python.org>
parents:
74338
diff
changeset
|
569 self.assertEqual('hello'.casefold(), 'hello') |
|
d4669f43d05f
add str.casefold() (closes #13752)
Benjamin Peterson <benjamin@python.org>
parents:
74338
diff
changeset
|
570 self.assertEqual('hELlo'.casefold(), 'hello') |
|
d4669f43d05f
add str.casefold() (closes #13752)
Benjamin Peterson <benjamin@python.org>
parents:
74338
diff
changeset
|
571 self.assertEqual('ß'.casefold(), 'ss') |
|
d4669f43d05f
add str.casefold() (closes #13752)
Benjamin Peterson <benjamin@python.org>
parents:
74338
diff
changeset
|
572 self.assertEqual('fi'.casefold(), 'fi') |
|
d4669f43d05f
add str.casefold() (closes #13752)
Benjamin Peterson <benjamin@python.org>
parents:
74338
diff
changeset
|
573 self.assertEqual('\u03a3'.casefold(), '\u03c3') |
|
d4669f43d05f
add str.casefold() (closes #13752)
Benjamin Peterson <benjamin@python.org>
parents:
74338
diff
changeset
|
574 self.assertEqual('A\u0345\u03a3'.casefold(), 'a\u03b9\u03c3') |
|
78440
cde674716de4
add another testcase
Benjamin Peterson <benjamin@python.org>
parents:
76890
diff
changeset
|
575 self.assertEqual('\u00b5'.casefold(), '\u03bc') |
|
74405
d4669f43d05f
add str.casefold() (closes #13752)
Benjamin Peterson <benjamin@python.org>
parents:
74338
diff
changeset
|
576 |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
577 def test_upper(self): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
578 string_tests.CommonTest.test_upper(self) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
579 self.assertEqual('\U0001044F'.upper(), '\U00010427') |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
580 self.assertEqual('\U0001044F\U0001044F'.upper(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
581 '\U00010427\U00010427') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
582 self.assertEqual('\U00010427\U0001044F'.upper(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
583 '\U00010427\U00010427') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
584 self.assertEqual('X\U00010427x\U0001044F'.upper(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
585 'X\U00010427X\U00010427') |
|
74338
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
586 self.assertEqual('fi'.upper(), 'FI') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
587 self.assertEqual('\u0130'.upper(), '\u0130') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
588 self.assertEqual('\u03a3'.upper(), '\u03a3') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
589 self.assertEqual('ß'.upper(), 'SS') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
590 self.assertEqual('\u1fd2'.upper(), '\u0399\u0308\u0300') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
591 self.assertEqual('\U0008fffe'.upper(), '\U0008fffe') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
592 self.assertEqual('\u2177'.upper(), '\u2167') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
593 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
594 def test_capitalize(self): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
595 string_tests.CommonTest.test_capitalize(self) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
596 self.assertEqual('\U0001044F'.capitalize(), '\U00010427') |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
597 self.assertEqual('\U0001044F\U0001044F'.capitalize(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
598 '\U00010427\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
599 self.assertEqual('\U00010427\U0001044F'.capitalize(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
600 '\U00010427\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
601 self.assertEqual('\U0001044F\U00010427'.capitalize(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
602 '\U00010427\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
603 self.assertEqual('X\U00010427x\U0001044F'.capitalize(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
604 'X\U0001044Fx\U0001044F') |
|
74338
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
605 self.assertEqual('h\u0130'.capitalize(), 'H\u0069\u0307') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
606 exp = '\u0399\u0308\u0300\u0069\u0307' |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
607 self.assertEqual('\u1fd2\u0130'.capitalize(), exp) |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
608 self.assertEqual('finnish'.capitalize(), 'FInnish') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
609 self.assertEqual('A\u0345\u03a3'.capitalize(), 'A\u0345\u03c2') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
610 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
611 def test_title(self): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
612 string_tests.MixinStrUnicodeUserStringTest.test_title(self) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
613 self.assertEqual('\U0001044F'.title(), '\U00010427') |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
614 self.assertEqual('\U0001044F\U0001044F'.title(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
615 '\U00010427\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
616 self.assertEqual('\U0001044F\U0001044F \U0001044F\U0001044F'.title(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
617 '\U00010427\U0001044F \U00010427\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
618 self.assertEqual('\U00010427\U0001044F \U00010427\U0001044F'.title(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
619 '\U00010427\U0001044F \U00010427\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
620 self.assertEqual('\U0001044F\U00010427 \U0001044F\U00010427'.title(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
621 '\U00010427\U0001044F \U00010427\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
622 self.assertEqual('X\U00010427x\U0001044F X\U00010427x\U0001044F'.title(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
623 'X\U0001044Fx\U0001044F X\U0001044Fx\U0001044F') |
|
74338
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
624 self.assertEqual('fiNNISH'.title(), 'Finnish') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
625 self.assertEqual('A\u03a3 \u1fa1xy'.title(), 'A\u03c2 \u1fa9xy') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
626 self.assertEqual('A\u03a3A'.title(), 'A\u03c3a') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
627 |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
628 def test_swapcase(self): |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
629 string_tests.CommonTest.test_swapcase(self) |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
630 self.assertEqual('\U0001044F'.swapcase(), '\U00010427') |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
631 self.assertEqual('\U00010427'.swapcase(), '\U0001044F') |
|
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
632 self.assertEqual('\U0001044F\U0001044F'.swapcase(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
633 '\U00010427\U00010427') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
634 self.assertEqual('\U00010427\U0001044F'.swapcase(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
635 '\U0001044F\U00010427') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
636 self.assertEqual('\U0001044F\U00010427'.swapcase(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
637 '\U00010427\U0001044F') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
638 self.assertEqual('X\U00010427x\U0001044F'.swapcase(), |
|
72040
af952a67cee1
Fix indentation and add a skip decorator.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72035
diff
changeset
|
639 'x\U0001044FX\U00010427') |
|
74338
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
640 self.assertEqual('fi'.swapcase(), 'FI') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
641 self.assertEqual('\u0130'.swapcase(), '\u0069\u0307') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
642 # Special case for GREEK CAPITAL LETTER SIGMA U+03A3 |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
643 self.assertEqual('\u03a3'.swapcase(), '\u03c3') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
644 self.assertEqual('\u0345\u03a3'.swapcase(), '\u0399\u03c3') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
645 self.assertEqual('A\u0345\u03a3'.swapcase(), 'a\u0399\u03c2') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
646 self.assertEqual('A\u0345\u03a3a'.swapcase(), 'a\u0399\u03c3A') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
647 self.assertEqual('A\u0345\u03a3'.swapcase(), 'a\u0399\u03c2') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
648 self.assertEqual('A\u03a3\u0345'.swapcase(), 'a\u03c2\u0399') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
649 self.assertEqual('\u03a3\u0345 '.swapcase(), '\u03c3\u0399 ') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
650 self.assertEqual('\u03a3'.swapcase(), '\u03c3') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
651 self.assertEqual('ß'.swapcase(), 'SS') |
|
f7e05d205a52
use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents:
73741
diff
changeset
|
652 self.assertEqual('\u1fd2'.swapcase(), '\u0399\u0308\u0300') |
|
72035
06b30c5bcc3d
#9200: The str.is* methods now work with strings that contain non-BMP characters even in narrow Unicode builds.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71848
diff
changeset
|
653 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
654 def test_contains(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
655 # Testing Unicode contains method |
|
58415
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
656 self.assertIn('a', 'abdb') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
657 self.assertIn('a', 'bdab') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
658 self.assertIn('a', 'bdaba') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
659 self.assertIn('a', 'bdba') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
660 self.assertNotIn('a', 'bdb') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
661 self.assertIn('a', 'bdba') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
662 self.assertIn('a', ('a',1,None)) |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
663 self.assertIn('a', (1,None,'a')) |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
664 self.assertIn('a', ('a',1,None)) |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
665 self.assertIn('a', (1,None,'a')) |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
666 self.assertNotIn('a', ('x',1,'y')) |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
667 self.assertNotIn('a', ('x',1,None)) |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
668 self.assertNotIn('abcd', 'abcxxxx') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
669 self.assertIn('ab', 'abcd') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
670 self.assertIn('ab', 'abc') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
671 self.assertIn('ab', (1,None,'ab')) |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
672 self.assertIn('', 'abc') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
673 self.assertIn('', '') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
674 self.assertIn('', 'abc') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
675 self.assertNotIn('\0', 'abc') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
676 self.assertIn('\0', '\0abc') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
677 self.assertIn('\0', 'abc\0') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
678 self.assertIn('a', '\0abc') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
679 self.assertIn('asdf', 'asdf') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
680 self.assertNotIn('asdf', 'asd') |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
56099
diff
changeset
|
681 self.assertNotIn('asdf', '') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
682 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
683 self.assertRaises(TypeError, "abc".__contains__) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
684 |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
685 def test_format(self): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
686 self.assertEqual(''.format(), '') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
687 self.assertEqual('a'.format(), 'a') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
688 self.assertEqual('ab'.format(), 'ab') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
689 self.assertEqual('a{{'.format(), 'a{') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
690 self.assertEqual('a}}'.format(), 'a}') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
691 self.assertEqual('{{b'.format(), '{b') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
692 self.assertEqual('}}b'.format(), '}b') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
693 self.assertEqual('a{{b'.format(), 'a{b') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
694 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
695 # examples from the PEP: |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
696 import datetime |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
697 self.assertEqual("My name is {0}".format('Fred'), "My name is Fred") |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
698 self.assertEqual("My name is {0[name]}".format(dict(name='Fred')), |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
699 "My name is Fred") |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
700 self.assertEqual("My name is {0} :-{{}}".format('Fred'), |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
701 "My name is Fred :-{}") |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
702 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
703 d = datetime.date(2007, 8, 18) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
704 self.assertEqual("The year is {0.year}".format(d), |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
705 "The year is 2007") |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
706 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
707 # classes we'll use for testing |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
708 class C: |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
709 def __init__(self, x=100): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
710 self._x = x |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
711 def __format__(self, spec): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
712 return spec |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
713 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
714 class D: |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
715 def __init__(self, x): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
716 self.x = x |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
717 def __format__(self, spec): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
718 return str(self.x) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
719 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
720 # class with __str__, but no __format__ |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
721 class E: |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
722 def __init__(self, x): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
723 self.x = x |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
724 def __str__(self): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
725 return 'E(' + self.x + ')' |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
726 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
727 # class with __repr__, but no __format__ or __str__ |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
728 class F: |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
729 def __init__(self, x): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
730 self.x = x |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
731 def __repr__(self): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
732 return 'F(' + self.x + ')' |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
733 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
734 # class with __format__ that forwards to string, for some format_spec's |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
735 class G: |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
736 def __init__(self, x): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
737 self.x = x |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
738 def __str__(self): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
739 return "string is " + self.x |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
740 def __format__(self, format_spec): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
741 if format_spec == 'd': |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
742 return 'G(' + self.x + ')' |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
743 return object.__format__(self, format_spec) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
744 |
|
42909
7a62c2469dea
Additional test for formatting code.
Eric Smith <eric@trueblade.com>
parents:
42907
diff
changeset
|
745 class I(datetime.date): |
|
7a62c2469dea
Additional test for formatting code.
Eric Smith <eric@trueblade.com>
parents:
42907
diff
changeset
|
746 def __format__(self, format_spec): |
|
7a62c2469dea
Additional test for formatting code.
Eric Smith <eric@trueblade.com>
parents:
42907
diff
changeset
|
747 return self.strftime(format_spec) |
|
7a62c2469dea
Additional test for formatting code.
Eric Smith <eric@trueblade.com>
parents:
42907
diff
changeset
|
748 |
| 43097 | 749 class J(int): |
| 750 def __format__(self, format_spec): | |
| 751 return int.__format__(self * 2, format_spec) | |
| 752 | |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
753 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
754 self.assertEqual(''.format(), '') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
755 self.assertEqual('abc'.format(), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
756 self.assertEqual('{0}'.format('abc'), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
757 self.assertEqual('{0:}'.format('abc'), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
758 # self.assertEqual('{ 0 }'.format('abc'), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
759 self.assertEqual('X{0}'.format('abc'), 'Xabc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
760 self.assertEqual('{0}X'.format('abc'), 'abcX') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
761 self.assertEqual('X{0}Y'.format('abc'), 'XabcY') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
762 self.assertEqual('{1}'.format(1, 'abc'), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
763 self.assertEqual('X{1}'.format(1, 'abc'), 'Xabc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
764 self.assertEqual('{1}X'.format(1, 'abc'), 'abcX') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
765 self.assertEqual('X{1}Y'.format(1, 'abc'), 'XabcY') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
766 self.assertEqual('{0}'.format(-15), '-15') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
767 self.assertEqual('{0}{1}'.format(-15, 'abc'), '-15abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
768 self.assertEqual('{0}X{1}'.format(-15, 'abc'), '-15Xabc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
769 self.assertEqual('{{'.format(), '{') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
770 self.assertEqual('}}'.format(), '}') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
771 self.assertEqual('{{}}'.format(), '{}') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
772 self.assertEqual('{{x}}'.format(), '{x}') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
773 self.assertEqual('{{{0}}}'.format(123), '{123}') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
774 self.assertEqual('{{{{0}}}}'.format(), '{{0}}') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
775 self.assertEqual('}}{{'.format(), '}{') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
776 self.assertEqual('}}x{{'.format(), '}x{') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
777 |
|
42875
5fd65e250843
PEP 3101: Completed string.Formatter class. Reimplemented field_name to object transformation.
Eric Smith <eric@trueblade.com>
parents:
42817
diff
changeset
|
778 # weird field names |
|
5fd65e250843
PEP 3101: Completed string.Formatter class. Reimplemented field_name to object transformation.
Eric Smith <eric@trueblade.com>
parents:
42817
diff
changeset
|
779 self.assertEqual("{0[foo-bar]}".format({'foo-bar':'baz'}), 'baz') |
|
5fd65e250843
PEP 3101: Completed string.Formatter class. Reimplemented field_name to object transformation.
Eric Smith <eric@trueblade.com>
parents:
42817
diff
changeset
|
780 self.assertEqual("{0[foo bar]}".format({'foo bar':'baz'}), 'baz') |
|
43206
f4fb74f63806
Fix segfault discovered by Ron Adam. Not checking for terminating right bracket in "'{0[}'.format(())". Fixed, and tests added.
Eric Smith <eric@trueblade.com>
parents:
43172
diff
changeset
|
781 self.assertEqual("{0[ ]}".format({' ':3}), '3') |
|
42875
5fd65e250843
PEP 3101: Completed string.Formatter class. Reimplemented field_name to object transformation.
Eric Smith <eric@trueblade.com>
parents:
42817
diff
changeset
|
782 |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
783 self.assertEqual('{foo._x}'.format(foo=C(20)), '20') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
784 self.assertEqual('{1}{0}'.format(D(10), D(20)), '2010') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
785 self.assertEqual('{0._x.x}'.format(C(D('abc'))), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
786 self.assertEqual('{0[0]}'.format(['abc', 'def']), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
787 self.assertEqual('{0[1]}'.format(['abc', 'def']), 'def') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
788 self.assertEqual('{0[1][0]}'.format(['abc', ['def']]), 'def') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
789 self.assertEqual('{0[1][0].x}'.format(['abc', [D('def')]]), 'def') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
790 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
791 # strings |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
792 self.assertEqual('{0:.3s}'.format('abc'), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
793 self.assertEqual('{0:.3s}'.format('ab'), 'ab') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
794 self.assertEqual('{0:.3s}'.format('abcdef'), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
795 self.assertEqual('{0:.0s}'.format('abcdef'), '') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
796 self.assertEqual('{0:3.3s}'.format('abc'), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
797 self.assertEqual('{0:2.3s}'.format('abc'), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
798 self.assertEqual('{0:2.2s}'.format('abc'), 'ab') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
799 self.assertEqual('{0:3.2s}'.format('abc'), 'ab ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
800 self.assertEqual('{0:x<0s}'.format('result'), 'result') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
801 self.assertEqual('{0:x<5s}'.format('result'), 'result') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
802 self.assertEqual('{0:x<6s}'.format('result'), 'result') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
803 self.assertEqual('{0:x<7s}'.format('result'), 'resultx') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
804 self.assertEqual('{0:x<8s}'.format('result'), 'resultxx') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
805 self.assertEqual('{0: <7s}'.format('result'), 'result ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
806 self.assertEqual('{0:<7s}'.format('result'), 'result ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
807 self.assertEqual('{0:>7s}'.format('result'), ' result') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
808 self.assertEqual('{0:>8s}'.format('result'), ' result') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
809 self.assertEqual('{0:^8s}'.format('result'), ' result ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
810 self.assertEqual('{0:^9s}'.format('result'), ' result ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
811 self.assertEqual('{0:^10s}'.format('result'), ' result ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
812 self.assertEqual('{0:10000}'.format('a'), 'a' + ' ' * 9999) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
813 self.assertEqual('{0:10000}'.format(''), ' ' * 10000) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
814 self.assertEqual('{0:10000000}'.format(''), ' ' * 10000000) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
815 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
816 # format specifiers for user defined type |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
817 self.assertEqual('{0:abc}'.format(C()), 'abc') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
818 |
|
48427
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
819 # !r, !s and !a coercions |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
820 self.assertEqual('{0!s}'.format('Hello'), 'Hello') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
821 self.assertEqual('{0!s:}'.format('Hello'), 'Hello') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
822 self.assertEqual('{0!s:15}'.format('Hello'), 'Hello ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
823 self.assertEqual('{0!s:15s}'.format('Hello'), 'Hello ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
824 self.assertEqual('{0!r}'.format('Hello'), "'Hello'") |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
825 self.assertEqual('{0!r:}'.format('Hello'), "'Hello'") |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
826 self.assertEqual('{0!r}'.format(F('Hello')), 'F(Hello)') |
|
49142
51ff934562c2
The Unicode database was updated to 5.1, and some characters have become printable.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49032
diff
changeset
|
827 self.assertEqual('{0!r}'.format('\u0378'), "'\\u0378'") # nonprintable |
|
48427
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
828 self.assertEqual('{0!r}'.format('\u0374'), "'\u0374'") # printable |
|
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
829 self.assertEqual('{0!r}'.format(F('\u0374')), 'F(\u0374)') |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
830 self.assertEqual('{0!a}'.format('Hello'), "'Hello'") |
|
49142
51ff934562c2
The Unicode database was updated to 5.1, and some characters have become printable.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49032
diff
changeset
|
831 self.assertEqual('{0!a}'.format('\u0378'), "'\\u0378'") # nonprintable |
|
48427
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
832 self.assertEqual('{0!a}'.format('\u0374'), "'\\u0374'") # printable |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
833 self.assertEqual('{0!a:}'.format('Hello'), "'Hello'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
834 self.assertEqual('{0!a}'.format(F('Hello')), 'F(Hello)') |
|
48427
4e6859c6d38c
Issue #3282: str.isprintable() should return False for undefined Unicode characters.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
835 self.assertEqual('{0!a}'.format(F('\u0374')), 'F(\\u0374)') |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
836 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
837 # test fallback to object.__format__ |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
838 self.assertEqual('{0}'.format({}), '{}') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
839 self.assertEqual('{0}'.format([]), '[]') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
840 self.assertEqual('{0}'.format([1]), '[1]') |
|
64724
9f55faaa3193
Issue 7994: Make object.__format__() raise a PendingDeprecationWarning
Eric Smith <eric@trueblade.com>
parents:
64694
diff
changeset
|
841 |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
842 self.assertEqual('{0:d}'.format(G('data')), 'G(data)') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
843 self.assertEqual('{0!s}'.format(G('data')), 'string is data') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
844 |
|
64724
9f55faaa3193
Issue 7994: Make object.__format__() raise a PendingDeprecationWarning
Eric Smith <eric@trueblade.com>
parents:
64694
diff
changeset
|
845 msg = 'object.__format__ with a non-empty format string is deprecated' |
|
68399
ee259a4f3eee
Issue 9856: Change object.__format__ with a non-empty format string from a PendingDeprecationWarning to a DeprecationWarning.
Eric V. Smith <eric@trueblade.com>
parents:
68258
diff
changeset
|
846 with support.check_warnings((msg, DeprecationWarning)): |
|
64724
9f55faaa3193
Issue 7994: Make object.__format__() raise a PendingDeprecationWarning
Eric Smith <eric@trueblade.com>
parents:
64694
diff
changeset
|
847 self.assertEqual('{0:^10}'.format(E('data')), ' E(data) ') |
|
9f55faaa3193
Issue 7994: Make object.__format__() raise a PendingDeprecationWarning
Eric Smith <eric@trueblade.com>
parents:
64694
diff
changeset
|
848 self.assertEqual('{0:^10s}'.format(E('data')), ' E(data) ') |
|
9f55faaa3193
Issue 7994: Make object.__format__() raise a PendingDeprecationWarning
Eric Smith <eric@trueblade.com>
parents:
64694
diff
changeset
|
849 self.assertEqual('{0:>15s}'.format(G('data')), ' string is data') |
|
9f55faaa3193
Issue 7994: Make object.__format__() raise a PendingDeprecationWarning
Eric Smith <eric@trueblade.com>
parents:
64694
diff
changeset
|
850 |
|
42909
7a62c2469dea
Additional test for formatting code.
Eric Smith <eric@trueblade.com>
parents:
42907
diff
changeset
|
851 self.assertEqual("{0:date: %Y-%m-%d}".format(I(year=2007, |
|
7a62c2469dea
Additional test for formatting code.
Eric Smith <eric@trueblade.com>
parents:
42907
diff
changeset
|
852 month=8, |
|
7a62c2469dea
Additional test for formatting code.
Eric Smith <eric@trueblade.com>
parents:
42907
diff
changeset
|
853 day=27)), |
|
7a62c2469dea
Additional test for formatting code.
Eric Smith <eric@trueblade.com>
parents:
42907
diff
changeset
|
854 "date: 2007-08-27") |
|
7a62c2469dea
Additional test for formatting code.
Eric Smith <eric@trueblade.com>
parents:
42907
diff
changeset
|
855 |
| 43097 | 856 # test deriving from a builtin type and overriding __format__ |
| 857 self.assertEqual("{0}".format(J(10)), "20") | |
| 858 | |
| 859 | |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
860 # string format specifiers |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
861 self.assertEqual('{0:}'.format('a'), 'a') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
862 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
863 # computed format specifiers |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
864 self.assertEqual("{0:.{1}}".format('hello world', 5), 'hello') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
865 self.assertEqual("{0:.{1}s}".format('hello world', 5), 'hello') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
866 self.assertEqual("{0:.{precision}s}".format('hello world', precision=5), 'hello') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
867 self.assertEqual("{0:{width}.{precision}s}".format('hello world', width=10, precision=5), 'hello ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
868 self.assertEqual("{0:{width}.{precision}s}".format('hello world', width='10', precision='5'), 'hello ') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
869 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
870 # test various errors |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
871 self.assertRaises(ValueError, '{'.format) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
872 self.assertRaises(ValueError, '}'.format) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
873 self.assertRaises(ValueError, 'a{'.format) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
874 self.assertRaises(ValueError, 'a}'.format) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
875 self.assertRaises(ValueError, '{a'.format) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
876 self.assertRaises(ValueError, '}a'.format) |
|
43241
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
877 self.assertRaises(IndexError, '{0}'.format) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
878 self.assertRaises(IndexError, '{1}'.format, 'abc') |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
879 self.assertRaises(KeyError, '{x}'.format) |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
880 self.assertRaises(ValueError, "}{".format) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
881 self.assertRaises(ValueError, "abc{0:{}".format) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
882 self.assertRaises(ValueError, "{0".format) |
|
43241
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
883 self.assertRaises(IndexError, "{0.}".format) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
884 self.assertRaises(ValueError, "{0.}".format, 0) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
885 self.assertRaises(IndexError, "{0[}".format) |
|
43206
f4fb74f63806
Fix segfault discovered by Ron Adam. Not checking for terminating right bracket in "'{0[}'.format(())". Fixed, and tests added.
Eric Smith <eric@trueblade.com>
parents:
43172
diff
changeset
|
886 self.assertRaises(ValueError, "{0[}".format, []) |
|
43241
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
887 self.assertRaises(KeyError, "{0]}".format) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
888 self.assertRaises(ValueError, "{0.[]}".format, 0) |
|
42875
5fd65e250843
PEP 3101: Completed string.Formatter class. Reimplemented field_name to object transformation.
Eric Smith <eric@trueblade.com>
parents:
42817
diff
changeset
|
889 self.assertRaises(ValueError, "{0..foo}".format, 0) |
|
43241
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
890 self.assertRaises(ValueError, "{0[0}".format, 0) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
891 self.assertRaises(ValueError, "{0[0:foo}".format, 0) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
892 self.assertRaises(KeyError, "{c]}".format) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
893 self.assertRaises(ValueError, "{{ {{{0}}".format, 0) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
894 self.assertRaises(ValueError, "{0}}".format, 0) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
895 self.assertRaises(KeyError, "{foo}".format, bar=3) |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
896 self.assertRaises(ValueError, "{0!x}".format, 3) |
|
43241
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
897 self.assertRaises(ValueError, "{0!}".format, 0) |
|
e946073dee38
Changed some ValueError's to KeyError and IndexError.
Eric Smith <eric@trueblade.com>
parents:
43206
diff
changeset
|
898 self.assertRaises(ValueError, "{0!rs}".format, 0) |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
899 self.assertRaises(ValueError, "{!}".format) |
|
52159
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
900 self.assertRaises(IndexError, "{:}".format) |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
901 self.assertRaises(IndexError, "{:s}".format) |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
902 self.assertRaises(IndexError, "{}".format) |
|
62185
b5af5c93135b
Merged revisions 81823,81835 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
59899
diff
changeset
|
903 big = "23098475029384702983476098230754973209482573" |
|
b5af5c93135b
Merged revisions 81823,81835 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
59899
diff
changeset
|
904 self.assertRaises(ValueError, ("{" + big + "}").format) |
|
b5af5c93135b
Merged revisions 81823,81835 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
59899
diff
changeset
|
905 self.assertRaises(ValueError, ("{[" + big + "]}").format, [0]) |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
906 |
|
54269
2bcac08cfc6d
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
53965
diff
changeset
|
907 # issue 6089 |
|
2bcac08cfc6d
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
53965
diff
changeset
|
908 self.assertRaises(ValueError, "{0[0]x}".format, [None]) |
|
2bcac08cfc6d
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
53965
diff
changeset
|
909 self.assertRaises(ValueError, "{0[0](10)}".format, [None]) |
|
2bcac08cfc6d
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
53965
diff
changeset
|
910 |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
911 # can't have a replacement on the field name portion |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
912 self.assertRaises(TypeError, '{0[{1}]}'.format, 'abcdefg', 4) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
913 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
914 # exceed maximum recursion depth |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
915 self.assertRaises(ValueError, "{0:{1:{2}}}".format, 'abc', 's', '') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
916 self.assertRaises(ValueError, "{0:{1:{2:{3:{4:{5:{6}}}}}}}".format, |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
917 0, 1, 2, 3, 4, 5, 6, 7) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
918 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
919 # string format spec errors |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
920 self.assertRaises(ValueError, "{0:-s}".format, '') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
921 self.assertRaises(ValueError, format, "", "-") |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
922 self.assertRaises(ValueError, "{0:=s}".format, '') |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42597
diff
changeset
|
923 |
| 48472 | 924 # Alternate formatting is not supported |
| 925 self.assertRaises(ValueError, format, '', '#') | |
| 926 self.assertRaises(ValueError, format, '', '#20') | |
| 927 | |
|
76509
139c3ae84772
Close #14648: Compute correctly maxchar in str.format() for substrin
Victor Stinner <victor.stinner@gmail.com>
parents:
76484
diff
changeset
|
928 # Non-ASCII |
|
139c3ae84772
Close #14648: Compute correctly maxchar in str.format() for substrin
Victor Stinner <victor.stinner@gmail.com>
parents:
76484
diff
changeset
|
929 self.assertEqual("{0:s}{1:s}".format("ABC", "\u0410\u0411\u0412"), |
|
139c3ae84772
Close #14648: Compute correctly maxchar in str.format() for substrin
Victor Stinner <victor.stinner@gmail.com>
parents:
76484
diff
changeset
|
930 'ABC\u0410\u0411\u0412') |
|
139c3ae84772
Close #14648: Compute correctly maxchar in str.format() for substrin
Victor Stinner <victor.stinner@gmail.com>
parents:
76484
diff
changeset
|
931 self.assertEqual("{0:.3s}".format("ABC\u0410\u0411\u0412"), |
|
139c3ae84772
Close #14648: Compute correctly maxchar in str.format() for substrin
Victor Stinner <victor.stinner@gmail.com>
parents:
76484
diff
changeset
|
932 'ABC') |
|
139c3ae84772
Close #14648: Compute correctly maxchar in str.format() for substrin
Victor Stinner <victor.stinner@gmail.com>
parents:
76484
diff
changeset
|
933 self.assertEqual("{0:.0s}".format("ABC\u0410\u0411\u0412"), |
|
139c3ae84772
Close #14648: Compute correctly maxchar in str.format() for substrin
Victor Stinner <victor.stinner@gmail.com>
parents:
76484
diff
changeset
|
934 '') |
|
139c3ae84772
Close #14648: Compute correctly maxchar in str.format() for substrin
Victor Stinner <victor.stinner@gmail.com>
parents:
76484
diff
changeset
|
935 |
|
65940
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
936 def test_format_map(self): |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
937 self.assertEqual(''.format_map({}), '') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
938 self.assertEqual('a'.format_map({}), 'a') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
939 self.assertEqual('ab'.format_map({}), 'ab') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
940 self.assertEqual('a{{'.format_map({}), 'a{') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
941 self.assertEqual('a}}'.format_map({}), 'a}') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
942 self.assertEqual('{{b'.format_map({}), '{b') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
943 self.assertEqual('}}b'.format_map({}), '}b') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
944 self.assertEqual('a{{b'.format_map({}), 'a{b') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
945 |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
946 # using mappings |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
947 class Mapping(dict): |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
948 def __missing__(self, key): |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
949 return key |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
950 self.assertEqual('{hello}'.format_map(Mapping()), 'hello') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
951 self.assertEqual('{a} {world}'.format_map(Mapping(a='hello')), 'hello world') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
952 |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
953 class InternalMapping: |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
954 def __init__(self): |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
955 self.mapping = {'a': 'hello'} |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
956 def __getitem__(self, key): |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
957 return self.mapping[key] |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
958 self.assertEqual('{a}'.format_map(InternalMapping()), 'hello') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
959 |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
960 |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
961 class C: |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
962 def __init__(self, x=100): |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
963 self._x = x |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
964 def __format__(self, spec): |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
965 return spec |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
966 self.assertEqual('{foo._x}'.format_map({'foo': C(20)}), '20') |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
967 |
|
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
968 # test various errors |
|
75558
995cddd15313
str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes #13450.
Eric V. Smith <eric@trueblade.com>
parents:
73680
diff
changeset
|
969 self.assertRaises(TypeError, ''.format_map) |
|
995cddd15313
str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes #13450.
Eric V. Smith <eric@trueblade.com>
parents:
73680
diff
changeset
|
970 self.assertRaises(TypeError, 'a'.format_map) |
|
995cddd15313
str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes #13450.
Eric V. Smith <eric@trueblade.com>
parents:
73680
diff
changeset
|
971 |
|
995cddd15313
str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes #13450.
Eric V. Smith <eric@trueblade.com>
parents:
73680
diff
changeset
|
972 self.assertRaises(ValueError, '{'.format_map, {}) |
|
995cddd15313
str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes #13450.
Eric V. Smith <eric@trueblade.com>
parents:
73680
diff
changeset
|
973 self.assertRaises(ValueError, '}'.format_map, {}) |
|
995cddd15313
str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes #13450.
Eric V. Smith <eric@trueblade.com>
parents:
73680
diff
changeset
|
974 self.assertRaises(ValueError, 'a{'.format_map, {}) |
|
995cddd15313
str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes #13450.
Eric V. Smith <eric@trueblade.com>
parents:
73680
diff
changeset
|
975 self.assertRaises(ValueError, 'a}'.format_map, {}) |
|
995cddd15313
str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes #13450.
Eric V. Smith <eric@trueblade.com>
parents:
73680
diff
changeset
|
976 self.assertRaises(ValueError, '{a'.format_map, {}) |
|
995cddd15313
str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes #13450.
Eric V. Smith <eric@trueblade.com>
parents:
73680
diff
changeset
|
977 self.assertRaises(ValueError, '}a'.format_map, {}) |
|
65940
05eed9f0ce01
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
Eric Smith <eric@trueblade.com>
parents:
65660
diff
changeset
|
978 |
|
71409
f6d074a7bbd4
Closes #12579. Positional fields with str.format_map() now raise a ValueError instead of SystemError.
Eric V. Smith <eric@trueblade.com>
parents:
71181
diff
changeset
|
979 # issue #12579: can't supply positional params to format_map |
|
f6d074a7bbd4
Closes #12579. Positional fields with str.format_map() now raise a ValueError instead of SystemError.
Eric V. Smith <eric@trueblade.com>
parents:
71181
diff
changeset
|
980 self.assertRaises(ValueError, '{}'.format_map, {'a' : 2}) |
|
f6d074a7bbd4
Closes #12579. Positional fields with str.format_map() now raise a ValueError instead of SystemError.
Eric V. Smith <eric@trueblade.com>
parents:
71181
diff
changeset
|
981 self.assertRaises(ValueError, '{}'.format_map, 'a') |
|
f6d074a7bbd4
Closes #12579. Positional fields with str.format_map() now raise a ValueError instead of SystemError.
Eric V. Smith <eric@trueblade.com>
parents:
71181
diff
changeset
|
982 self.assertRaises(ValueError, '{a} {}'.format_map, {"a" : 2, "b" : 1}) |
|
f6d074a7bbd4
Closes #12579. Positional fields with str.format_map() now raise a ValueError instead of SystemError.
Eric V. Smith <eric@trueblade.com>
parents:
71181
diff
changeset
|
983 |
|
52159
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
984 def test_format_auto_numbering(self): |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
985 class C: |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
986 def __init__(self, x=100): |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
987 self._x = x |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
988 def __format__(self, spec): |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
989 return spec |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
990 |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
991 self.assertEqual('{}'.format(10), '10') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
992 self.assertEqual('{:5}'.format('s'), 's ') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
993 self.assertEqual('{!r}'.format('s'), "'s'") |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
994 self.assertEqual('{._x}'.format(C(10)), '10') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
995 self.assertEqual('{[1]}'.format([1, 2]), '2') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
996 self.assertEqual('{[a]}'.format({'a':4, 'b':2}), '4') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
997 self.assertEqual('a{}b{}c'.format(0, 1), 'a0b1c') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
998 |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
999 self.assertEqual('a{:{}}b'.format('x', '^10'), 'a x b') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1000 self.assertEqual('a{:{}x}b'.format(20, '#'), 'a0x14b') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1001 |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1002 # can't mix and match numbering and auto-numbering |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1003 self.assertRaises(ValueError, '{}{1}'.format, 1, 2) |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1004 self.assertRaises(ValueError, '{1}{}'.format, 1, 2) |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1005 self.assertRaises(ValueError, '{:{1}}'.format, 1, 2) |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1006 self.assertRaises(ValueError, '{0:{}}'.format, 1, 2) |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1007 |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1008 # can mix and match auto-numbering and named |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1009 self.assertEqual('{f}{}'.format(4, f='test'), 'test4') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1010 self.assertEqual('{}{f}'.format(4, f='test'), '4test') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1011 self.assertEqual('{:{f}}{g}{}'.format(1, 3, g='g', f=2), ' 1g3') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1012 self.assertEqual('{f:{}}{}{g}'.format(2, 4, f=1, g='g'), ' 14g') |
|
1c0a0f7b4f76
Merged revisions 70364 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49142
diff
changeset
|
1013 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1014 def test_formatting(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
1015 string_tests.MixinStrUnicodeUserStringTest.test_formatting(self) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1016 # Testing Unicode formatting strings... |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1017 self.assertEqual("%s, %s" % ("abc", "abc"), 'abc, abc') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1018 self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", 1, 2, 3), 'abc, abc, 1, 2.000000, 3.00') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1019 self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", 1, -2, 3), 'abc, abc, 1, -2.000000, 3.00') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1020 self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", -1, -2, 3.5), 'abc, abc, -1, -2.000000, 3.50') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1021 self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", -1, -2, 3.57), 'abc, abc, -1, -2.000000, 3.57') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1022 self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", -1, -2, 1003.57), 'abc, abc, -1, -2.000000, 1003.57') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1023 if not sys.platform.startswith('java'): |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1024 self.assertEqual("%r, %r" % (b"abc", "abc"), "b'abc', 'abc'") |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
1025 self.assertEqual("%r" % ("\u1234",), "'\u1234'") |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
1026 self.assertEqual("%a" % ("\u1234",), "'\\u1234'") |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1027 self.assertEqual("%(x)s, %(y)s" % {'x':"abc", 'y':"def"}, 'abc, def') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1028 self.assertEqual("%(x)s, %(\xfc)s" % {'x':"abc", '\xfc':"def"}, 'abc, def') |
|
28479
e13a7e1fdb9e
Remove duplicate test.
Walter Dörwald <walter@livinglogic.de>
parents:
28478
diff
changeset
|
1029 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1030 self.assertEqual('%c' % 0x1234, '\u1234') |
|
48430
04817793b962
Issue #3280: like chr() already does, the "%c" format now accepts the full unicode range
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48427
diff
changeset
|
1031 self.assertEqual('%c' % 0x21483, '\U00021483') |
|
04817793b962
Issue #3280: like chr() already does, the "%c" format now accepts the full unicode range
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48427
diff
changeset
|
1032 self.assertRaises(OverflowError, "%c".__mod__, (0x110000,)) |
|
04817793b962
Issue #3280: like chr() already does, the "%c" format now accepts the full unicode range
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48427
diff
changeset
|
1033 self.assertEqual('%c' % '\U00021483', '\U00021483') |
|
04817793b962
Issue #3280: like chr() already does, the "%c" format now accepts the full unicode range
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48427
diff
changeset
|
1034 self.assertRaises(TypeError, "%c".__mod__, "aa") |
|
63101
5cff058d6ced
Merged revisions 82978 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
62710
diff
changeset
|
1035 self.assertRaises(ValueError, "%.1\u1032f".__mod__, (1.0/3)) |
|
71181
97707459bb5a
Fix closes issue12471 - wrong TypeError message when '%i' format spec was used.
Senthil Kumaran <senthil@uthcode.com>
parents:
69564
diff
changeset
|
1036 self.assertRaises(TypeError, "%i".__mod__, "aa") |
|
20563
9058e49c6c57
Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents:
20240
diff
changeset
|
1037 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1038 # formatting jobs delegated from the string implementation: |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1039 self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1040 self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1041 self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1042 self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...') |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1043 self.assertEqual('...%(foo)s...' % {'foo':"abc",'def':123}, '...abc...') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1044 self.assertEqual('...%(foo)s...' % {'foo':"abc",'def':123}, '...abc...') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1045 self.assertEqual('...%s...%s...%s...%s...' % (1,2,3,"abc"), '...1...2...3...abc...') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1046 self.assertEqual('...%%...%%s...%s...%s...%s...%s...' % (1,2,3,"abc"), '...%...%s...1...2...3...abc...') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1047 self.assertEqual('...%s...' % "abc", '...abc...') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1048 self.assertEqual('%*s' % (5,'abc',), ' abc') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1049 self.assertEqual('%*s' % (-5,'abc',), 'abc ') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1050 self.assertEqual('%*.*s' % (5,2,'abc',), ' ab') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1051 self.assertEqual('%*.*s' % (5,3,'abc',), ' abc') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1052 self.assertEqual('%i %*.*s' % (10, 5,3,'abc',), '10 abc') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1053 self.assertEqual('%i%s %*.*s' % (10, 3, 5, 3, 'abc',), '103 abc') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1054 self.assertEqual('%c' % 'a', 'a') |
|
35331
ef11cbc08dab
Change the %s format specifier for str objects so that it returns a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
34931
diff
changeset
|
1055 class Wrapper: |
|
ef11cbc08dab
Change the %s format specifier for str objects so that it returns a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
34931
diff
changeset
|
1056 def __str__(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1057 return '\u1234' |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1058 self.assertEqual('%s' % Wrapper(), '\u1234') |
|
20563
9058e49c6c57
Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents:
20240
diff
changeset
|
1059 |
|
53849
04bdc944718a
Issue #3382. float 'F' formatting no longer maps to 'f'. This only affects nan and inf.
Eric Smith <eric@trueblade.com>
parents:
53742
diff
changeset
|
1060 # issue 3382 |
|
04bdc944718a
Issue #3382. float 'F' formatting no longer maps to 'f'. This only affects nan and inf.
Eric Smith <eric@trueblade.com>
parents:
53742
diff
changeset
|
1061 NAN = float('nan') |
|
04bdc944718a
Issue #3382. float 'F' formatting no longer maps to 'f'. This only affects nan and inf.
Eric Smith <eric@trueblade.com>
parents:
53742
diff
changeset
|
1062 INF = float('inf') |
|
04bdc944718a
Issue #3382. float 'F' formatting no longer maps to 'f'. This only affects nan and inf.
Eric Smith <eric@trueblade.com>
parents:
53742
diff
changeset
|
1063 self.assertEqual('%f' % NAN, 'nan') |
|
04bdc944718a
Issue #3382. float 'F' formatting no longer maps to 'f'. This only affects nan and inf.
Eric Smith <eric@trueblade.com>
parents:
53742
diff
changeset
|
1064 self.assertEqual('%F' % NAN, 'NAN') |
|
04bdc944718a
Issue #3382. float 'F' formatting no longer maps to 'f'. This only affects nan and inf.
Eric Smith <eric@trueblade.com>
parents:
53742
diff
changeset
|
1065 self.assertEqual('%f' % INF, 'inf') |
|
04bdc944718a
Issue #3382. float 'F' formatting no longer maps to 'f'. This only affects nan and inf.
Eric Smith <eric@trueblade.com>
parents:
53742
diff
changeset
|
1066 self.assertEqual('%F' % INF, 'INF') |
|
04bdc944718a
Issue #3382. float 'F' formatting no longer maps to 'f'. This only affects nan and inf.
Eric Smith <eric@trueblade.com>
parents:
53742
diff
changeset
|
1067 |
|
76841
6d39b5ea4542
unicode_writer_finish() checks string consistency
Victor Stinner <victor.stinner@gmail.com>
parents:
76509
diff
changeset
|
1068 # PEP 393 |
|
6d39b5ea4542
unicode_writer_finish() checks string consistency
Victor Stinner <victor.stinner@gmail.com>
parents:
76509
diff
changeset
|
1069 self.assertEqual('%.1s' % "a\xe9\u20ac", 'a') |
|
6d39b5ea4542
unicode_writer_finish() checks string consistency
Victor Stinner <victor.stinner@gmail.com>
parents:
76509
diff
changeset
|
1070 self.assertEqual('%.2s' % "a\xe9\u20ac", 'a\xe9') |
|
6d39b5ea4542
unicode_writer_finish() checks string consistency
Victor Stinner <victor.stinner@gmail.com>
parents:
76509
diff
changeset
|
1071 |
|
69563
bcbf8c3c4a88
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66340
diff
changeset
|
1072 def test_startswith_endswith_errors(self): |
|
bcbf8c3c4a88
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66340
diff
changeset
|
1073 for meth in ('foo'.startswith, 'foo'.endswith): |
| 69564 | 1074 with self.assertRaises(TypeError) as cm: |
|
69563
bcbf8c3c4a88
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66340
diff
changeset
|
1075 meth(['f']) |
| 69564 | 1076 exc = str(cm.exception) |
|
69563
bcbf8c3c4a88
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66340
diff
changeset
|
1077 self.assertIn('str', exc) |
|
bcbf8c3c4a88
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66340
diff
changeset
|
1078 self.assertIn('tuple', exc) |
|
bcbf8c3c4a88
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66340
diff
changeset
|
1079 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46307
diff
changeset
|
1080 @support.run_with_locale('LC_ALL', 'de_DE', 'fr_FR') |
|
36341
4bcf5fe54d83
Checkin the test of patch #1400181.
Georg Brandl <georg@python.org>
parents:
36056
diff
changeset
|
1081 def test_format_float(self): |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1082 # should not format with a comma, but always with C locale |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1083 self.assertEqual('1.0', '%.1f' % 1.0) |
|
36341
4bcf5fe54d83
Checkin the test of patch #1400181.
Georg Brandl <georg@python.org>
parents:
36056
diff
changeset
|
1084 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1085 def test_constructor(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1086 # unicode(obj) tests (this maps to PyObject_Unicode() at C level) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1087 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1088 self.assertEqual( |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1089 str('unicode remains unicode'), |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1090 'unicode remains unicode' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1091 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1092 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1093 class UnicodeSubclass(str): |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1094 pass |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
18828
diff
changeset
|
1095 |
|
72566
756001a37949
Optimize unicode_subtype_new(): don't encode to wchar_t and decode from wchar_t
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1096 for text in ('ascii', '\xe9', '\u20ac', '\U0010FFFF'): |
|
756001a37949
Optimize unicode_subtype_new(): don't encode to wchar_t and decode from wchar_t
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1097 subclass = UnicodeSubclass(text) |
|
756001a37949
Optimize unicode_subtype_new(): don't encode to wchar_t and decode from wchar_t
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1098 self.assertEqual(str(subclass), text) |
|
756001a37949
Optimize unicode_subtype_new(): don't encode to wchar_t and decode from wchar_t
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1099 self.assertEqual(len(subclass), len(text)) |
|
756001a37949
Optimize unicode_subtype_new(): don't encode to wchar_t and decode from wchar_t
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1100 if text == 'ascii': |
|
756001a37949
Optimize unicode_subtype_new(): don't encode to wchar_t and decode from wchar_t
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1101 self.assertEqual(subclass.encode('ascii'), b'ascii') |
|
756001a37949
Optimize unicode_subtype_new(): don't encode to wchar_t and decode from wchar_t
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72558
diff
changeset
|
1102 self.assertEqual(subclass.encode('utf-8'), b'ascii') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1103 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1104 self.assertEqual( |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1105 str('strings are converted to unicode'), |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1106 'strings are converted to unicode' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1107 ) |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
18828
diff
changeset
|
1108 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1109 class StringCompat: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1110 def __init__(self, x): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1111 self.x = x |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1112 def __str__(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1113 return self.x |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1114 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1115 self.assertEqual( |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1116 str(StringCompat('__str__ compatible objects are recognized')), |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1117 '__str__ compatible objects are recognized' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1118 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1119 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1120 # unicode(obj) is compatible to str(): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1121 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1122 o = StringCompat('unicode(obj) is compatible to str()') |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1123 self.assertEqual(str(o), 'unicode(obj) is compatible to str()') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1124 self.assertEqual(str(o), 'unicode(obj) is compatible to str()') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1125 |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
1126 for obj in (123, 123.45, 123): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1127 self.assertEqual(str(obj), str(str(obj))) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1128 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1129 # unicode(obj, encoding, error) tests (this maps to |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1130 # PyUnicode_FromEncodedObject() at C level) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1131 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1132 if not sys.platform.startswith('java'): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1133 self.assertRaises( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1134 TypeError, |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1135 str, |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1136 'decoding unicode is not supported', |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1137 'utf-8', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1138 'strict' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1139 ) |
|
21882
94bac88f150f
Fix for the UTF-8 memory allocation bug and the UTF-8 encoding
Marc-André Lemburg <mal@egenix.com>
parents:
21337
diff
changeset
|
1140 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1141 self.assertEqual( |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1142 str(b'strings are decoded to unicode', 'utf-8', 'strict'), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1143 'strings are decoded to unicode' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1144 ) |
|
13410
5157eb7be20d
Tests for new surrogate support in the UTF-8 codec. By Bill Tutt.
Marc-André Lemburg <mal@egenix.com>
parents:
13400
diff
changeset
|
1145 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1146 if not sys.platform.startswith('java'): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1147 self.assertEqual( |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1148 str( |
|
43487
8c10aac37037
Breaking ground for PEP 3137 implementation:
Guido van Rossum <guido@python.org>
parents:
43446
diff
changeset
|
1149 memoryview(b'character buffers are decoded to unicode'), |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1150 'utf-8', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1151 'strict' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1152 ), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1153 'character buffers are decoded to unicode' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1154 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1155 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1156 self.assertRaises(TypeError, str, 42, 42, 42) |
|
13410
5157eb7be20d
Tests for new surrogate support in the UTF-8 codec. By Bill Tutt.
Marc-André Lemburg <mal@egenix.com>
parents:
13400
diff
changeset
|
1157 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1158 def test_codecs_utf7(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1159 utfTests = [ |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1160 ('A\u2262\u0391.', b'A+ImIDkQ.'), # RFC2152 example |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1161 ('Hi Mom -\u263a-!', b'Hi Mom -+Jjo--!'), # RFC2152 example |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1162 ('\u65E5\u672C\u8A9E', b'+ZeVnLIqe-'), # RFC2152 example |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1163 ('Item 3 is \u00a31.', b'Item 3 is +AKM-1.'), # RFC2152 example |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1164 ('+', b'+-'), |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1165 ('+-', b'+--'), |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1166 ('+?', b'+-?'), |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1167 ('\?', b'+AFw?'), |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1168 ('+?', b'+-?'), |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1169 (r'\\?', b'+AFwAXA?'), |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1170 (r'\\\?', b'+AFwAXABc?'), |
|
53742
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1171 (r'++--', b'+-+---'), |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1172 ('\U000abcde', b'+2m/c3g-'), # surrogate pairs |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1173 ('/', b'/'), |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1174 ] |
| 12051 | 1175 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1176 for (x, y) in utfTests: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1177 self.assertEqual(x.encode('utf-7'), y) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1178 |
|
73552
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1179 # Unpaired surrogates are passed through |
|
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1180 self.assertEqual('\uD801'.encode('utf-7'), b'+2AE-') |
|
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1181 self.assertEqual('\uD801x'.encode('utf-7'), b'+2AE-x') |
|
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1182 self.assertEqual('\uDC01'.encode('utf-7'), b'+3AE-') |
|
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1183 self.assertEqual('\uDC01x'.encode('utf-7'), b'+3AE-x') |
|
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1184 self.assertEqual(b'+2AE-'.decode('utf-7'), '\uD801') |
|
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1185 self.assertEqual(b'+2AE-x'.decode('utf-7'), '\uD801x') |
|
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1186 self.assertEqual(b'+3AE-'.decode('utf-7'), '\uDC01') |
|
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1187 self.assertEqual(b'+3AE-x'.decode('utf-7'), '\uDC01x') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1188 |
|
73552
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1189 self.assertEqual('\uD801\U000abcde'.encode('utf-7'), b'+2AHab9ze-') |
|
ddfcb0de564f
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72813
diff
changeset
|
1190 self.assertEqual(b'+2AHab9ze-'.decode('utf-7'), '\uD801\U000abcde') |
| 12331 | 1191 |
|
48570
862c0eab1c50
Merged revisions 65227 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48472
diff
changeset
|
1192 # Issue #2242: crash on some Windows/MSVC versions |
|
53742
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1193 self.assertEqual(b'+\xc1'.decode('utf-7'), '\xc1') |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1194 |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1195 # Direct encoded characters |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1196 set_d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'(),-./:?" |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1197 # Optional direct characters |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1198 set_o = '!"#$%&*;<=>@[]^_`{|}' |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1199 for c in set_d: |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1200 self.assertEqual(c.encode('utf7'), c.encode('ascii')) |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1201 self.assertEqual(c.encode('ascii').decode('utf7'), c) |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1202 for c in set_o: |
|
9b9590007e82
Merged revisions 72283-72284 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53681
diff
changeset
|
1203 self.assertEqual(c.encode('ascii').decode('utf7'), c) |
|
48570
862c0eab1c50
Merged revisions 65227 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48472
diff
changeset
|
1204 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1205 def test_codecs_utf8(self): |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1206 self.assertEqual(''.encode('utf-8'), b'') |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1207 self.assertEqual('\u20ac'.encode('utf-8'), b'\xe2\x82\xac') |
|
72666
f39b26ca7f3d
#13054: fix usage of sys.maxunicode after PEP-393.
Ezio Melotti
parents:
72663
diff
changeset
|
1208 self.assertEqual('\U00010002'.encode('utf-8'), b'\xf0\x90\x80\x82') |
|
f39b26ca7f3d
#13054: fix usage of sys.maxunicode after PEP-393.
Ezio Melotti
parents:
72663
diff
changeset
|
1209 self.assertEqual('\U00023456'.encode('utf-8'), b'\xf0\xa3\x91\x96') |
|
53965
fbcdae3e0ca1
Rename the surrogates error handler to surrogatepass.
Martin v. Löwis <martin@v.loewis.de>
parents:
53849
diff
changeset
|
1210 self.assertEqual('\ud800'.encode('utf-8', 'surrogatepass'), b'\xed\xa0\x80') |
|
fbcdae3e0ca1
Rename the surrogates error handler to surrogatepass.
Martin v. Löwis <martin@v.loewis.de>
parents:
53849
diff
changeset
|
1211 self.assertEqual('\udc00'.encode('utf-8', 'surrogatepass'), b'\xed\xb0\x80') |
|
72666
f39b26ca7f3d
#13054: fix usage of sys.maxunicode after PEP-393.
Ezio Melotti
parents:
72663
diff
changeset
|
1212 self.assertEqual(('\U00010002'*10).encode('utf-8'), |
|
f39b26ca7f3d
#13054: fix usage of sys.maxunicode after PEP-393.
Ezio Melotti
parents:
72663
diff
changeset
|
1213 b'\xf0\x90\x80\x82'*10) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1214 self.assertEqual( |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1215 '\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f' |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1216 '\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00' |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1217 '\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c' |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1218 '\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067' |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1219 '\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das' |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1220 ' Nunstuck git und'.encode('utf-8'), |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1221 b'\xe6\xad\xa3\xe7\xa2\xba\xe3\x81\xab\xe8\xa8\x80\xe3\x81' |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1222 b'\x86\xe3\x81\xa8\xe7\xbf\xbb\xe8\xa8\xb3\xe3\x81\xaf\xe3' |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1223 b'\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x81\xbe' |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1224 b'\xe3\x81\x9b\xe3\x82\x93\xe3\x80\x82\xe4\xb8\x80\xe9\x83' |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1225 b'\xa8\xe3\x81\xaf\xe3\x83\x89\xe3\x82\xa4\xe3\x83\x84\xe8' |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1226 b'\xaa\x9e\xe3\x81\xa7\xe3\x81\x99\xe3\x81\x8c\xe3\x80\x81' |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1227 b'\xe3\x81\x82\xe3\x81\xa8\xe3\x81\xaf\xe3\x81\xa7\xe3\x81' |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1228 b'\x9f\xe3\x82\x89\xe3\x82\x81\xe3\x81\xa7\xe3\x81\x99\xe3' |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1229 b'\x80\x82\xe5\xae\x9f\xe9\x9a\x9b\xe3\x81\xab\xe3\x81\xaf' |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1230 b'\xe3\x80\x8cWenn ist das Nunstuck git und' |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1231 ) |
|
22423
b523a470a0ce
Do not insert characters for unicode-escape decoders if the error mode
Martin v. Löwis <martin@v.loewis.de>
parents:
21886
diff
changeset
|
1232 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1233 # UTF-8 specific decoding tests |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1234 self.assertEqual(str(b'\xf0\xa3\x91\x96', 'utf-8'), '\U00023456' ) |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1235 self.assertEqual(str(b'\xf0\x90\x80\x82', 'utf-8'), '\U00010002' ) |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1236 self.assertEqual(str(b'\xe2\x82\xac', 'utf-8'), '\u20ac' ) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1237 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1238 # Other possible utf-8 test cases: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1239 # * strict decoding testing for all of the |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1240 # UTF8_ERROR cases in PyUnicode_DecodeUTF8 |
| 12051 | 1241 |
|
62710
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1242 def test_utf8_decode_valid_sequences(self): |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1243 sequences = [ |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1244 # single byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1245 (b'\x00', '\x00'), (b'a', 'a'), (b'\x7f', '\x7f'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1246 # 2 bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1247 (b'\xc2\x80', '\x80'), (b'\xdf\xbf', '\u07ff'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1248 # 3 bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1249 (b'\xe0\xa0\x80', '\u0800'), (b'\xed\x9f\xbf', '\ud7ff'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1250 (b'\xee\x80\x80', '\uE000'), (b'\xef\xbf\xbf', '\uffff'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1251 # 4 bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1252 (b'\xF0\x90\x80\x80', '\U00010000'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1253 (b'\xf4\x8f\xbf\xbf', '\U0010FFFF') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1254 ] |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1255 for seq, res in sequences: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1256 self.assertEqual(seq.decode('utf-8'), res) |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1257 |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1258 |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1259 def test_utf8_decode_invalid_sequences(self): |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1260 # continuation bytes in a sequence of 2, 3, or 4 bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1261 continuation_bytes = [bytes([x]) for x in range(0x80, 0xC0)] |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1262 # start bytes of a 2-byte sequence equivalent to codepoints < 0x7F |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1263 invalid_2B_seq_start_bytes = [bytes([x]) for x in range(0xC0, 0xC2)] |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1264 # start bytes of a 4-byte sequence equivalent to codepoints > 0x10FFFF |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1265 invalid_4B_seq_start_bytes = [bytes([x]) for x in range(0xF5, 0xF8)] |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1266 invalid_start_bytes = ( |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1267 continuation_bytes + invalid_2B_seq_start_bytes + |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1268 invalid_4B_seq_start_bytes + [bytes([x]) for x in range(0xF7, 0x100)] |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1269 ) |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1270 |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1271 for byte in invalid_start_bytes: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1272 self.assertRaises(UnicodeDecodeError, byte.decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1273 |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1274 for sb in invalid_2B_seq_start_bytes: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1275 for cb in continuation_bytes: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1276 self.assertRaises(UnicodeDecodeError, (sb+cb).decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1277 |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1278 for sb in invalid_4B_seq_start_bytes: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1279 for cb1 in continuation_bytes[:3]: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1280 for cb3 in continuation_bytes[:3]: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1281 self.assertRaises(UnicodeDecodeError, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1282 (sb+cb1+b'\x80'+cb3).decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1283 |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1284 for cb in [bytes([x]) for x in range(0x80, 0xA0)]: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1285 self.assertRaises(UnicodeDecodeError, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1286 (b'\xE0'+cb+b'\x80').decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1287 self.assertRaises(UnicodeDecodeError, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1288 (b'\xE0'+cb+b'\xBF').decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1289 # surrogates |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1290 for cb in [bytes([x]) for x in range(0xA0, 0xC0)]: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1291 self.assertRaises(UnicodeDecodeError, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1292 (b'\xED'+cb+b'\x80').decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1293 self.assertRaises(UnicodeDecodeError, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1294 (b'\xED'+cb+b'\xBF').decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1295 for cb in [bytes([x]) for x in range(0x80, 0x90)]: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1296 self.assertRaises(UnicodeDecodeError, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1297 (b'\xF0'+cb+b'\x80\x80').decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1298 self.assertRaises(UnicodeDecodeError, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1299 (b'\xF0'+cb+b'\xBF\xBF').decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1300 for cb in [bytes([x]) for x in range(0x90, 0xC0)]: |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1301 self.assertRaises(UnicodeDecodeError, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1302 (b'\xF4'+cb+b'\x80\x80').decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1303 self.assertRaises(UnicodeDecodeError, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1304 (b'\xF4'+cb+b'\xBF\xBF').decode, 'utf-8') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1305 |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1306 def test_issue8271(self): |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1307 # Issue #8271: during the decoding of an invalid UTF-8 byte sequence, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1308 # only the start byte and the continuation byte(s) are now considered |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1309 # invalid, instead of the number of bytes specified by the start byte. |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1310 # See http://www.unicode.org/versions/Unicode5.2.0/ch03.pdf (page 95, |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1311 # table 3-8, Row 2) for more information about the algorithm used. |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1312 FFFD = '\ufffd' |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1313 sequences = [ |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1314 # invalid start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1315 (b'\x80', FFFD), # continuation byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1316 (b'\x80\x80', FFFD*2), # 2 continuation bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1317 (b'\xc0', FFFD), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1318 (b'\xc0\xc0', FFFD*2), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1319 (b'\xc1', FFFD), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1320 (b'\xc1\xc0', FFFD*2), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1321 (b'\xc0\xc1', FFFD*2), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1322 # with start byte of a 2-byte sequence |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1323 (b'\xc2', FFFD), # only the start byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1324 (b'\xc2\xc2', FFFD*2), # 2 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1325 (b'\xc2\xc2\xc2', FFFD*3), # 2 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1326 (b'\xc2\x41', FFFD+'A'), # invalid continuation byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1327 # with start byte of a 3-byte sequence |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1328 (b'\xe1', FFFD), # only the start byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1329 (b'\xe1\xe1', FFFD*2), # 2 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1330 (b'\xe1\xe1\xe1', FFFD*3), # 3 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1331 (b'\xe1\xe1\xe1\xe1', FFFD*4), # 4 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1332 (b'\xe1\x80', FFFD), # only 1 continuation byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1333 (b'\xe1\x41', FFFD+'A'), # invalid continuation byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1334 (b'\xe1\x41\x80', FFFD+'A'+FFFD), # invalid cb followed by valid cb |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1335 (b'\xe1\x41\x41', FFFD+'AA'), # 2 invalid continuation bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1336 (b'\xe1\x80\x41', FFFD+'A'), # only 1 valid continuation byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1337 (b'\xe1\x80\xe1\x41', FFFD*2+'A'), # 1 valid and the other invalid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1338 (b'\xe1\x41\xe1\x80', FFFD+'A'+FFFD), # 1 invalid and the other valid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1339 # with start byte of a 4-byte sequence |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1340 (b'\xf1', FFFD), # only the start byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1341 (b'\xf1\xf1', FFFD*2), # 2 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1342 (b'\xf1\xf1\xf1', FFFD*3), # 3 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1343 (b'\xf1\xf1\xf1\xf1', FFFD*4), # 4 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1344 (b'\xf1\xf1\xf1\xf1\xf1', FFFD*5), # 5 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1345 (b'\xf1\x80', FFFD), # only 1 continuation bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1346 (b'\xf1\x80\x80', FFFD), # only 2 continuation bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1347 (b'\xf1\x80\x41', FFFD+'A'), # 1 valid cb and 1 invalid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1348 (b'\xf1\x80\x41\x41', FFFD+'AA'), # 1 valid cb and 1 invalid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1349 (b'\xf1\x80\x80\x41', FFFD+'A'), # 2 valid cb and 1 invalid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1350 (b'\xf1\x41\x80', FFFD+'A'+FFFD), # 1 invalid cv and 1 valid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1351 (b'\xf1\x41\x80\x80', FFFD+'A'+FFFD*2), # 1 invalid cb and 2 invalid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1352 (b'\xf1\x41\x80\x41', FFFD+'A'+FFFD+'A'), # 2 invalid cb and 1 invalid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1353 (b'\xf1\x41\x41\x80', FFFD+'AA'+FFFD), # 1 valid cb and 1 invalid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1354 (b'\xf1\x41\xf1\x80', FFFD+'A'+FFFD), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1355 (b'\xf1\x41\x80\xf1', FFFD+'A'+FFFD*2), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1356 (b'\xf1\xf1\x80\x41', FFFD*2+'A'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1357 (b'\xf1\x41\xf1\xf1', FFFD+'A'+FFFD*2), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1358 # with invalid start byte of a 4-byte sequence (rfc2279) |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1359 (b'\xf5', FFFD), # only the start byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1360 (b'\xf5\xf5', FFFD*2), # 2 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1361 (b'\xf5\x80', FFFD*2), # only 1 continuation byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1362 (b'\xf5\x80\x80', FFFD*3), # only 2 continuation byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1363 (b'\xf5\x80\x80\x80', FFFD*4), # 3 continuation bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1364 (b'\xf5\x80\x41', FFFD*2+'A'), # 1 valid cb and 1 invalid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1365 (b'\xf5\x80\x41\xf5', FFFD*2+'A'+FFFD), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1366 (b'\xf5\x41\x80\x80\x41', FFFD+'A'+FFFD*2+'A'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1367 # with invalid start byte of a 5-byte sequence (rfc2279) |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1368 (b'\xf8', FFFD), # only the start byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1369 (b'\xf8\xf8', FFFD*2), # 2 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1370 (b'\xf8\x80', FFFD*2), # only one continuation byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1371 (b'\xf8\x80\x41', FFFD*2 + 'A'), # 1 valid cb and 1 invalid |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1372 (b'\xf8\x80\x80\x80\x80', FFFD*5), # invalid 5 bytes seq with 5 bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1373 # with invalid start byte of a 6-byte sequence (rfc2279) |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1374 (b'\xfc', FFFD), # only the start byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1375 (b'\xfc\xfc', FFFD*2), # 2 start bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1376 (b'\xfc\x80\x80', FFFD*3), # only 2 continuation bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1377 (b'\xfc\x80\x80\x80\x80\x80', FFFD*6), # 6 continuation bytes |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1378 # invalid start byte |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1379 (b'\xfe', FFFD), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1380 (b'\xfe\x80\x80', FFFD*3), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1381 # other sequences |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1382 (b'\xf1\x80\x41\x42\x43', '\ufffd\x41\x42\x43'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1383 (b'\xf1\x80\xff\x42\x43', '\ufffd\ufffd\x42\x43'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1384 (b'\xf1\x80\xc2\x81\x43', '\ufffd\x81\x43'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1385 (b'\x61\xF1\x80\x80\xE1\x80\xC2\x62\x80\x63\x80\xBF\x64', |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1386 '\x61\uFFFD\uFFFD\uFFFD\x62\uFFFD\x63\uFFFD\uFFFD\x64'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1387 ] |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1388 for n, (seq, res) in enumerate(sequences): |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1389 self.assertRaises(UnicodeDecodeError, seq.decode, 'utf-8', 'strict') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1390 self.assertEqual(seq.decode('utf-8', 'replace'), res) |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1391 self.assertEqual((seq+b'b').decode('utf-8', 'replace'), res+'b') |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1392 self.assertEqual(seq.decode('utf-8', 'ignore'), |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1393 res.replace('\uFFFD', '')) |
|
9dc5f385f494
Merged revisions 82413,82468 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62185
diff
changeset
|
1394 |
|
30059
200165d11a94
Support trailing dots in DNS names. Fixes #782510. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29164
diff
changeset
|
1395 def test_codecs_idna(self): |
|
200165d11a94
Support trailing dots in DNS names. Fixes #782510. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29164
diff
changeset
|
1396 # Test whether trailing dot is preserved |
|
41702
e06e196a05cf
There's no longer a u prefix for unicode objects
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
1397 self.assertEqual("www.python.org.".encode("idna"), b"www.python.org.") |
|
30059
200165d11a94
Support trailing dots in DNS names. Fixes #782510. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29164
diff
changeset
|
1398 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1399 def test_codecs_errors(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1400 # Error handling (encoding) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1401 self.assertRaises(UnicodeError, 'Andr\202 x'.encode, 'ascii') |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1402 self.assertRaises(UnicodeError, 'Andr\202 x'.encode, 'ascii','strict') |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1403 self.assertEqual('Andr\202 x'.encode('ascii','ignore'), b"Andr x") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1404 self.assertEqual('Andr\202 x'.encode('ascii','replace'), b"Andr? x") |
|
56099
1b7bdae02179
Merged revisions 74929 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
55593
diff
changeset
|
1405 self.assertEqual('Andr\202 x'.encode('ascii', 'replace'), |
|
1b7bdae02179
Merged revisions 74929 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
55593
diff
changeset
|
1406 'Andr\202 x'.encode('ascii', errors='replace')) |
|
1b7bdae02179
Merged revisions 74929 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
55593
diff
changeset
|
1407 self.assertEqual('Andr\202 x'.encode('ascii', 'ignore'), |
|
1b7bdae02179
Merged revisions 74929 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
55593
diff
changeset
|
1408 'Andr\202 x'.encode(encoding='ascii', errors='ignore')) |
| 12051 | 1409 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1410 # Error handling (decoding) |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1411 self.assertRaises(UnicodeError, str, b'Andr\202 x', 'ascii') |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1412 self.assertRaises(UnicodeError, str, b'Andr\202 x', 'ascii', 'strict') |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1413 self.assertEqual(str(b'Andr\202 x', 'ascii', 'ignore'), "Andr x") |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1414 self.assertEqual(str(b'Andr\202 x', 'ascii', 'replace'), 'Andr\uFFFD x') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1415 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1416 # Error handling (unknown character names) |
|
42902
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42875
diff
changeset
|
1417 self.assertEqual(b"\\N{foo}xx".decode("unicode-escape", "ignore"), "xx") |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1418 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1419 # Error handling (truncated escape sequence) |
|
42907
0170418dadea
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42902
diff
changeset
|
1420 self.assertRaises(UnicodeError, b"\\".decode, "unicode-escape") |
| 12051 | 1421 |
|
42907
0170418dadea
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42902
diff
changeset
|
1422 self.assertRaises(TypeError, b"hello".decode, "test.unicode1") |
|
0170418dadea
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42902
diff
changeset
|
1423 self.assertRaises(TypeError, str, b"hello", "test.unicode2") |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1424 self.assertRaises(TypeError, "hello".encode, "test.unicode1") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1425 self.assertRaises(TypeError, "hello".encode, "test.unicode2") |
|
21886
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21882
diff
changeset
|
1426 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1427 # Error handling (wrong arguments) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1428 self.assertRaises(TypeError, "hello".encode, 42, 42, 42) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1429 |
|
66673
7b6af56ee74d
Issue #10557: Fixed error messages from float() and other numeric
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66581
diff
changeset
|
1430 # Error handling (lone surrogate in PyUnicode_TransformDecimalToASCII()) |
|
7b6af56ee74d
Issue #10557: Fixed error messages from float() and other numeric
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66581
diff
changeset
|
1431 self.assertRaises(UnicodeError, int, "\ud800") |
|
7b6af56ee74d
Issue #10557: Fixed error messages from float() and other numeric
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66581
diff
changeset
|
1432 self.assertRaises(UnicodeError, int, "\udf00") |
|
7b6af56ee74d
Issue #10557: Fixed error messages from float() and other numeric
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66581
diff
changeset
|
1433 self.assertRaises(UnicodeError, float, "\ud800") |
|
7b6af56ee74d
Issue #10557: Fixed error messages from float() and other numeric
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66581
diff
changeset
|
1434 self.assertRaises(UnicodeError, float, "\udf00") |
|
7b6af56ee74d
Issue #10557: Fixed error messages from float() and other numeric
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66581
diff
changeset
|
1435 self.assertRaises(UnicodeError, complex, "\ud800") |
|
7b6af56ee74d
Issue #10557: Fixed error messages from float() and other numeric
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66581
diff
changeset
|
1436 self.assertRaises(UnicodeError, complex, "\udf00") |
|
21886
abedb2418f62
Fix to the UTF-8 encoder: it failed on 0-length input strings.
Marc-André Lemburg <mal@egenix.com>
parents:
21882
diff
changeset
|
1437 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1438 def test_codecs(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1439 # Encoding |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1440 self.assertEqual('hello'.encode('ascii'), b'hello') |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1441 self.assertEqual('hello'.encode('utf-7'), b'hello') |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1442 self.assertEqual('hello'.encode('utf-8'), b'hello') |
|
68142
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
68087
diff
changeset
|
1443 self.assertEqual('hello'.encode('utf-8'), b'hello') |
|
41620
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1444 self.assertEqual('hello'.encode('utf-16-le'), b'h\000e\000l\000l\000o\000') |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1445 self.assertEqual('hello'.encode('utf-16-be'), b'\000h\000e\000l\000l\000o') |
|
6b7d1782a574
test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents:
41592
diff
changeset
|
1446 self.assertEqual('hello'.encode('latin-1'), b'hello') |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
12074
diff
changeset
|
1447 |
|
68142
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
68087
diff
changeset
|
1448 # Default encoding is utf-8 |
|
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
68087
diff
changeset
|
1449 self.assertEqual('\u2603'.encode(), b'\xe2\x98\x83') |
|
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
68087
diff
changeset
|
1450 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1451 # Roundtrip safety for BMP (just the first 1024 chars) |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41620
diff
changeset
|
1452 for c in range(1024): |
|
41585
825d966338ea
Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents:
41575
diff
changeset
|
1453 u = chr(c) |
|
36056
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
1454 for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
1455 'utf-16-be', 'raw_unicode_escape', |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
1456 'unicode_escape', 'unicode_internal'): |
|
73579
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1457 with warnings.catch_warnings(): |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1458 # unicode-internal has been deprecated |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1459 warnings.simplefilter("ignore", DeprecationWarning) |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1460 |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1461 self.assertEqual(str(u.encode(encoding),encoding), u) |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
12074
diff
changeset
|
1462 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1463 # Roundtrip safety for BMP (just the first 256 chars) |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41620
diff
changeset
|
1464 for c in range(256): |
|
41585
825d966338ea
Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents:
41575
diff
changeset
|
1465 u = chr(c) |
|
36056
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
1466 for encoding in ('latin-1',): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1467 self.assertEqual(str(u.encode(encoding),encoding), u) |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
12074
diff
changeset
|
1468 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1469 # Roundtrip safety for BMP (just the first 128 chars) |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41620
diff
changeset
|
1470 for c in range(128): |
|
41585
825d966338ea
Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents:
41575
diff
changeset
|
1471 u = chr(c) |
|
36056
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
1472 for encoding in ('ascii',): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1473 self.assertEqual(str(u.encode(encoding),encoding), u) |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
15081
diff
changeset
|
1474 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1475 # Roundtrip safety for non-BMP (just a few chars) |
|
73579
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1476 with warnings.catch_warnings(): |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1477 # unicode-internal has been deprecated |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1478 warnings.simplefilter("ignore", DeprecationWarning) |
|
17815
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17655
diff
changeset
|
1479 |
|
73579
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1480 u = '\U00010001\U00020002\U00030003\U00040004\U00050005' |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1481 for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be', |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1482 'raw_unicode_escape', |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1483 'unicode_escape', 'unicode_internal'): |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73553
diff
changeset
|
1484 self.assertEqual(str(u.encode(encoding),encoding), u) |
|
17815
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17655
diff
changeset
|
1485 |
|
73497
bd5c4dda6ad0
Make test more inclusive
Antoine Pitrou <solipsis@pitrou.net>
parents:
73496
diff
changeset
|
1486 # UTF-8 must be roundtrip safe for all code points |
|
bd5c4dda6ad0
Make test more inclusive
Antoine Pitrou <solipsis@pitrou.net>
parents:
73496
diff
changeset
|
1487 # (except surrogates, which are forbidden). |
|
bd5c4dda6ad0
Make test more inclusive
Antoine Pitrou <solipsis@pitrou.net>
parents:
73496
diff
changeset
|
1488 u = ''.join(map(chr, list(range(0, 0xd800)) + |
| 73502 | 1489 list(range(0xe000, 0x110000)))) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1490 for encoding in ('utf-8',): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1491 self.assertEqual(str(u.encode(encoding),encoding), u) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1492 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1493 def test_codecs_charmap(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1494 # 0-127 |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41620
diff
changeset
|
1495 s = bytes(range(128)) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1496 for encoding in ( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1497 'cp037', 'cp1026', |
|
62572
1d1797af4622
Merged revisions 81499,81506 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
62171
diff
changeset
|
1498 'cp437', 'cp500', 'cp720', 'cp737', 'cp775', 'cp850', |
|
1d1797af4622
Merged revisions 81499,81506 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
62171
diff
changeset
|
1499 'cp852', 'cp855', 'cp858', 'cp860', 'cp861', 'cp862', |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1500 'cp863', 'cp865', 'cp866', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1501 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1502 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1503 'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1504 'mac_cyrillic', 'mac_latin2', |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
12074
diff
changeset
|
1505 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1506 'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1507 'cp1256', 'cp1257', 'cp1258', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1508 'cp856', 'cp857', 'cp864', 'cp869', 'cp874', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1509 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1510 'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1511 'cp1006', 'iso8859_8', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1512 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1513 ### These have undefined mappings: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1514 #'cp424', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1515 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1516 ### These fail the round-trip: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1517 #'cp875' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1518 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1519 ): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1520 self.assertEqual(str(s, encoding).encode(encoding), s) |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
15081
diff
changeset
|
1521 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1522 # 128-255 |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41620
diff
changeset
|
1523 s = bytes(range(128, 256)) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1524 for encoding in ( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1525 'cp037', 'cp1026', |
|
62572
1d1797af4622
Merged revisions 81499,81506 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
62171
diff
changeset
|
1526 'cp437', 'cp500', 'cp720', 'cp737', 'cp775', 'cp850', |
|
1d1797af4622
Merged revisions 81499,81506 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
62171
diff
changeset
|
1527 'cp852', 'cp855', 'cp858', 'cp860', 'cp861', 'cp862', |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1528 'cp863', 'cp865', 'cp866', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1529 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1530 'iso8859_2', 'iso8859_4', 'iso8859_5', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1531 'iso8859_9', 'koi8_r', 'latin_1', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1532 'mac_cyrillic', 'mac_latin2', |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
15081
diff
changeset
|
1533 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1534 ### These have undefined mappings: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1535 #'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1536 #'cp1256', 'cp1257', 'cp1258', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1537 #'cp424', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1538 #'iso8859_3', 'iso8859_6', 'iso8859_7', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1539 #'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish', |
|
12390
6edbae6dbcf5
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12365
diff
changeset
|
1540 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1541 ### These fail the round-trip: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1542 #'cp1006', 'cp875', 'iso8859_8', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1543 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1544 ): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1545 self.assertEqual(str(s, encoding).encode(encoding), s) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1546 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1547 def test_concatenation(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1548 self.assertEqual(("abc" "def"), "abcdef") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1549 self.assertEqual(("abc" "def"), "abcdef") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1550 self.assertEqual(("abc" "def"), "abcdef") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1551 self.assertEqual(("abc" "def" "ghi"), "abcdefghi") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1552 self.assertEqual(("abc" "def" "ghi"), "abcdefghi") |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20563
diff
changeset
|
1553 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1554 def test_printing(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1555 class BitBucket: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1556 def write(self, text): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1557 pass |
|
24598
12e146171f3d
Committing patch #591250 which provides "str1 in str2" when str1 is a
Barry Warsaw <barry@python.org>
parents:
24538
diff
changeset
|
1558 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1559 out = BitBucket() |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1560 print('abc', file=out) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1561 print('abc', 'def', file=out) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1562 print('abc', 'def', file=out) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1563 print('abc', 'def', file=out) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1564 print('abc\n', file=out) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1565 print('abc\n', end=' ', file=out) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1566 print('abc\n', end=' ', file=out) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1567 print('def\n', file=out) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1568 print('def\n', file=out) |
|
24598
12e146171f3d
Committing patch #591250 which provides "str1 in str2" when str1 is a
Barry Warsaw <barry@python.org>
parents:
24538
diff
changeset
|
1569 |
|
29164
4d9017ef7b5f
Consider \U-escapes in raw-unicode-escape. Fixes #444514.
Martin v. Löwis <martin@v.loewis.de>
parents:
28917
diff
changeset
|
1570 def test_ucs4(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1571 x = '\U00100000' |
|
29164
4d9017ef7b5f
Consider \U-escapes in raw-unicode-escape. Fixes #444514.
Martin v. Löwis <martin@v.loewis.de>
parents:
28917
diff
changeset
|
1572 y = x.encode("raw-unicode-escape").decode("raw-unicode-escape") |
|
4d9017ef7b5f
Consider \U-escapes in raw-unicode-escape. Fixes #444514.
Martin v. Löwis <martin@v.loewis.de>
parents:
28917
diff
changeset
|
1573 self.assertEqual(x, y) |
|
4d9017ef7b5f
Consider \U-escapes in raw-unicode-escape. Fixes #444514.
Martin v. Löwis <martin@v.loewis.de>
parents:
28917
diff
changeset
|
1574 |
|
64694
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1575 y = br'\U00100000' |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1576 x = y.decode("raw-unicode-escape").encode("raw-unicode-escape") |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1577 self.assertEqual(x, y) |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1578 y = br'\U00010000' |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1579 x = y.decode("raw-unicode-escape").encode("raw-unicode-escape") |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1580 self.assertEqual(x, y) |
|
46034
0a485593ae1c
Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
1581 |
|
64694
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1582 try: |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1583 br'\U11111111'.decode("raw-unicode-escape") |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1584 except UnicodeDecodeError as e: |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1585 self.assertEqual(e.start, 0) |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1586 self.assertEqual(e.end, 10) |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1587 else: |
|
1e89b5ee02f8
Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64666
diff
changeset
|
1588 self.fail("Should have raised UnicodeDecodeError") |
|
46034
0a485593ae1c
Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
1589 |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1590 def test_conversion(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1591 # Make sure __unicode__() works properly |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1592 class Foo0: |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1593 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1594 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1595 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1596 class Foo1: |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
1597 def __str__(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1598 return "foo" |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1599 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1600 class Foo2(object): |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
1601 def __str__(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1602 return "foo" |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1603 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1604 class Foo3(object): |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
1605 def __str__(self): |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1606 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1607 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1608 class Foo4(str): |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
1609 def __str__(self): |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1610 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1611 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1612 class Foo5(str): |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
1613 def __str__(self): |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1614 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1615 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1616 class Foo6(str): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1617 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1618 return "foos" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1619 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
1620 def __str__(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1621 return "foou" |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1622 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1623 class Foo7(str): |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1624 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1625 return "foos" |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
1626 def __str__(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1627 return "foou" |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1628 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1629 class Foo8(str): |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1630 def __new__(cls, content=""): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1631 return str.__new__(cls, 2*content) |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
1632 def __str__(self): |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1633 return self |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1634 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1635 class Foo9(str): |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1636 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1637 return "not unicode" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1638 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1639 self.assertEqual(str(Foo0()), "foo") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1640 self.assertEqual(str(Foo1()), "foo") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1641 self.assertEqual(str(Foo2()), "foo") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1642 self.assertEqual(str(Foo3()), "foo") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1643 self.assertEqual(str(Foo4("bar")), "foo") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1644 self.assertEqual(str(Foo5("bar")), "foo") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1645 self.assertEqual(str(Foo6("bar")), "foou") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1646 self.assertEqual(str(Foo7("bar")), "foou") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1647 self.assertEqual(str(Foo8("foo")), "foofoo") |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1648 self.assertEqual(str(Foo9("foo")), "not unicode") |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1649 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1650 def test_unicode_repr(self): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1651 class s1: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1652 def __repr__(self): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1653 return '\\n' |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1654 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1655 class s2: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1656 def __repr__(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1657 return '\\n' |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1658 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1659 self.assertEqual(repr(s1()), '\\n') |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1660 self.assertEqual(repr(s2()), '\\n') |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1661 |
|
64146
8f97c64b2333
#5127: Even on narrow unicode builds, the C functions that access the Unicode
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
63939
diff
changeset
|
1662 def test_printable_repr(self): |
|
8f97c64b2333
#5127: Even on narrow unicode builds, the C functions that access the Unicode
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
63939
diff
changeset
|
1663 self.assertEqual(repr('\U00010000'), "'%c'" % (0x10000,)) # printable |
|
65217
cbde81ef4af7
Upgrade to Unicode 6.0.0.
Martin v. Löwis <martin@v.loewis.de>
parents:
65059
diff
changeset
|
1664 self.assertEqual(repr('\U00014000'), "'\\U00014000'") # nonprintable |
|
64146
8f97c64b2333
#5127: Even on narrow unicode builds, the C functions that access the Unicode
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
63939
diff
changeset
|
1665 |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41702
diff
changeset
|
1666 def test_expandtabs_overflows_gracefully(self): |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41702
diff
changeset
|
1667 # This test only affects 32-bit platforms because expandtabs can only take |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41702
diff
changeset
|
1668 # an int as the max value, not a 64-bit C long. If expandtabs is changed |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41702
diff
changeset
|
1669 # to take a 64-bit long, this test should apply to all platforms. |
|
44160
9d152530910a
Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents:
44039
diff
changeset
|
1670 if sys.maxsize > (1 << 32) or struct.calcsize('P') != 4: |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41702
diff
changeset
|
1671 return |
|
44160
9d152530910a
Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents:
44039
diff
changeset
|
1672 self.assertRaises(OverflowError, 't\tt\t'.expandtabs, sys.maxsize) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36341
diff
changeset
|
1673 |
|
72788
e3d5b718f2e6
Mark 'abc'.expandtab() optimization as specific to CPython
Victor Stinner <vstinner@wyplay.com>
parents:
72784
diff
changeset
|
1674 @support.cpython_only |
|
72663
447f521ac6d9
When expandtabs() would be a no-op, don't create a duplicate string
Antoine Pitrou <solipsis@pitrou.net>
parents:
72566
diff
changeset
|
1675 def test_expandtabs_optimization(self): |
|
447f521ac6d9
When expandtabs() would be a no-op, don't create a duplicate string
Antoine Pitrou <solipsis@pitrou.net>
parents:
72566
diff
changeset
|
1676 s = 'abc' |
|
447f521ac6d9
When expandtabs() would be a no-op, don't create a duplicate string
Antoine Pitrou <solipsis@pitrou.net>
parents:
72566
diff
changeset
|
1677 self.assertIs(s.expandtabs(), s) |
|
447f521ac6d9
When expandtabs() would be a no-op, don't create a duplicate string
Antoine Pitrou <solipsis@pitrou.net>
parents:
72566
diff
changeset
|
1678 |
|
48601
a476ef5eebad
Merged revisions 65339-65340,65342 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48570
diff
changeset
|
1679 def test_raiseMemError(self): |
| 72475 | 1680 if struct.calcsize('P') == 8: |
| 1681 # 64 bits pointers | |
|
72480
f19af08eef02
Fix struct sizes. Drop -1, since the resulting string was actually the largest one
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
1682 ascii_struct_size = 48 |
|
f19af08eef02
Fix struct sizes. Drop -1, since the resulting string was actually the largest one
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
1683 compact_struct_size = 72 |
| 72475 | 1684 else: |
| 1685 # 32 bits pointers | |
|
72480
f19af08eef02
Fix struct sizes. Drop -1, since the resulting string was actually the largest one
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
1686 ascii_struct_size = 24 |
|
f19af08eef02
Fix struct sizes. Drop -1, since the resulting string was actually the largest one
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
1687 compact_struct_size = 36 |
| 72475 | 1688 |
| 1689 for char in ('a', '\xe9', '\u20ac', '\U0010ffff'): | |
| 1690 code = ord(char) | |
| 1691 if code < 0x100: | |
| 1692 char_size = 1 # sizeof(Py_UCS1) | |
| 1693 struct_size = ascii_struct_size | |
| 1694 elif code < 0x10000: | |
| 1695 char_size = 2 # sizeof(Py_UCS2) | |
| 1696 struct_size = compact_struct_size | |
| 1697 else: | |
| 1698 char_size = 4 # sizeof(Py_UCS4) | |
| 1699 struct_size = compact_struct_size | |
| 1700 # Note: sys.maxsize is half of the actual max allocation because of | |
|
72480
f19af08eef02
Fix struct sizes. Drop -1, since the resulting string was actually the largest one
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
1701 # the signedness of Py_ssize_t. Strings of maxlen-1 should in principle |
|
f19af08eef02
Fix struct sizes. Drop -1, since the resulting string was actually the largest one
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
1702 # be allocatable, given enough memory. |
|
f19af08eef02
Fix struct sizes. Drop -1, since the resulting string was actually the largest one
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
1703 maxlen = ((sys.maxsize - struct_size) // char_size) |
| 72475 | 1704 alloc = lambda: char * maxlen |
| 1705 self.assertRaises(MemoryError, alloc) | |
| 1706 self.assertRaises(MemoryError, alloc) | |
|
48723
1d88ad5f4def
Merged revisions 65773 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48601
diff
changeset
|
1707 |
|
59899
84405c22e4c7
Merged revisions 79281 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
1708 def test_format_subclass(self): |
|
84405c22e4c7
Merged revisions 79281 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
1709 class S(str): |
|
84405c22e4c7
Merged revisions 79281 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
1710 def __str__(self): |
|
84405c22e4c7
Merged revisions 79281 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
1711 return '__str__ overridden' |
|
84405c22e4c7
Merged revisions 79281 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
1712 s = S('xxx') |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65661
diff
changeset
|
1713 self.assertEqual("%s" % s, '__str__ overridden') |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65661
diff
changeset
|
1714 self.assertEqual("{}".format(s), '__str__ overridden') |
|
59899
84405c22e4c7
Merged revisions 79281 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
1715 |
|
67363
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1716 # Test PyUnicode_FromFormat() |
|
64639
1cfad55de5bd
Issue #9738: PyUnicode_FromFormat() and PyErr_Format() raise an error on
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64146
diff
changeset
|
1717 def test_from_format(self): |
|
67363
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1718 support.import_module('ctypes') |
|
79545
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1719 from ctypes import ( |
|
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1720 pythonapi, py_object, sizeof, |
|
68203
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1721 c_int, c_long, c_longlong, c_ssize_t, |
|
79545
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1722 c_uint, c_ulong, c_ulonglong, c_size_t, c_void_p) |
| 72475 | 1723 name = "PyUnicode_FromFormat" |
|
67363
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1724 _PyUnicode_FromFormat = getattr(pythonapi, name) |
|
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1725 _PyUnicode_FromFormat.restype = py_object |
|
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1726 |
|
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1727 def PyUnicode_FromFormat(format, *args): |
|
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1728 cargs = tuple( |
|
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1729 py_object(arg) if isinstance(arg, str) else arg |
|
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1730 for arg in args) |
|
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1731 return _PyUnicode_FromFormat(format, *cargs) |
|
64639
1cfad55de5bd
Issue #9738: PyUnicode_FromFormat() and PyErr_Format() raise an error on
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64146
diff
changeset
|
1732 |
|
1cfad55de5bd
Issue #9738: PyUnicode_FromFormat() and PyErr_Format() raise an error on
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64146
diff
changeset
|
1733 # ascii format, non-ascii argument |
|
67363
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1734 text = PyUnicode_FromFormat(b'ascii\x7f=%U', 'unicode\xe9') |
|
64639
1cfad55de5bd
Issue #9738: PyUnicode_FromFormat() and PyErr_Format() raise an error on
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64146
diff
changeset
|
1735 self.assertEqual(text, 'ascii\x7f=unicode\xe9') |
|
1cfad55de5bd
Issue #9738: PyUnicode_FromFormat() and PyErr_Format() raise an error on
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64146
diff
changeset
|
1736 |
|
67363
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1737 # non-ascii format, ascii argument: ensure that PyUnicode_FromFormatV() |
|
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1738 # raises an error |
|
66581
38bec90fd8ab
#10273: Rename assertRegexpMatches and assertRaisesRegexp to assertRegex and assertRaisesRegex.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66402
diff
changeset
|
1739 self.assertRaisesRegex(ValueError, |
|
64639
1cfad55de5bd
Issue #9738: PyUnicode_FromFormat() and PyErr_Format() raise an error on
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64146
diff
changeset
|
1740 '^PyUnicode_FromFormatV\(\) expects an ASCII-encoded format ' |
|
64666
852bb052156a
Issue #9738, #9836: Fix refleak introduced by r84704
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64639
diff
changeset
|
1741 'string, got a non-ASCII byte: 0xe9$', |
|
67363
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1742 PyUnicode_FromFormat, b'unicode\xe9=%s', 'ascii') |
|
48601
a476ef5eebad
Merged revisions 65339-65340,65342 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48570
diff
changeset
|
1743 |
|
68201
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1744 # test "%c" |
|
68087
ef28aad3bbae
Fix PyUnicode_FromFormatV("%c") for non-BMP char
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67791
diff
changeset
|
1745 self.assertEqual(PyUnicode_FromFormat(b'%c', c_int(0xabcd)), '\uabcd') |
|
ef28aad3bbae
Fix PyUnicode_FromFormatV("%c") for non-BMP char
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67791
diff
changeset
|
1746 self.assertEqual(PyUnicode_FromFormat(b'%c', c_int(0x10ffff)), '\U0010ffff') |
|
ef28aad3bbae
Fix PyUnicode_FromFormatV("%c") for non-BMP char
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67791
diff
changeset
|
1747 |
|
68201
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1748 # test "%" |
|
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1749 self.assertEqual(PyUnicode_FromFormat(b'%'), '%') |
|
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1750 self.assertEqual(PyUnicode_FromFormat(b'%%'), '%') |
|
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1751 self.assertEqual(PyUnicode_FromFormat(b'%%s'), '%s') |
|
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1752 self.assertEqual(PyUnicode_FromFormat(b'[%%]'), '[%]') |
|
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1753 self.assertEqual(PyUnicode_FromFormat(b'%%%s', b'abc'), '%abc') |
|
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1754 |
|
68203
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1755 # test integer formats (%i, %d, %u) |
|
68201
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1756 self.assertEqual(PyUnicode_FromFormat(b'%03i', c_int(10)), '010') |
|
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1757 self.assertEqual(PyUnicode_FromFormat(b'%0.4i', c_int(10)), '0010') |
|
68203
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1758 self.assertEqual(PyUnicode_FromFormat(b'%i', c_int(-123)), '-123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1759 self.assertEqual(PyUnicode_FromFormat(b'%li', c_long(-123)), '-123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1760 self.assertEqual(PyUnicode_FromFormat(b'%lli', c_longlong(-123)), '-123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1761 self.assertEqual(PyUnicode_FromFormat(b'%zi', c_ssize_t(-123)), '-123') |
|
68201
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1762 |
|
68203
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1763 self.assertEqual(PyUnicode_FromFormat(b'%d', c_int(-123)), '-123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1764 self.assertEqual(PyUnicode_FromFormat(b'%ld', c_long(-123)), '-123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1765 self.assertEqual(PyUnicode_FromFormat(b'%lld', c_longlong(-123)), '-123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1766 self.assertEqual(PyUnicode_FromFormat(b'%zd', c_ssize_t(-123)), '-123') |
|
68201
da95440d92b3
Issue #10829: Refactor PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68198
diff
changeset
|
1767 |
|
68203
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1768 self.assertEqual(PyUnicode_FromFormat(b'%u', c_uint(123)), '123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1769 self.assertEqual(PyUnicode_FromFormat(b'%lu', c_ulong(123)), '123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1770 self.assertEqual(PyUnicode_FromFormat(b'%llu', c_ulonglong(123)), '123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1771 self.assertEqual(PyUnicode_FromFormat(b'%zu', c_size_t(123)), '123') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1772 |
|
79545
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1773 # test long output |
|
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1774 min_longlong = -(2 ** (8 * sizeof(c_longlong) - 1)) |
|
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1775 max_longlong = -min_longlong - 1 |
|
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1776 self.assertEqual(PyUnicode_FromFormat(b'%lld', c_longlong(min_longlong)), str(min_longlong)) |
|
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1777 self.assertEqual(PyUnicode_FromFormat(b'%lld', c_longlong(max_longlong)), str(max_longlong)) |
|
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1778 max_ulonglong = 2 ** (8 * sizeof(c_ulonglong)) - 1 |
|
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1779 self.assertEqual(PyUnicode_FromFormat(b'%llu', c_ulonglong(max_ulonglong)), str(max_ulonglong)) |
|
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1780 PyUnicode_FromFormat(b'%p', c_void_p(-1)) |
|
e16ec3b468d1
Issue #16147: PyUnicode_FromFormatV() doesn't need anymore to allocate a buffer
Victor Stinner <victor.stinner@gmail.com>
parents:
79542
diff
changeset
|
1781 |
|
79542
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1782 # test padding (width and/or precision) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1783 self.assertEqual(PyUnicode_FromFormat(b'%010i', c_int(123)), '123'.rjust(10, '0')) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1784 self.assertEqual(PyUnicode_FromFormat(b'%100i', c_int(123)), '123'.rjust(100)) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1785 self.assertEqual(PyUnicode_FromFormat(b'%.100i', c_int(123)), '123'.rjust(100, '0')) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1786 self.assertEqual(PyUnicode_FromFormat(b'%100.80i', c_int(123)), '123'.rjust(80, '0').rjust(100)) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1787 |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1788 self.assertEqual(PyUnicode_FromFormat(b'%010u', c_uint(123)), '123'.rjust(10, '0')) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1789 self.assertEqual(PyUnicode_FromFormat(b'%100u', c_uint(123)), '123'.rjust(100)) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1790 self.assertEqual(PyUnicode_FromFormat(b'%.100u', c_uint(123)), '123'.rjust(100, '0')) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1791 self.assertEqual(PyUnicode_FromFormat(b'%100.80u', c_uint(123)), '123'.rjust(80, '0').rjust(100)) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1792 |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1793 self.assertEqual(PyUnicode_FromFormat(b'%010x', c_int(0x123)), '123'.rjust(10, '0')) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1794 self.assertEqual(PyUnicode_FromFormat(b'%100x', c_int(0x123)), '123'.rjust(100)) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1795 self.assertEqual(PyUnicode_FromFormat(b'%.100x', c_int(0x123)), '123'.rjust(100, '0')) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1796 self.assertEqual(PyUnicode_FromFormat(b'%100.80x', c_int(0x123)), '123'.rjust(80, '0').rjust(100)) |
|
b4bee17625e1
Issue #16147: Rewrite PyUnicode_FromFormatV() to use _PyUnicodeWriter API
Victor Stinner <victor.stinner@gmail.com>
parents:
78440
diff
changeset
|
1797 |
|
68203
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1798 # test %A |
|
67363
dd3f28ffd029
test_unicode: use ctypes to test PyUnicode_FromFormat()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66673
diff
changeset
|
1799 text = PyUnicode_FromFormat(b'%%A:%A', 'abc\xe9\uabcd\U0010ffff') |
|
65530
3faff7e51f40
PyUnicode_FromFormatV(): Fix %A format
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65217
diff
changeset
|
1800 self.assertEqual(text, r"%A:'abc\xe9\uabcd\U0010ffff'") |
|
3faff7e51f40
PyUnicode_FromFormatV(): Fix %A format
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65217
diff
changeset
|
1801 |
|
68203
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1802 # test %V |
|
68058
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1803 text = PyUnicode_FromFormat(b'repr=%V', 'abc', b'xyz') |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1804 self.assertEqual(text, 'repr=abc') |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1805 |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1806 # Test string decode from parameter of %s using utf-8. |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1807 # b'\xe4\xba\xba\xe6\xb0\x91' is utf-8 encoded byte sequence of |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1808 # '\u4eba\u6c11' |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1809 text = PyUnicode_FromFormat(b'repr=%V', None, b'\xe4\xba\xba\xe6\xb0\x91') |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1810 self.assertEqual(text, 'repr=\u4eba\u6c11') |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1811 |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1812 #Test replace error handler. |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1813 text = PyUnicode_FromFormat(b'repr=%V', None, b'abc\xff') |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1814 self.assertEqual(text, 'repr=abc\ufffd') |
|
72f30f8ef331
Merged revisions 88697 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68087
diff
changeset
|
1815 |
|
68203
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1816 # not supported: copy the raw format string. these tests are just here |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1817 # to check for crashs and should not be considered as specifications |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1818 self.assertEqual(PyUnicode_FromFormat(b'%1%s', b'abc'), '%s') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1819 self.assertEqual(PyUnicode_FromFormat(b'%1abc'), '%1abc') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1820 self.assertEqual(PyUnicode_FromFormat(b'%+i', c_int(10)), '%+i') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1821 self.assertEqual(PyUnicode_FromFormat(b'%.%s', b'abc'), '%.%s') |
|
87de017da4bf
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68201
diff
changeset
|
1822 |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1823 # Test PyUnicode_AsWideChar() |
|
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1824 def test_aswidechar(self): |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1825 from _testcapi import unicode_aswidechar |
|
66402
127f5168a774
Fix tests when ctypes isn't available
Antoine Pitrou <solipsis@pitrou.net>
parents:
66310
diff
changeset
|
1826 support.import_module('ctypes') |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1827 from ctypes import c_wchar, sizeof |
|
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1828 |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1829 wchar, size = unicode_aswidechar('abcdef', 2) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1830 self.assertEqual(size, 2) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1831 self.assertEqual(wchar, 'ab') |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1832 |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1833 wchar, size = unicode_aswidechar('abc', 3) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1834 self.assertEqual(size, 3) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1835 self.assertEqual(wchar, 'abc') |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1836 |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1837 wchar, size = unicode_aswidechar('abc', 4) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1838 self.assertEqual(size, 3) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1839 self.assertEqual(wchar, 'abc\0') |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1840 |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1841 wchar, size = unicode_aswidechar('abc', 10) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1842 self.assertEqual(size, 3) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1843 self.assertEqual(wchar, 'abc\0') |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1844 |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1845 wchar, size = unicode_aswidechar('abc\0def', 20) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1846 self.assertEqual(size, 7) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1847 self.assertEqual(wchar, 'abc\0def\0') |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1848 |
|
65056
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1849 nonbmp = chr(0x10ffff) |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1850 if sizeof(c_wchar) == 2: |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1851 buflen = 3 |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1852 nchar = 2 |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1853 else: # sizeof(c_wchar) == 4 |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1854 buflen = 2 |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1855 nchar = 1 |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1856 wchar, size = unicode_aswidechar(nonbmp, buflen) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1857 self.assertEqual(size, nchar) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1858 self.assertEqual(wchar, nonbmp + '\0') |
|
65056
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1859 |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1860 # Test PyUnicode_AsWideCharString() |
|
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1861 def test_aswidecharstring(self): |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1862 from _testcapi import unicode_aswidecharstring |
|
66402
127f5168a774
Fix tests when ctypes isn't available
Antoine Pitrou <solipsis@pitrou.net>
parents:
66310
diff
changeset
|
1863 support.import_module('ctypes') |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1864 from ctypes import c_wchar, sizeof |
|
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1865 |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1866 wchar, size = unicode_aswidecharstring('abc') |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1867 self.assertEqual(size, 3) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1868 self.assertEqual(wchar, 'abc\0') |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1869 |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1870 wchar, size = unicode_aswidecharstring('abc\0def') |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1871 self.assertEqual(size, 7) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1872 self.assertEqual(wchar, 'abc\0def\0') |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1873 |
|
65056
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1874 nonbmp = chr(0x10ffff) |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1875 if sizeof(c_wchar) == 2: |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1876 nchar = 2 |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1877 else: # sizeof(c_wchar) == 4 |
|
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1878 nchar = 1 |
|
65059
8de535def122
Issue #8670: Rename testcapi unicode test methods
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65058
diff
changeset
|
1879 wchar, size = unicode_aswidecharstring(nonbmp) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1880 self.assertEqual(size, nchar) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66033
diff
changeset
|
1881 self.assertEqual(wchar, nonbmp + '\0') |
|
65056
0cc3ff8020ae
Issue #8670: PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() replace
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65055
diff
changeset
|
1882 |
|
72558
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1883 def test_subclass_add(self): |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1884 class S(str): |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1885 def __add__(self, o): |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1886 return "3" |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1887 self.assertEqual(S("4") + S("5"), "3") |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1888 class S(str): |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1889 def __iadd__(self, o): |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1890 return "3" |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1891 s = S("1") |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1892 s += "4" |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1893 self.assertEqual(s, "3") |
|
6da962d77eb3
remove "fast-path" for (i)adding strings
Benjamin Peterson <benjamin@python.org>
parents:
72480
diff
changeset
|
1894 |
|
73671
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1895 def test_encode_decimal(self): |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1896 from _testcapi import unicode_encodedecimal |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1897 self.assertEqual(unicode_encodedecimal('123'), |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1898 b'123') |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1899 self.assertEqual(unicode_encodedecimal('\u0663.\u0661\u0664'), |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1900 b'3.14') |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1901 self.assertEqual(unicode_encodedecimal("\N{EM SPACE}3.14\N{EN SPACE}"), |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1902 b' 3.14 ') |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1903 self.assertRaises(UnicodeEncodeError, |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1904 unicode_encodedecimal, "123\u20ac", "strict") |
|
73741
a20fae95618c
Close #13093: PyUnicode_EncodeDecimal() doesn't support error handlers
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73692
diff
changeset
|
1905 self.assertRaisesRegex( |
|
a20fae95618c
Close #13093: PyUnicode_EncodeDecimal() doesn't support error handlers
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73692
diff
changeset
|
1906 ValueError, |
|
a20fae95618c
Close #13093: PyUnicode_EncodeDecimal() doesn't support error handlers
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73692
diff
changeset
|
1907 "^'decimal' codec can't encode character", |
|
a20fae95618c
Close #13093: PyUnicode_EncodeDecimal() doesn't support error handlers
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73692
diff
changeset
|
1908 unicode_encodedecimal, "123\u20ac", "replace") |
|
73671
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1909 |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1910 def test_transform_decimal(self): |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1911 from _testcapi import unicode_transformdecimaltoascii as transform_decimal |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1912 self.assertEqual(transform_decimal('123'), |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1913 '123') |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1914 self.assertEqual(transform_decimal('\u0663.\u0661\u0664'), |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1915 '3.14') |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1916 self.assertEqual(transform_decimal("\N{EM SPACE}3.14\N{EN SPACE}"), |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1917 "\N{EM SPACE}3.14\N{EN SPACE}") |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1918 self.assertEqual(transform_decimal('123\u20ac'), |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1919 '123\u20ac') |
|
849e9277906a
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73579
diff
changeset
|
1920 |
|
73676
5d5133f518cb
Add a test on str.__getnewargs__()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73671
diff
changeset
|
1921 def test_getnewargs(self): |
|
5d5133f518cb
Add a test on str.__getnewargs__()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73671
diff
changeset
|
1922 text = 'abc' |
|
5d5133f518cb
Add a test on str.__getnewargs__()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73671
diff
changeset
|
1923 args = text.__getnewargs__() |
|
5d5133f518cb
Add a test on str.__getnewargs__()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73671
diff
changeset
|
1924 self.assertIsNot(args[0], text) |
|
5d5133f518cb
Add a test on str.__getnewargs__()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73671
diff
changeset
|
1925 self.assertEqual(args[0], text) |
|
5d5133f518cb
Add a test on str.__getnewargs__()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73671
diff
changeset
|
1926 self.assertEqual(len(args), 1) |
|
5d5133f518cb
Add a test on str.__getnewargs__()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73671
diff
changeset
|
1927 |
|
65055
de7cdb726350
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
Victor Stinner <victor.stinner@haypocalc.com>
parents:
64724
diff
changeset
|
1928 |
|
67791
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1929 class StringModuleTest(unittest.TestCase): |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1930 def test_formatter_parser(self): |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1931 def parse(format): |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1932 return list(_string.formatter_parser(format)) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1933 |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1934 formatter = parse("prefix {2!s}xxx{0:^+10.3f}{obj.attr!s} {z[0]!s:10}") |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1935 self.assertEqual(formatter, [ |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1936 ('prefix ', '2', '', 's'), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1937 ('xxx', '0', '^+10.3f', None), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1938 ('', 'obj.attr', '', 's'), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1939 (' ', 'z[0]', '10', 's'), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1940 ]) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1941 |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1942 formatter = parse("prefix {} suffix") |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1943 self.assertEqual(formatter, [ |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1944 ('prefix ', '', '', None), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1945 (' suffix', None, None, None), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1946 ]) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1947 |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1948 formatter = parse("str") |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1949 self.assertEqual(formatter, [ |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1950 ('str', None, None, None), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1951 ]) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1952 |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1953 formatter = parse("") |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1954 self.assertEqual(formatter, []) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1955 |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1956 formatter = parse("{0}") |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1957 self.assertEqual(formatter, [ |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1958 ('', '0', '', None), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1959 ]) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1960 |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1961 self.assertRaises(TypeError, _string.formatter_parser, 1) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1962 |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1963 def test_formatter_field_name_split(self): |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1964 def split(name): |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1965 items = list(_string.formatter_field_name_split(name)) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1966 items[1] = list(items[1]) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1967 return items |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1968 self.assertEqual(split("obj"), ["obj", []]) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1969 self.assertEqual(split("obj.arg"), ["obj", [(True, 'arg')]]) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1970 self.assertEqual(split("obj[key]"), ["obj", [(False, 'key')]]) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1971 self.assertEqual(split("obj.arg[key1][key2]"), [ |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1972 "obj", |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1973 [(True, 'arg'), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1974 (False, 'key1'), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1975 (False, 'key2'), |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1976 ]]) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1977 self.assertRaises(TypeError, _string.formatter_field_name_split, 1) |
|
3ef865327d7b
Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash.
Eric Smith <eric@trueblade.com>
parents:
67363
diff
changeset
|
1978 |
|
48601
a476ef5eebad
Merged revisions 65339-65340,65342 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48570
diff
changeset
|
1979 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1980 def test_main(): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46307
diff
changeset
|
1981 support.run_unittest(__name__) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1982 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1983 if __name__ == "__main__": |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1984 test_main() |
