Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_unicode.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | d2d028f65c7c |
| children | 7780482a64da |
| rev | line source |
|---|---|
|
24538
8d5e0e3f6445
Add encoding declaration.
Martin v. Löwis <martin@v.loewis.de>
parents:
24364
diff
changeset
|
1 # -*- coding: iso-8859-1 -*- |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 """ Test script for the Unicode implementation. |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 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
|
5 |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 (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
|
7 |
|
15957
c1a8deb15f0e
This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents:
15910
diff
changeset
|
8 """#" |
|
45468
1d84bf5f9478
Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents:
45391
diff
changeset
|
9 import sys, struct, codecs |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
10 from test import test_support, string_tests |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
11 |
|
35938
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
12 # 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
|
13 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
|
14 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
|
15 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
|
16 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
|
17 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 else: |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
27 return None |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
28 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
|
29 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
30 class UnicodeTest( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
31 string_tests.CommonTest, |
|
33298
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
32 string_tests.MixinStrUnicodeUserStringTest, |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
33 string_tests.MixinStrUnicodeTest, |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
34 ): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
35 type2test = unicode |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
36 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 self.assertEqual(realresult, result) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
41 self.assert_(type(realresult) is type(result)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
42 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
43 # 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
|
44 # 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
|
45 if realresult is object: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
46 class usub(unicode): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
47 def __repr__(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
48 return 'usub(%r)' % unicode.__repr__(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 self.assertEqual(realresult, result) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
53 self.assert_(object is not realresult) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 |
|
30653
3b47d6057151
Fix for SF bug [ 817156 ] invalid \U escape gives 0=length unistr.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30059
diff
changeset
|
55 def test_literals(self): |
|
3b47d6057151
Fix for SF bug [ 817156 ] invalid \U escape gives 0=length unistr.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30059
diff
changeset
|
56 self.assertEqual(u'\xff', u'\u00ff') |
|
3b47d6057151
Fix for SF bug [ 817156 ] invalid \U escape gives 0=length unistr.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30059
diff
changeset
|
57 self.assertEqual(u'\uffff', u'\U0000ffff') |
|
42310
4c658377b908
Fix failing unicode test caused by change to ast.c at r56441
Kurt B. Kaiser <kbk@shore.net>
parents:
42023
diff
changeset
|
58 self.assertRaises(SyntaxError, eval, 'u\'\\Ufffffffe\'') |
|
4c658377b908
Fix failing unicode test caused by change to ast.c at r56441
Kurt B. Kaiser <kbk@shore.net>
parents:
42023
diff
changeset
|
59 self.assertRaises(SyntaxError, eval, 'u\'\\Uffffffff\'') |
|
4c658377b908
Fix failing unicode test caused by change to ast.c at r56441
Kurt B. Kaiser <kbk@shore.net>
parents:
42023
diff
changeset
|
60 self.assertRaises(SyntaxError, eval, 'u\'\\U%08x\'' % 0x110000) |
|
30653
3b47d6057151
Fix for SF bug [ 817156 ] invalid \U escape gives 0=length unistr.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30059
diff
changeset
|
61 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
62 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
|
63 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
|
64 # Test basic sanity of repr() |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
65 self.assertEqual(repr(u'abc'), "u'abc'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
66 self.assertEqual(repr(u'ab\\c'), "u'ab\\\\c'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
67 self.assertEqual(repr(u'ab\\'), "u'ab\\\\'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
68 self.assertEqual(repr(u'\\c'), "u'\\\\c'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
69 self.assertEqual(repr(u'\\'), "u'\\\\'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
70 self.assertEqual(repr(u'\n'), "u'\\n'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
71 self.assertEqual(repr(u'\r'), "u'\\r'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
72 self.assertEqual(repr(u'\t'), "u'\\t'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
73 self.assertEqual(repr(u'\b'), "u'\\x08'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
74 self.assertEqual(repr(u"'\""), """u'\\'"'""") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
75 self.assertEqual(repr(u"'\""), """u'\\'"'""") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
76 self.assertEqual(repr(u"'"), '''u"'"''') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
77 self.assertEqual(repr(u'"'), """u'"'""") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
78 latin1repr = ( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
79 "u'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
80 "\\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
|
81 "\\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
|
82 "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
|
83 "\\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
|
84 "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
85 "\\x9c\\x9d\\x9e\\x9f\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
86 "\\xaa\\xab\\xac\\xad\\xae\\xaf\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
87 "\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
88 "\\xc6\\xc7\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\\xd0\\xd1\\xd2\\xd3" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
89 "\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\\xe0\\xe1" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
90 "\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
91 "\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd" |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
92 "\\xfe\\xff'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
93 testrepr = repr(u''.join(map(unichr, xrange(256)))) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
94 self.assertEqual(testrepr, latin1repr) |
|
39621
e8a65bbd6a29
Patch #1541585: fix buffer overrun when performing repr() on
Neal Norwitz <nnorwitz@gmail.com>
parents:
38096
diff
changeset
|
95 # Test repr works on wide unicode escapes without overflow. |
|
e8a65bbd6a29
Patch #1541585: fix buffer overrun when performing repr() on
Neal Norwitz <nnorwitz@gmail.com>
parents:
38096
diff
changeset
|
96 self.assertEqual(repr(u"\U00010000" * 39 + u"\uffff" * 4096), |
|
e8a65bbd6a29
Patch #1541585: fix buffer overrun when performing repr() on
Neal Norwitz <nnorwitz@gmail.com>
parents:
38096
diff
changeset
|
97 repr(u"\U00010000" * 39 + u"\uffff" * 4096)) |
|
e8a65bbd6a29
Patch #1541585: fix buffer overrun when performing repr() on
Neal Norwitz <nnorwitz@gmail.com>
parents:
38096
diff
changeset
|
98 |
|
20017
08446a986a56
Test basic functioning of unicode repr(). (If this breaks Jython,
Guido van Rossum <guido@python.org>
parents:
19999
diff
changeset
|
99 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
100 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
|
101 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
|
102 # check mixed argument types |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
103 self.checkequalnofix(3, 'aaa', 'count', u'a') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
104 self.checkequalnofix(0, 'aaa', 'count', u'b') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
105 self.checkequalnofix(3, u'aaa', 'count', 'a') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
106 self.checkequalnofix(0, u'aaa', 'count', 'b') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
107 self.checkequalnofix(0, u'aaa', 'count', 'b') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
108 self.checkequalnofix(1, u'aaa', 'count', 'a', -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
109 self.checkequalnofix(3, u'aaa', 'count', 'a', -10) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
110 self.checkequalnofix(2, u'aaa', 'count', 'a', 0, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
111 self.checkequalnofix(0, u'aaa', 'count', 'a', 0, -10) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
113 def test_find(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
114 self.checkequalnofix(0, u'abcdefghiabc', 'find', u'abc') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
115 self.checkequalnofix(9, u'abcdefghiabc', 'find', u'abc', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
116 self.checkequalnofix(-1, u'abcdefghiabc', 'find', u'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
|
117 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
118 self.assertRaises(TypeError, u'hello'.find) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
119 self.assertRaises(TypeError, u'hello'.find, 42) |
|
15910
f7f3be3d00b9
Added checks to prevent PyUnicode_Count() from dumping core
Marc-André Lemburg <mal@egenix.com>
parents:
15706
diff
changeset
|
120 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
121 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
|
122 string_tests.CommonTest.test_rfind(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
123 # check mixed argument types |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
124 self.checkequalnofix(9, 'abcdefghiabc', 'rfind', u'abc') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
125 self.checkequalnofix(12, 'abcdefghiabc', 'rfind', u'') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
126 self.checkequalnofix(12, u'abcdefghiabc', 'rfind', '') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
128 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
|
129 string_tests.CommonTest.test_index(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
130 # check mixed argument types |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
131 for (t1, t2) in ((str, unicode), (unicode, str)): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
132 self.checkequalnofix(0, t1('abcdefghiabc'), 'index', t2('')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
133 self.checkequalnofix(3, t1('abcdefghiabc'), 'index', t2('def')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
134 self.checkequalnofix(0, t1('abcdefghiabc'), 'index', t2('abc')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
135 self.checkequalnofix(9, t1('abcdefghiabc'), 'index', t2('abc'), 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
136 self.assertRaises(ValueError, t1('abcdefghiabc').index, t2('hib')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
137 self.assertRaises(ValueError, t1('abcdefghiab').index, t2('abc'), 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
138 self.assertRaises(ValueError, t1('abcdefghi').index, t2('ghi'), 8) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
139 self.assertRaises(ValueError, t1('abcdefghi').index, t2('ghi'), -1) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
141 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
|
142 string_tests.CommonTest.test_rindex(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
143 # check mixed argument types |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
144 for (t1, t2) in ((str, unicode), (unicode, str)): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
145 self.checkequalnofix(12, t1('abcdefghiabc'), 'rindex', t2('')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
146 self.checkequalnofix(3, t1('abcdefghiabc'), 'rindex', t2('def')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
147 self.checkequalnofix(9, t1('abcdefghiabc'), 'rindex', t2('abc')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
148 self.checkequalnofix(0, t1('abcdefghiabc'), 'rindex', t2('abc'), 0, -1) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
150 self.assertRaises(ValueError, t1('abcdefghiabc').rindex, t2('hib')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
151 self.assertRaises(ValueError, t1('defghiabc').rindex, t2('def'), 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
152 self.assertRaises(ValueError, t1('defghiabc').rindex, t2('abc'), 0, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
153 self.assertRaises(ValueError, t1('abcdefghi').rindex, t2('ghi'), 0, 8) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
154 self.assertRaises(ValueError, t1('abcdefghi').rindex, t2('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
|
155 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
156 def test_translate(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
157 self.checkequalnofix(u'bbbc', u'abababc', 'translate', {ord('a'):None}) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
158 self.checkequalnofix(u'iiic', u'abababc', 'translate', {ord('a'):None, ord('b'):ord('i')}) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
159 self.checkequalnofix(u'iiix', u'abababc', 'translate', {ord('a'):None, ord('b'):ord('i'), ord('c'):u'x'}) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
160 self.checkequalnofix(u'<i><i><i>c', u'abababc', 'translate', {ord('a'):None, ord('b'):u'<i>'}) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
161 self.checkequalnofix(u'c', u'abababc', 'translate', {ord('a'):None, ord('b'):u''}) |
|
31455
37d501b9e2d5
Fix reallocation bug in unicode.translate(): The code was comparing
Walter Dörwald <walter@livinglogic.de>
parents:
30653
diff
changeset
|
162 self.checkequalnofix(u'xyyx', u'xzx', 'translate', {ord('z'):u'yy'}) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
163 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
164 self.assertRaises(TypeError, u'hello'.translate) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
165 self.assertRaises(TypeError, u'abababc'.translate, {ord('a'):''}) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
167 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
|
168 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
|
169 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
170 # Mixed arguments |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
171 self.checkequalnofix([u'a', u'b', u'c', u'd'], u'a//b//c//d', 'split', '//') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
172 self.checkequalnofix([u'a', u'b', u'c', u'd'], 'a//b//c//d', 'split', u'//') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
173 self.checkequalnofix([u'endcase ', u''], u'endcase test', 'split', 'test') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
175 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
|
176 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
|
177 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
178 # mixed arguments |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
179 self.checkequalnofix(u'a b c d', u' ', 'join', ['a', 'b', u'c', u'd']) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
180 self.checkequalnofix(u'abcd', u'', 'join', (u'a', u'b', u'c', u'd')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
181 self.checkequalnofix(u'w x y z', u' ', 'join', string_tests.Sequence('wxyz')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
182 self.checkequalnofix(u'a b c d', ' ', 'join', [u'a', u'b', u'c', u'd']) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
183 self.checkequalnofix(u'a b c d', ' ', 'join', ['a', 'b', u'c', u'd']) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
184 self.checkequalnofix(u'abcd', '', 'join', (u'a', u'b', u'c', u'd')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
185 self.checkequalnofix(u'w x y z', ' ', 'join', string_tests.Sequence(u'wxyz')) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
187 def test_strip(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
188 string_tests.CommonTest.test_strip(self) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
189 self.assertRaises(UnicodeError, u"hello".strip, "\xff") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
190 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
191 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
|
192 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
|
193 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
194 # method call forwarded from str implementation because of unicode argument |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
195 self.checkequalnofix(u'one@two!three!', 'one!two!three!', 'replace', u'!', u'@', 1) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
196 self.assertRaises(TypeError, 'replace'.replace, u"r", 42) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
198 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
|
199 # Comparisons: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
200 self.assertEqual(u'abc', 'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
201 self.assertEqual('abc', u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
202 self.assertEqual(u'abc', u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
203 self.assert_(u'abcd' > 'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
204 self.assert_('abcd' > u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
205 self.assert_(u'abcd' > u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
206 self.assert_(u'abc' < 'abcd') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
207 self.assert_('abc' < u'abcd') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
208 self.assert_(u'abc' < u'abcd') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
209 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
210 if 0: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
211 # 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
|
212 # 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
|
213 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
214 # No surrogates, no fixup required. |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
215 self.assert_(u'\u0061' < u'\u20ac') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
216 # Non surrogate below surrogate value, no fixup required |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
217 self.assert_(u'\u0061' < u'\ud800\udc02') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
218 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
219 # 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
|
220 def test_lecmp(s, s2): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
221 self.assert_(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
|
222 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
223 def test_fixup(s): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
224 s2 = u'\ud800\udc01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
225 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
226 s2 = u'\ud900\udc01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
227 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
228 s2 = u'\uda00\udc01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
229 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
230 s2 = u'\udb00\udc01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
231 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
232 s2 = u'\ud800\udd01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
233 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
234 s2 = u'\ud900\udd01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
235 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
236 s2 = u'\uda00\udd01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
237 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
238 s2 = u'\udb00\udd01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
239 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
240 s2 = u'\ud800\ude01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
241 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
242 s2 = u'\ud900\ude01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
243 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
244 s2 = u'\uda00\ude01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
245 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
246 s2 = u'\udb00\ude01' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
247 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
248 s2 = u'\ud800\udfff' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
249 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
250 s2 = u'\ud900\udfff' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
251 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
252 s2 = u'\uda00\udfff' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
253 test_lecmp(s, s2) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
254 s2 = u'\udb00\udfff' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
255 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
|
256 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
257 test_fixup(u'\ue000') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
258 test_fixup(u'\uff61') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
259 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
260 # Surrogates on both sides, no fixup required |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
261 self.assert_(u'\ud800\udc02' < u'\ud84d\udc56') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
263 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
|
264 string_tests.MixinStrUnicodeUserStringTest.test_islower(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
265 self.checkequalnofix(False, u'\u1FFc', 'islower') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
267 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
|
268 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
|
269 if not sys.platform.startswith('java'): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
270 self.checkequalnofix(False, u'\u1FFc', 'isupper') |
|
13353
0b289e00d52a
Added tests for the new .isalpha() and .isalnum() methods.
Marc-André Lemburg <mal@egenix.com>
parents:
13189
diff
changeset
|
271 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
272 def test_istitle(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
273 string_tests.MixinStrUnicodeUserStringTest.test_title(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
274 self.checkequalnofix(True, u'\u1FFc', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
275 self.checkequalnofix(True, u'Greek \u1FFcitlecases ...', 'istitle') |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
277 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
|
278 string_tests.MixinStrUnicodeUserStringTest.test_isspace(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
279 self.checkequalnofix(True, u'\u2000', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
280 self.checkequalnofix(True, u'\u200a', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
281 self.checkequalnofix(False, u'\u2014', 'isspace') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
282 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
283 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
|
284 string_tests.MixinStrUnicodeUserStringTest.test_isalpha(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
285 self.checkequalnofix(True, u'\u1FFc', '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
|
286 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
287 def test_isdecimal(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
288 self.checkequalnofix(False, u'', 'isdecimal') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
289 self.checkequalnofix(False, u'a', 'isdecimal') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
290 self.checkequalnofix(True, u'0', 'isdecimal') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
291 self.checkequalnofix(False, u'\u2460', 'isdecimal') # CIRCLED DIGIT ONE |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
292 self.checkequalnofix(False, u'\xbc', 'isdecimal') # VULGAR FRACTION ONE QUARTER |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
293 self.checkequalnofix(True, u'\u0660', 'isdecimal') # ARABIC-INDIC DIGIT ZERO |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
294 self.checkequalnofix(True, u'0123456789', 'isdecimal') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
295 self.checkequalnofix(False, u'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
|
296 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
297 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
|
298 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
299 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
|
300 string_tests.MixinStrUnicodeUserStringTest.test_isdigit(self) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
301 self.checkequalnofix(True, u'\u2460', 'isdigit') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
302 self.checkequalnofix(False, u'\xbc', 'isdigit') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
303 self.checkequalnofix(True, u'\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
|
304 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
305 def test_isnumeric(self): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
306 self.checkequalnofix(False, u'', 'isnumeric') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
307 self.checkequalnofix(False, u'a', 'isnumeric') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
308 self.checkequalnofix(True, u'0', 'isnumeric') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
309 self.checkequalnofix(True, u'\u2460', 'isnumeric') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
310 self.checkequalnofix(True, u'\xbc', 'isnumeric') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
311 self.checkequalnofix(True, u'\u0660', 'isnumeric') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
312 self.checkequalnofix(True, u'0123456789', 'isnumeric') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
313 self.checkequalnofix(False, u'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
|
314 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
315 self.assertRaises(TypeError, u"abc".isnumeric, 42) |
|
12917
2a2caaee6797
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12897
diff
changeset
|
316 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
317 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
|
318 # Testing Unicode contains method |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
319 self.assert_('a' in u'abdb') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
320 self.assert_('a' in u'bdab') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
321 self.assert_('a' in u'bdaba') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
322 self.assert_('a' in u'bdba') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
323 self.assert_('a' in u'bdba') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
324 self.assert_(u'a' in u'bdba') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
325 self.assert_(u'a' not in u'bdb') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
326 self.assert_(u'a' not in 'bdb') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
327 self.assert_(u'a' in 'bdba') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
328 self.assert_(u'a' in ('a',1,None)) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
329 self.assert_(u'a' in (1,None,'a')) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
330 self.assert_(u'a' in (1,None,u'a')) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
331 self.assert_('a' in ('a',1,None)) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
332 self.assert_('a' in (1,None,'a')) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
333 self.assert_('a' in (1,None,u'a')) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
334 self.assert_('a' not in ('x',1,u'y')) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
335 self.assert_('a' not in ('x',1,None)) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
336 self.assert_(u'abcd' not in u'abcxxxx') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
337 self.assert_(u'ab' in u'abcd') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
338 self.assert_('ab' in u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
339 self.assert_(u'ab' in 'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
340 self.assert_(u'ab' in (1,None,u'ab')) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
341 self.assert_(u'' in u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
342 self.assert_('' in u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
343 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
344 # If the following fails either |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
345 # the contains operator does not propagate UnicodeErrors or |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
346 # someone has changed the default encoding |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
347 self.assertRaises(UnicodeError, 'g\xe2teau'.__contains__, u'\xe2') |
|
24737
eaa87632b1e8
Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level.
Marc-André Lemburg <mal@egenix.com>
parents:
24703
diff
changeset
|
348 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
349 self.assert_(u'' in '') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
350 self.assert_('' in u'') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
351 self.assert_(u'' in u'') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
352 self.assert_(u'' in 'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
353 self.assert_('' in u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
354 self.assert_(u'' in u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
355 self.assert_(u'\0' not in 'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
356 self.assert_('\0' not in u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
357 self.assert_(u'\0' not in u'abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
358 self.assert_(u'\0' in '\0abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
359 self.assert_('\0' in u'\0abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
360 self.assert_(u'\0' in u'\0abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
361 self.assert_(u'\0' in 'abc\0') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
362 self.assert_('\0' in u'abc\0') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
363 self.assert_(u'\0' in u'abc\0') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
364 self.assert_(u'a' in '\0abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
365 self.assert_('a' in u'\0abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
366 self.assert_(u'a' in u'\0abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
367 self.assert_(u'asdf' in 'asdf') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
368 self.assert_('asdf' in u'asdf') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
369 self.assert_(u'asdf' in u'asdf') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
370 self.assert_(u'asdf' not in 'asd') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
371 self.assert_('asdf' not in u'asd') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
372 self.assert_(u'asdf' not in u'asd') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
373 self.assert_(u'asdf' not in '') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
374 self.assert_('asdf' not in u'') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
375 self.assert_(u'asdf' not in u'') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
376 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
377 self.assertRaises(TypeError, u"abc".__contains__) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
379 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
|
380 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
|
381 # Testing Unicode formatting strings... |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
382 self.assertEqual(u"%s, %s" % (u"abc", "abc"), u'abc, abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
383 self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, 2, 3), u'abc, abc, 1, 2.000000, 3.00') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
384 self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, -2, 3), u'abc, abc, 1, -2.000000, 3.00') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
385 self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.5), u'abc, abc, -1, -2.000000, 3.50') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
386 self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.57), u'abc, abc, -1, -2.000000, 3.57') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
387 self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 1003.57), u'abc, abc, -1, -2.000000, 1003.57') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
388 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
|
389 self.assertEqual(u"%r, %r" % (u"abc", "abc"), u"u'abc', 'abc'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
390 self.assertEqual(u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"}, u'abc, def') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
391 self.assertEqual(u"%(x)s, %(\xfc)s" % {'x':u"abc", u'\xfc':"def"}, u'abc, def') |
|
28479
e13a7e1fdb9e
Remove duplicate test.
Walter Dörwald <walter@livinglogic.de>
parents:
28478
diff
changeset
|
392 |
|
28478
8802de0da533
Fix PyString_Format() so that '%c' % u'a' returns u'a'
Walter Dörwald <walter@livinglogic.de>
parents:
28009
diff
changeset
|
393 self.assertEqual(u'%c' % 0x1234, u'\u1234') |
|
28494
32bea41fef68
Change formatchar(), so that u"%c" % 0xffffffff now raises
Walter Dörwald <walter@livinglogic.de>
parents:
28479
diff
changeset
|
394 self.assertRaises(OverflowError, u"%c".__mod__, (sys.maxunicode+1,)) |
|
20563
9058e49c6c57
Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents:
20240
diff
changeset
|
395 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
396 # formatting jobs delegated from the string implementation: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
397 self.assertEqual('...%(foo)s...' % {'foo':u"abc"}, u'...abc...') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
398 self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
399 self.assertEqual('...%(foo)s...' % {u'foo':"abc"}, '...abc...') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
400 self.assertEqual('...%(foo)s...' % {u'foo':u"abc"}, u'...abc...') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
401 self.assertEqual('...%(foo)s...' % {u'foo':u"abc",'def':123}, u'...abc...') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
402 self.assertEqual('...%(foo)s...' % {u'foo':u"abc",u'def':123}, u'...abc...') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
403 self.assertEqual('...%s...%s...%s...%s...' % (1,2,3,u"abc"), u'...1...2...3...abc...') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
404 self.assertEqual('...%%...%%s...%s...%s...%s...%s...' % (1,2,3,u"abc"), u'...%...%s...1...2...3...abc...') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
405 self.assertEqual('...%s...' % u"abc", u'...abc...') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
406 self.assertEqual('%*s' % (5,u'abc',), u' abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
407 self.assertEqual('%*s' % (-5,u'abc',), u'abc ') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
408 self.assertEqual('%*.*s' % (5,2,u'abc',), u' ab') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
409 self.assertEqual('%*.*s' % (5,3,u'abc',), u' abc') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
410 self.assertEqual('%i %*.*s' % (10, 5,3,u'abc',), u'10 abc') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
411 self.assertEqual('%i%s %*.*s' % (10, 3, 5, 3, u'abc',), u'103 abc') |
|
28478
8802de0da533
Fix PyString_Format() so that '%c' % u'a' returns u'a'
Walter Dörwald <walter@livinglogic.de>
parents:
28009
diff
changeset
|
412 self.assertEqual('%c' % u'a', u'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
|
413 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
|
414 def __str__(self): |
|
ef11cbc08dab
Change the %s format specifier for str objects so that it returns a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
34931
diff
changeset
|
415 return u'\u1234' |
|
ef11cbc08dab
Change the %s format specifier for str objects so that it returns a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
34931
diff
changeset
|
416 self.assertEqual('%s' % Wrapper(), u'\u1234') |
|
38096
5457ab9f8599
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
38055
diff
changeset
|
417 |
|
38055
fcc61835c6ac
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents:
37301
diff
changeset
|
418 @test_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
|
419 def test_format_float(self): |
|
38055
fcc61835c6ac
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents:
37301
diff
changeset
|
420 # should not format with a comma, but always with C locale |
|
fcc61835c6ac
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents:
37301
diff
changeset
|
421 self.assertEqual(u'1.0', u'%.1f' % 1.0) |
|
36341
4bcf5fe54d83
Checkin the test of patch #1400181.
Georg Brandl <georg@python.org>
parents:
36056
diff
changeset
|
422 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
423 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
|
424 # 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
|
425 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
426 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
427 unicode(u'unicode remains unicode'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
428 u'unicode remains unicode' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
429 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
430 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
431 class UnicodeSubclass(unicode): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
432 pass |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
18828
diff
changeset
|
433 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
434 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
435 unicode(UnicodeSubclass('unicode subclass becomes unicode')), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
436 u'unicode subclass becomes unicode' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
437 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
438 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
439 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
440 unicode('strings are converted to unicode'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
441 u'strings are converted to unicode' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
442 ) |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
18828
diff
changeset
|
443 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
444 class UnicodeCompat: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
445 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
|
446 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
|
447 def __unicode__(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
448 return self.x |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
18828
diff
changeset
|
449 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
450 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
451 unicode(UnicodeCompat('__unicode__ compatible objects are recognized')), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
452 u'__unicode__ compatible objects are recognized') |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
18828
diff
changeset
|
453 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
454 class StringCompat: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
455 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
|
456 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
|
457 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
|
458 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
|
459 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
460 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
461 unicode(StringCompat('__str__ compatible objects are recognized')), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
462 u'__str__ compatible objects are recognized' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
463 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
464 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
465 # 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
|
466 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
467 o = StringCompat('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
|
468 self.assertEqual(unicode(o), u'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
|
469 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
|
470 |
|
32801
16de4f90ef44
Let u'%s' % obj try obj.__unicode__() first and fallback to obj.__str__().
Marc-André Lemburg <mal@egenix.com>
parents:
32240
diff
changeset
|
471 # %-formatting and .__unicode__() |
|
16de4f90ef44
Let u'%s' % obj try obj.__unicode__() first and fallback to obj.__str__().
Marc-André Lemburg <mal@egenix.com>
parents:
32240
diff
changeset
|
472 self.assertEqual(u'%s' % |
|
16de4f90ef44
Let u'%s' % obj try obj.__unicode__() first and fallback to obj.__str__().
Marc-André Lemburg <mal@egenix.com>
parents:
32240
diff
changeset
|
473 UnicodeCompat(u"u'%s' % obj uses obj.__unicode__()"), |
|
16de4f90ef44
Let u'%s' % obj try obj.__unicode__() first and fallback to obj.__str__().
Marc-André Lemburg <mal@egenix.com>
parents:
32240
diff
changeset
|
474 u"u'%s' % obj uses obj.__unicode__()") |
|
16de4f90ef44
Let u'%s' % obj try obj.__unicode__() first and fallback to obj.__str__().
Marc-André Lemburg <mal@egenix.com>
parents:
32240
diff
changeset
|
475 self.assertEqual(u'%s' % |
|
16de4f90ef44
Let u'%s' % obj try obj.__unicode__() first and fallback to obj.__str__().
Marc-André Lemburg <mal@egenix.com>
parents:
32240
diff
changeset
|
476 UnicodeCompat(u"u'%s' % obj falls back to obj.__str__()"), |
|
16de4f90ef44
Let u'%s' % obj try obj.__unicode__() first and fallback to obj.__str__().
Marc-André Lemburg <mal@egenix.com>
parents:
32240
diff
changeset
|
477 u"u'%s' % obj falls back to obj.__str__()") |
|
16de4f90ef44
Let u'%s' % obj try obj.__unicode__() first and fallback to obj.__str__().
Marc-André Lemburg <mal@egenix.com>
parents:
32240
diff
changeset
|
478 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
479 for obj in (123, 123.45, 123L): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
480 self.assertEqual(unicode(obj), unicode(str(obj))) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
481 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
482 # 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
|
483 # 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
|
484 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
485 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
|
486 self.assertRaises( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
487 TypeError, |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
488 unicode, |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
489 u'decoding unicode is not supported', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
490 'utf-8', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
491 'strict' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
492 ) |
|
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
|
493 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
494 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
495 unicode('strings are decoded to unicode', 'utf-8', 'strict'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
496 u'strings are decoded to unicode' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
497 ) |
|
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
|
498 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
499 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
|
500 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
501 unicode( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
502 buffer('character buffers are decoded to unicode'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
503 'utf-8', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
504 'strict' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
505 ), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
506 u'character buffers are decoded to unicode' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
507 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
508 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
509 self.assertRaises(TypeError, unicode, 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
|
510 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
511 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
|
512 utfTests = [ |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
513 (u'A\u2262\u0391.', 'A+ImIDkQ.'), # RFC2152 example |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
514 (u'Hi Mom -\u263a-!', 'Hi Mom -+Jjo--!'), # RFC2152 example |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
515 (u'\u65E5\u672C\u8A9E', '+ZeVnLIqe-'), # RFC2152 example |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
516 (u'Item 3 is \u00a31.', 'Item 3 is +AKM-1.'), # RFC2152 example |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
517 (u'+', '+-'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
518 (u'+-', '+--'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
519 (u'+?', '+-?'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
520 (u'\?', '+AFw?'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
521 (u'+?', '+-?'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
522 (ur'\\?', '+AFwAXA?'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
523 (ur'\\\?', '+AFwAXABc?'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
524 (ur'++--', '+-+---') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
525 ] |
| 12051 | 526 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
527 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
|
528 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
|
529 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
530 # surrogates not supported |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
531 self.assertRaises(UnicodeError, unicode, '+3ADYAA-', 'utf-7') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
532 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
533 self.assertEqual(unicode('+3ADYAA-', 'utf-7', 'replace'), u'\ufffd') |
| 12331 | 534 |
|
48070
35a462ff9873
#2242: utf7 decoding crashes on bogus input on some Windows/MSVC versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
46028
diff
changeset
|
535 # Issue #2242: crash on some Windows/MSVC versions |
|
35a462ff9873
#2242: utf7 decoding crashes on bogus input on some Windows/MSVC versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
46028
diff
changeset
|
536 self.assertRaises(UnicodeDecodeError, '+\xc1'.decode, 'utf-7') |
|
35a462ff9873
#2242: utf7 decoding crashes on bogus input on some Windows/MSVC versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
46028
diff
changeset
|
537 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
538 def test_codecs_utf8(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
539 self.assertEqual(u''.encode('utf-8'), '') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
540 self.assertEqual(u'\u20ac'.encode('utf-8'), '\xe2\x82\xac') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
541 self.assertEqual(u'\ud800\udc02'.encode('utf-8'), '\xf0\x90\x80\x82') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
542 self.assertEqual(u'\ud84d\udc56'.encode('utf-8'), '\xf0\xa3\x91\x96') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
543 self.assertEqual(u'\ud800'.encode('utf-8'), '\xed\xa0\x80') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
544 self.assertEqual(u'\udc00'.encode('utf-8'), '\xed\xb0\x80') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
545 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
546 (u'\ud800\udc02'*1000).encode('utf-8'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
547 '\xf0\x90\x80\x82'*1000 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
548 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
549 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
550 u'\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
551 u'\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
552 u'\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
553 u'\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
554 u'\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
555 u' Nunstuck git und'.encode('utf-8'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
556 '\xe6\xad\xa3\xe7\xa2\xba\xe3\x81\xab\xe8\xa8\x80\xe3\x81' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
557 '\x86\xe3\x81\xa8\xe7\xbf\xbb\xe8\xa8\xb3\xe3\x81\xaf\xe3' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
558 '\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x81\xbe' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
559 '\xe3\x81\x9b\xe3\x82\x93\xe3\x80\x82\xe4\xb8\x80\xe9\x83' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
560 '\xa8\xe3\x81\xaf\xe3\x83\x89\xe3\x82\xa4\xe3\x83\x84\xe8' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
561 '\xaa\x9e\xe3\x81\xa7\xe3\x81\x99\xe3\x81\x8c\xe3\x80\x81' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
562 '\xe3\x81\x82\xe3\x81\xa8\xe3\x81\xaf\xe3\x81\xa7\xe3\x81' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
563 '\x9f\xe3\x82\x89\xe3\x82\x81\xe3\x81\xa7\xe3\x81\x99\xe3' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
564 '\x80\x82\xe5\xae\x9f\xe9\x9a\x9b\xe3\x81\xab\xe3\x81\xaf' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
565 '\xe3\x80\x8cWenn ist das Nunstuck git und' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
566 ) |
|
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
|
567 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
568 # UTF-8 specific decoding tests |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
569 self.assertEqual(unicode('\xf0\xa3\x91\x96', 'utf-8'), u'\U00023456' ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
570 self.assertEqual(unicode('\xf0\x90\x80\x82', 'utf-8'), u'\U00010002' ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
571 self.assertEqual(unicode('\xe2\x82\xac', 'utf-8'), u'\u20ac' ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
572 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
573 # 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
|
574 # * 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
|
575 # UTF8_ERROR cases in PyUnicode_DecodeUTF8 |
| 12051 | 576 |
|
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
|
577 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
|
578 # Test whether trailing dot is preserved |
|
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
|
579 self.assertEqual(u"www.python.org.".encode("idna"), "www.python.org.") |
|
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
|
580 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
581 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
|
582 # Error handling (encoding) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
583 self.assertRaises(UnicodeError, u'Andr\202 x'.encode, 'ascii') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
584 self.assertRaises(UnicodeError, u'Andr\202 x'.encode, 'ascii','strict') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
585 self.assertEqual(u'Andr\202 x'.encode('ascii','ignore'), "Andr x") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
586 self.assertEqual(u'Andr\202 x'.encode('ascii','replace'), "Andr? x") |
| 12051 | 587 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
588 # Error handling (decoding) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
589 self.assertRaises(UnicodeError, unicode, 'Andr\202 x', 'ascii') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
590 self.assertRaises(UnicodeError, unicode, 'Andr\202 x', 'ascii','strict') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
591 self.assertEqual(unicode('Andr\202 x','ascii','ignore'), u"Andr x") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
592 self.assertEqual(unicode('Andr\202 x','ascii','replace'), u'Andr\uFFFD x') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
593 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
594 # Error handling (unknown character names) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
595 self.assertEqual("\\N{foo}xx".decode("unicode-escape", "ignore"), u"xx") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
596 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
597 # Error handling (truncated escape sequence) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
598 self.assertRaises(UnicodeError, "\\".decode, "unicode-escape") |
| 12051 | 599 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
600 self.assertRaises(TypeError, "hello".decode, "test.unicode1") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
601 self.assertRaises(TypeError, unicode, "hello", "test.unicode2") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
602 self.assertRaises(TypeError, u"hello".encode, "test.unicode1") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
603 self.assertRaises(TypeError, u"hello".encode, "test.unicode2") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
604 # executes PyUnicode_Encode() |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
605 import imp |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
606 self.assertRaises( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
607 ImportError, |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
608 imp.find_module, |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
609 "non-existing module", |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
610 [u"non-existing dir"] |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
611 ) |
|
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
|
612 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
613 # Error handling (wrong arguments) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
614 self.assertRaises(TypeError, u"hello".encode, 42, 42, 42) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
615 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
616 # Error handling (PyUnicode_EncodeDecimal()) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
617 self.assertRaises(UnicodeError, int, u"\u0200") |
|
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
|
618 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
619 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
|
620 # Encoding |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
621 self.assertEqual(u'hello'.encode('ascii'), 'hello') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
622 self.assertEqual(u'hello'.encode('utf-7'), 'hello') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
623 self.assertEqual(u'hello'.encode('utf-8'), 'hello') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
624 self.assertEqual(u'hello'.encode('utf8'), 'hello') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
625 self.assertEqual(u'hello'.encode('utf-16-le'), 'h\000e\000l\000l\000o\000') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
626 self.assertEqual(u'hello'.encode('utf-16-be'), '\000h\000e\000l\000l\000o') |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
627 self.assertEqual(u'hello'.encode('latin-1'), '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
|
628 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
629 # Roundtrip safety for BMP (just the first 1024 chars) |
|
36056
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
630 for c in xrange(1024): |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
631 u = unichr(c) |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
632 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
|
633 '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
|
634 'unicode_escape', 'unicode_internal'): |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
635 self.assertEqual(unicode(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
|
636 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
637 # Roundtrip safety for BMP (just the first 256 chars) |
|
36056
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
638 for c in xrange(256): |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
639 u = unichr(c) |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
640 for encoding in ('latin-1',): |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
641 self.assertEqual(unicode(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
|
642 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
643 # Roundtrip safety for BMP (just the first 128 chars) |
|
36056
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
644 for c in xrange(128): |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
645 u = unichr(c) |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
646 for encoding in ('ascii',): |
|
f1ae11457d34
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35938
diff
changeset
|
647 self.assertEqual(unicode(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
|
648 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
649 # Roundtrip safety for non-BMP (just a few chars) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
650 u = u'\U00010001\U00020002\U00030003\U00040004\U00050005' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
651 for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
652 #'raw_unicode_escape', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
653 'unicode_escape', 'unicode_internal'): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
654 self.assertEqual(unicode(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
|
655 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
656 # UTF-8 must be roundtrip safe for all UCS-2 code points |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
657 # This excludes surrogates: in the full range, there would be |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
658 # a surrogate pair (\udbff\udc00), which gets converted back |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
659 # to a non-BMP character (\U0010fc00) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
660 u = u''.join(map(unichr, range(0,0xd800)+range(0xe000,0x10000))) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
661 for encoding in ('utf-8',): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
662 self.assertEqual(unicode(u.encode(encoding),encoding), u) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
663 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
664 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
|
665 # 0-127 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
666 s = ''.join(map(chr, xrange(128))) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
667 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
|
668 'cp037', 'cp1026', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
669 'cp437', 'cp500', 'cp737', 'cp775', 'cp850', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
670 'cp852', 'cp855', 'cp860', 'cp861', 'cp862', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
671 '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
|
672 '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
|
673 '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
|
674 '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
|
675 '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
|
676 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
677 '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
|
678 '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
|
679 '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
|
680 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
681 '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
|
682 '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
|
683 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
684 ### 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
|
685 #'cp424', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
686 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
687 ### 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
|
688 #'cp875' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
689 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
690 ): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
691 self.assertEqual(unicode(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
|
692 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
693 # 128-255 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
694 s = ''.join(map(chr, xrange(128, 256))) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
695 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
|
696 'cp037', 'cp1026', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
697 'cp437', 'cp500', 'cp737', 'cp775', 'cp850', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
698 'cp852', 'cp855', 'cp860', 'cp861', 'cp862', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
699 '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
|
700 '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
|
701 '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
|
702 '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
|
703 '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
|
704 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
705 ### 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
|
706 #'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
|
707 #'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
|
708 #'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
|
709 #'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
|
710 #'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
|
711 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
712 ### 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
|
713 #'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
|
714 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
715 ): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
716 self.assertEqual(unicode(s, encoding).encode(encoding), s) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
717 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
718 def test_concatenation(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
719 self.assertEqual((u"abc" u"def"), u"abcdef") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
720 self.assertEqual(("abc" u"def"), u"abcdef") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
721 self.assertEqual((u"abc" "def"), u"abcdef") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
722 self.assertEqual((u"abc" u"def" "ghi"), u"abcdefghi") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
723 self.assertEqual(("abc" "def" u"ghi"), u"abcdefghi") |
|
21027
dee0e866653e
Fix for bug #480188: printing unicode objects
Marc-André Lemburg <mal@egenix.com>
parents:
20563
diff
changeset
|
724 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
725 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
|
726 class BitBucket: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
727 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
|
728 pass |
|
24598
12e146171f3d
Committing patch #591250 which provides "str1 in str2" when str1 is a
Barry Warsaw <barry@python.org>
parents:
24538
diff
changeset
|
729 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
730 out = BitBucket() |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
731 print >>out, u'abc' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
732 print >>out, u'abc', u'def' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
733 print >>out, u'abc', 'def' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
734 print >>out, 'abc', u'def' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
735 print >>out, u'abc\n' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
736 print >>out, u'abc\n', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
737 print >>out, u'abc\n', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
738 print >>out, u'def\n' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
739 print >>out, u'def\n' |
|
24598
12e146171f3d
Committing patch #591250 which provides "str1 in str2" when str1 is a
Barry Warsaw <barry@python.org>
parents:
24538
diff
changeset
|
740 |
|
29164
4d9017ef7b5f
Consider \U-escapes in raw-unicode-escape. Fixes #444514.
Martin v. Löwis <martin@v.loewis.de>
parents:
28917
diff
changeset
|
741 def test_ucs4(self): |
|
4d9017ef7b5f
Consider \U-escapes in raw-unicode-escape. Fixes #444514.
Martin v. Löwis <martin@v.loewis.de>
parents:
28917
diff
changeset
|
742 x = u'\U00100000' |
|
4d9017ef7b5f
Consider \U-escapes in raw-unicode-escape. Fixes #444514.
Martin v. Löwis <martin@v.loewis.de>
parents:
28917
diff
changeset
|
743 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
|
744 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
|
745 |
|
46028
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
746 y = r'\U00100000' |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
747 x = y.decode("raw-unicode-escape").encode("raw-unicode-escape") |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
748 self.assertEqual(x, y) |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
749 y = r'\U00010000' |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
750 x = y.decode("raw-unicode-escape").encode("raw-unicode-escape") |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
751 self.assertEqual(x, y) |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
752 |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
753 try: |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
754 '\U11111111'.decode("raw-unicode-escape") |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
755 except UnicodeDecodeError as e: |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
756 self.assertEqual(e.start, 0) |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
757 self.assertEqual(e.end, 10) |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
758 else: |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
759 self.fail("Should have raised UnicodeDecodeError") |
|
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
760 |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
761 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
|
762 # 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
|
763 class Foo0: |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
764 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
765 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
766 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
767 class Foo1: |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
768 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
769 return u"foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
770 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
771 class Foo2(object): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
772 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
773 return u"foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
774 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
775 class Foo3(object): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
776 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
777 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
778 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
779 class Foo4(str): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
780 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
781 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
782 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
783 class Foo5(unicode): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
784 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
785 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
786 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
787 class Foo6(str): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
788 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
789 return "foos" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
790 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
791 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
792 return u"foou" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
793 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
794 class Foo7(unicode): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
795 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
796 return "foos" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
797 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
798 return u"foou" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
799 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
800 class Foo8(unicode): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
801 def __new__(cls, content=""): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
802 return unicode.__new__(cls, 2*content) |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
803 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
804 return self |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
805 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
806 class Foo9(unicode): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
807 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
808 return "string" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
809 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
810 return "not unicode" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
811 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
812 self.assertEqual(unicode(Foo0()), u"foo") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
813 self.assertEqual(unicode(Foo1()), u"foo") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
814 self.assertEqual(unicode(Foo2()), u"foo") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
815 self.assertEqual(unicode(Foo3()), u"foo") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
816 self.assertEqual(unicode(Foo4("bar")), u"foo") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
817 self.assertEqual(unicode(Foo5("bar")), u"foo") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
818 self.assertEqual(unicode(Foo6("bar")), u"foou") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
819 self.assertEqual(unicode(Foo7("bar")), u"foou") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
820 self.assertEqual(unicode(Foo8("foo")), u"foofoo") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
821 self.assertEqual(str(Foo9("foo")), "string") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
822 self.assertEqual(unicode(Foo9("foo")), u"not unicode") |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
823 |
|
37301
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
824 def test_unicode_repr(self): |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
825 class s1: |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
826 def __repr__(self): |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
827 return '\\n' |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
828 |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
829 class s2: |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
830 def __repr__(self): |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
831 return u'\\n' |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
832 |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
833 self.assertEqual(repr(s1()), '\\n') |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
834 self.assertEqual(repr(s2()), '\\n') |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
835 |
|
42004
e62b606eff0b
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
41534
diff
changeset
|
836 def test_expandtabs_overflows_gracefully(self): |
|
e62b606eff0b
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
41534
diff
changeset
|
837 # This test only affects 32-bit platforms because expandtabs can only take |
|
e62b606eff0b
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
41534
diff
changeset
|
838 # an int as the max value, not a 64-bit C long. If expandtabs is changed |
|
e62b606eff0b
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
41534
diff
changeset
|
839 # to take a 64-bit long, this test should apply to all platforms. |
|
42023
dde7c37f4536
Prevent these tests from running on Win64 since they don\'t apply there either
Neal Norwitz <nnorwitz@gmail.com>
parents:
42004
diff
changeset
|
840 if sys.maxint > (1 << 32) or struct.calcsize('P') != 4: |
|
42004
e62b606eff0b
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
41534
diff
changeset
|
841 return |
|
e62b606eff0b
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
41534
diff
changeset
|
842 self.assertRaises(OverflowError, u't\tt\t'.expandtabs, sys.maxint) |
|
37301
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
843 |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
844 def test__format__(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
845 def test(value, format, expected): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
846 # test both with and without the trailing 's' |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
847 self.assertEqual(value.__format__(format), expected) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
848 self.assertEqual(value.__format__(format + u's'), expected) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
849 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
850 test(u'', u'', u'') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
851 test(u'abc', u'', u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
852 test(u'abc', u'.3', u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
853 test(u'ab', u'.3', u'ab') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
854 test(u'abcdef', u'.3', u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
855 test(u'abcdef', u'.0', u'') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
856 test(u'abc', u'3.3', u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
857 test(u'abc', u'2.3', u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
858 test(u'abc', u'2.2', u'ab') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
859 test(u'abc', u'3.2', u'ab ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
860 test(u'result', u'x<0', u'result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
861 test(u'result', u'x<5', u'result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
862 test(u'result', u'x<6', u'result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
863 test(u'result', u'x<7', u'resultx') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
864 test(u'result', u'x<8', u'resultxx') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
865 test(u'result', u' <7', u'result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
866 test(u'result', u'<7', u'result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
867 test(u'result', u'>7', u' result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
868 test(u'result', u'>8', u' result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
869 test(u'result', u'^8', u' result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
870 test(u'result', u'^9', u' result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
871 test(u'result', u'^10', u' result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
872 test(u'a', u'10000', u'a' + u' ' * 9999) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
873 test(u'', u'10000', u' ' * 10000) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
874 test(u'', u'10000000', u' ' * 10000000) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
875 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
876 # test mixing unicode and str |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
877 self.assertEqual(u'abc'.__format__('s'), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
878 self.assertEqual(u'abc'.__format__('->10s'), u'-------abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
879 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
880 def test_format(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
881 self.assertEqual(u''.format(), u'') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
882 self.assertEqual(u'a'.format(), u'a') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
883 self.assertEqual(u'ab'.format(), u'ab') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
884 self.assertEqual(u'a{{'.format(), u'a{') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
885 self.assertEqual(u'a}}'.format(), u'a}') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
886 self.assertEqual(u'{{b'.format(), u'{b') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
887 self.assertEqual(u'}}b'.format(), u'}b') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
888 self.assertEqual(u'a{{b'.format(), u'a{b') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
889 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
890 # examples from the PEP: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
891 import datetime |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
892 self.assertEqual(u"My name is {0}".format(u'Fred'), u"My name is Fred") |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
893 self.assertEqual(u"My name is {0[name]}".format(dict(name=u'Fred')), |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
894 u"My name is Fred") |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
895 self.assertEqual(u"My name is {0} :-{{}}".format(u'Fred'), |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
896 u"My name is Fred :-{}") |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
897 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
898 # datetime.__format__ doesn't work with unicode |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
899 #d = datetime.date(2007, 8, 18) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
900 #self.assertEqual("The year is {0.year}".format(d), |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
901 # "The year is 2007") |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
902 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
903 # classes we'll use for testing |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
904 class C: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
905 def __init__(self, x=100): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
906 self._x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
907 def __format__(self, spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
908 return spec |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
909 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
910 class D: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
911 def __init__(self, x): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
912 self.x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
913 def __format__(self, spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
914 return str(self.x) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
915 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
916 # class with __str__, but no __format__ |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
917 class E: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
918 def __init__(self, x): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
919 self.x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
920 def __str__(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
921 return u'E(' + self.x + u')' |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
922 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
923 # class with __repr__, but no __format__ or __str__ |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
924 class F: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
925 def __init__(self, x): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
926 self.x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
927 def __repr__(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
928 return u'F(' + self.x + u')' |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
929 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
930 # class with __format__ that forwards to string, for some format_spec's |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
931 class G: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
932 def __init__(self, x): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
933 self.x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
934 def __str__(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
935 return u"string is " + self.x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
936 def __format__(self, format_spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
937 if format_spec == 'd': |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
938 return u'G(' + self.x + u')' |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
939 return object.__format__(self, format_spec) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
940 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
941 # class that returns a bad type from __format__ |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
942 class H: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
943 def __format__(self, format_spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
944 return 1.0 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
945 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
946 class I(datetime.date): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
947 def __format__(self, format_spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
948 return self.strftime(format_spec) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
949 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
950 class J(int): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
951 def __format__(self, format_spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
952 return int.__format__(self * 2, format_spec) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
953 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
954 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
955 self.assertEqual(u''.format(), u'') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
956 self.assertEqual(u'abc'.format(), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
957 self.assertEqual(u'{0}'.format(u'abc'), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
958 self.assertEqual(u'{0:}'.format(u'abc'), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
959 self.assertEqual(u'X{0}'.format(u'abc'), u'Xabc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
960 self.assertEqual(u'{0}X'.format(u'abc'), u'abcX') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
961 self.assertEqual(u'X{0}Y'.format(u'abc'), u'XabcY') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
962 self.assertEqual(u'{1}'.format(1, u'abc'), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
963 self.assertEqual(u'X{1}'.format(1, u'abc'), u'Xabc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
964 self.assertEqual(u'{1}X'.format(1, u'abc'), u'abcX') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
965 self.assertEqual(u'X{1}Y'.format(1, u'abc'), u'XabcY') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
966 self.assertEqual(u'{0}'.format(-15), u'-15') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
967 self.assertEqual(u'{0}{1}'.format(-15, u'abc'), u'-15abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
968 self.assertEqual(u'{0}X{1}'.format(-15, u'abc'), u'-15Xabc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
969 self.assertEqual(u'{{'.format(), u'{') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
970 self.assertEqual(u'}}'.format(), u'}') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
971 self.assertEqual(u'{{}}'.format(), u'{}') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
972 self.assertEqual(u'{{x}}'.format(), u'{x}') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
973 self.assertEqual(u'{{{0}}}'.format(123), u'{123}') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
974 self.assertEqual(u'{{{{0}}}}'.format(), u'{{0}}') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
975 self.assertEqual(u'}}{{'.format(), u'}{') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
976 self.assertEqual(u'}}x{{'.format(), u'}x{') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
977 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
978 # weird field names |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
979 self.assertEqual(u"{0[foo-bar]}".format({u'foo-bar':u'baz'}), u'baz') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
980 self.assertEqual(u"{0[foo bar]}".format({u'foo bar':u'baz'}), u'baz') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
981 self.assertEqual(u"{0[ ]}".format({u' ':3}), u'3') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
982 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
983 self.assertEqual(u'{foo._x}'.format(foo=C(20)), u'20') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
984 self.assertEqual(u'{1}{0}'.format(D(10), D(20)), u'2010') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
985 self.assertEqual(u'{0._x.x}'.format(C(D(u'abc'))), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
986 self.assertEqual(u'{0[0]}'.format([u'abc', u'def']), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
987 self.assertEqual(u'{0[1]}'.format([u'abc', u'def']), u'def') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
988 self.assertEqual(u'{0[1][0]}'.format([u'abc', [u'def']]), u'def') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
989 self.assertEqual(u'{0[1][0].x}'.format(['abc', [D(u'def')]]), u'def') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
990 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
991 # strings |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
992 self.assertEqual(u'{0:.3s}'.format(u'abc'), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
993 self.assertEqual(u'{0:.3s}'.format(u'ab'), u'ab') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
994 self.assertEqual(u'{0:.3s}'.format(u'abcdef'), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
995 self.assertEqual(u'{0:.0s}'.format(u'abcdef'), u'') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
996 self.assertEqual(u'{0:3.3s}'.format(u'abc'), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
997 self.assertEqual(u'{0:2.3s}'.format(u'abc'), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
998 self.assertEqual(u'{0:2.2s}'.format(u'abc'), u'ab') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
999 self.assertEqual(u'{0:3.2s}'.format(u'abc'), u'ab ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1000 self.assertEqual(u'{0:x<0s}'.format(u'result'), u'result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1001 self.assertEqual(u'{0:x<5s}'.format(u'result'), u'result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1002 self.assertEqual(u'{0:x<6s}'.format(u'result'), u'result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1003 self.assertEqual(u'{0:x<7s}'.format(u'result'), u'resultx') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1004 self.assertEqual(u'{0:x<8s}'.format(u'result'), u'resultxx') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1005 self.assertEqual(u'{0: <7s}'.format(u'result'), u'result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1006 self.assertEqual(u'{0:<7s}'.format(u'result'), u'result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1007 self.assertEqual(u'{0:>7s}'.format(u'result'), u' result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1008 self.assertEqual(u'{0:>8s}'.format(u'result'), u' result') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1009 self.assertEqual(u'{0:^8s}'.format(u'result'), u' result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1010 self.assertEqual(u'{0:^9s}'.format(u'result'), u' result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1011 self.assertEqual(u'{0:^10s}'.format(u'result'), u' result ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1012 self.assertEqual(u'{0:10000}'.format(u'a'), u'a' + u' ' * 9999) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1013 self.assertEqual(u'{0:10000}'.format(u''), u' ' * 10000) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1014 self.assertEqual(u'{0:10000000}'.format(u''), u' ' * 10000000) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1015 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1016 # format specifiers for user defined type |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1017 self.assertEqual(u'{0:abc}'.format(C()), u'abc') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1018 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1019 # !r and !s coersions |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1020 self.assertEqual(u'{0!s}'.format(u'Hello'), u'Hello') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1021 self.assertEqual(u'{0!s:}'.format(u'Hello'), u'Hello') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1022 self.assertEqual(u'{0!s:15}'.format(u'Hello'), u'Hello ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1023 self.assertEqual(u'{0!s:15s}'.format(u'Hello'), u'Hello ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1024 self.assertEqual(u'{0!r}'.format(u'Hello'), u"u'Hello'") |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1025 self.assertEqual(u'{0!r:}'.format(u'Hello'), u"u'Hello'") |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1026 self.assertEqual(u'{0!r}'.format(F(u'Hello')), u'F(Hello)') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1027 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1028 # test fallback to object.__format__ |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1029 self.assertEqual(u'{0}'.format({}), u'{}') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1030 self.assertEqual(u'{0}'.format([]), u'[]') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1031 self.assertEqual(u'{0}'.format([1]), u'[1]') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1032 self.assertEqual(u'{0}'.format(E(u'data')), u'E(data)') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1033 self.assertEqual(u'{0:^10}'.format(E(u'data')), u' E(data) ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1034 self.assertEqual(u'{0:^10s}'.format(E(u'data')), u' E(data) ') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1035 self.assertEqual(u'{0:d}'.format(G(u'data')), u'G(data)') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1036 self.assertEqual(u'{0:>15s}'.format(G(u'data')), u' string is data') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1037 self.assertEqual(u'{0!s}'.format(G(u'data')), u'string is data') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1038 |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1039 self.assertEqual(u"{0:date: %Y-%m-%d}".format(I(year=2007, |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1040 month=8, |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1041 day=27)), |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1042 u"date: 2007-08-27") |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1043 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1044 # test deriving from a builtin type and overriding __format__ |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1045 self.assertEqual(u"{0}".format(J(10)), u"20") |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1046 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1047 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1048 # string format specifiers |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1049 self.assertEqual(u'{0:}'.format('a'), u'a') |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1050 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1051 # computed format specifiers |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1052 self.assertEqual(u"{0:.{1}}".format(u'hello world', 5), u'hello') |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1053 self.assertEqual(u"{0:.{1}s}".format(u'hello world', 5), u'hello') |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1054 self.assertEqual(u"{0:.{precision}s}".format('hello world', precision=5), u'hello') |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1055 self.assertEqual(u"{0:{width}.{precision}s}".format('hello world', width=10, precision=5), u'hello ') |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1056 self.assertEqual(u"{0:{width}.{precision}s}".format('hello world', width='10', precision='5'), u'hello ') |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1057 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1058 # test various errors |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1059 self.assertRaises(ValueError, u'{'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1060 self.assertRaises(ValueError, u'}'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1061 self.assertRaises(ValueError, u'a{'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1062 self.assertRaises(ValueError, u'a}'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1063 self.assertRaises(ValueError, u'{a'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1064 self.assertRaises(ValueError, u'}a'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1065 self.assertRaises(IndexError, u'{0}'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1066 self.assertRaises(IndexError, u'{1}'.format, u'abc') |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1067 self.assertRaises(KeyError, u'{x}'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1068 self.assertRaises(ValueError, u"}{".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1069 self.assertRaises(ValueError, u"{".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1070 self.assertRaises(ValueError, u"}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1071 self.assertRaises(ValueError, u"abc{0:{}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1072 self.assertRaises(ValueError, u"{0".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1073 self.assertRaises(IndexError, u"{0.}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1074 self.assertRaises(ValueError, u"{0.}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1075 self.assertRaises(IndexError, u"{0[}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1076 self.assertRaises(ValueError, u"{0[}".format, []) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1077 self.assertRaises(KeyError, u"{0]}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1078 self.assertRaises(ValueError, u"{0.[]}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1079 self.assertRaises(ValueError, u"{0..foo}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1080 self.assertRaises(ValueError, u"{0[0}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1081 self.assertRaises(ValueError, u"{0[0:foo}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1082 self.assertRaises(KeyError, u"{c]}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1083 self.assertRaises(ValueError, u"{{ {{{0}}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1084 self.assertRaises(ValueError, u"{0}}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1085 self.assertRaises(KeyError, u"{foo}".format, bar=3) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1086 self.assertRaises(ValueError, u"{0!x}".format, 3) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1087 self.assertRaises(ValueError, u"{0!}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1088 self.assertRaises(ValueError, u"{0!rs}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1089 self.assertRaises(ValueError, u"{!}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1090 self.assertRaises(ValueError, u"{:}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1091 self.assertRaises(ValueError, u"{:s}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1092 self.assertRaises(ValueError, u"{}".format) |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1093 |
|
54268
d2d028f65c7c
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
52162
diff
changeset
|
1094 # issue 6089 |
|
d2d028f65c7c
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
52162
diff
changeset
|
1095 self.assertRaises(ValueError, u"{0[0]x}".format, [None]) |
|
d2d028f65c7c
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
52162
diff
changeset
|
1096 self.assertRaises(ValueError, u"{0[0](10)}".format, [None]) |
|
d2d028f65c7c
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
52162
diff
changeset
|
1097 |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1098 # can't have a replacement on the field name portion |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1099 self.assertRaises(TypeError, u'{0[{1}]}'.format, u'abcdefg', 4) |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1100 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1101 # exceed maximum recursion depth |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1102 self.assertRaises(ValueError, u"{0:{1:{2}}}".format, u'abc', u's', u'') |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1103 self.assertRaises(ValueError, u"{0:{1:{2:{3:{4:{5:{6}}}}}}}".format, |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1104 0, 1, 2, 3, 4, 5, 6, 7) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1105 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1106 # string format spec errors |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1107 self.assertRaises(ValueError, u"{0:-s}".format, u'') |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1108 self.assertRaises(ValueError, format, u"", u"-") |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1109 self.assertRaises(ValueError, u"{0:=s}".format, u'') |
|
37301
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1110 |
|
45391
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1111 # test combining string and unicode |
|
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1112 self.assertEqual(u"foo{0}".format('bar'), u'foobar') |
|
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1113 # This will try to convert the argument from unicode to str, which |
|
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1114 # will succeed |
|
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1115 self.assertEqual("foo{0}".format(u'bar'), 'foobar') |
|
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1116 # This will try to convert the argument from unicode to str, which |
|
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1117 # will fail |
|
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1118 self.assertRaises(UnicodeEncodeError, "foo{0}".format, u'\u1000bar') |
|
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1119 |
|
48117
a94f136b5283
Correct a crash when two successive unicode allocations fail with a MemoryError:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48070
diff
changeset
|
1120 def test_raiseMemError(self): |
|
a94f136b5283
Correct a crash when two successive unicode allocations fail with a MemoryError:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48070
diff
changeset
|
1121 # Ensure that the freelist contains a consistent object, even |
|
a94f136b5283
Correct a crash when two successive unicode allocations fail with a MemoryError:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48070
diff
changeset
|
1122 # when a string allocation fails with a MemoryError. |
|
a94f136b5283
Correct a crash when two successive unicode allocations fail with a MemoryError:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48070
diff
changeset
|
1123 # This used to crash the interpreter, |
|
a94f136b5283
Correct a crash when two successive unicode allocations fail with a MemoryError:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48070
diff
changeset
|
1124 # or leak references when the number was smaller. |
|
49031
433220a60a8d
#3601: test_unicode.test_raiseMemError fails in UCS4
Antoine Pitrou <solipsis@pitrou.net>
parents:
48268
diff
changeset
|
1125 charwidth = 4 if sys.maxunicode >= 0x10000 else 2 |
|
433220a60a8d
#3601: test_unicode.test_raiseMemError fails in UCS4
Antoine Pitrou <solipsis@pitrou.net>
parents:
48268
diff
changeset
|
1126 # Note: sys.maxsize is half of the actual max allocation because of |
|
433220a60a8d
#3601: test_unicode.test_raiseMemError fails in UCS4
Antoine Pitrou <solipsis@pitrou.net>
parents:
48268
diff
changeset
|
1127 # the signedness of Py_ssize_t. |
|
433220a60a8d
#3601: test_unicode.test_raiseMemError fails in UCS4
Antoine Pitrou <solipsis@pitrou.net>
parents:
48268
diff
changeset
|
1128 alloc = lambda: u"a" * (sys.maxsize // charwidth * 2) |
|
48268
d7d7139d5840
#3556: test_raiseMemError consumes an insane amount of memory
Antoine Pitrou <solipsis@pitrou.net>
parents:
48117
diff
changeset
|
1129 self.assertRaises(MemoryError, alloc) |
|
d7d7139d5840
#3556: test_raiseMemError consumes an insane amount of memory
Antoine Pitrou <solipsis@pitrou.net>
parents:
48117
diff
changeset
|
1130 self.assertRaises(MemoryError, alloc) |
|
48117
a94f136b5283
Correct a crash when two successive unicode allocations fail with a MemoryError:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48070
diff
changeset
|
1131 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1132 def test_main(): |
|
41534
6c4d7678af5e
Standardize on test.test_support.run_unittest() (as opposed to a mix of run_unittest() and run_suite()). Also, add functionality to run_unittest() that admits usage of unittest.TestLoader.loadTestsFromModule().
Collin Winter <collinw@gmail.com>
parents:
39621
diff
changeset
|
1133 test_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
|
1134 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1135 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
|
1136 test_main() |
