Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_unicode.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 0cd197f13400 |
| children | 21fb1767e185 |
| rev | line source |
|---|---|
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 """ Test script for the Unicode implementation. |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 Written by Marc-Andre Lemburg (mal@lemburg.com). |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
15957
c1a8deb15f0e
This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents:
15910
diff
changeset
|
7 """#" |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
8 import sys |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
9 import struct |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
10 import codecs |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
11 import unittest |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
12 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
|
13 |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
14 # decorator to skip tests on narrow builds |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
15 requires_wide_build = unittest.skipIf(sys.maxunicode == 65535, |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
16 'requires wide build') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
17 |
|
35938
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
18 # 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
|
19 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
|
20 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
|
21 return 42 # not a tuple |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
22 def 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
|
23 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
|
24 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
|
25 return (42, 42) # no unicode |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 else: |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
33 return None |
|
bb80b8f393ef
Move registration of the codec search function to the module scope
Neal Norwitz <nnorwitz@gmail.com>
parents:
35331
diff
changeset
|
34 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
|
35 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
36 class UnicodeTest( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
37 string_tests.CommonTest, |
|
33298
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
38 string_tests.MixinStrUnicodeUserStringTest, |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
39 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
|
40 ): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
41 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
|
42 |
|
64708
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
43 def assertEqual(self, first, second, msg=None): |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
44 # strict assertEqual method: reject implicit bytes/unicode equality |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
45 super(UnicodeTest, self).assertEqual(first, second, msg) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
46 if isinstance(first, unicode) or isinstance(second, unicode): |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
47 self.assertIsInstance(first, unicode) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
48 self.assertIsInstance(second, unicode) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
49 elif isinstance(first, str) or isinstance(second, str): |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
50 self.assertIsInstance(first, str) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
51 self.assertIsInstance(second, str) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
52 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 self.assertEqual(realresult, result) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
57 self.assertTrue(type(realresult) is type(result)) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
58 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
59 # 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
|
60 # 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 self.assertEqual(realresult, result) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
69 self.assertTrue(object is not realresult) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 |
|
30653
3b47d6057151
Fix for SF bug [ 817156 ] invalid \U escape gives 0=length unistr.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30059
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
78 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
|
79 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
|
80 # 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 latin1repr = ( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
95 "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
|
96 "\\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
|
97 "\\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
|
98 "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
|
99 "\\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
|
100 "\\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
|
101 "\\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
|
102 "\\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
|
103 "\\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
|
104 "\\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
|
105 "\\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
|
106 "\\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
|
107 "\\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
|
108 "\\xfe\\xff'") |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
109 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
|
110 self.assertEqual(testrepr, latin1repr) |
|
39621
e8a65bbd6a29
Patch #1541585: fix buffer overrun when performing repr() on
Neal Norwitz <nnorwitz@gmail.com>
parents:
38096
diff
changeset
|
111 # 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
|
112 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
|
113 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
|
114 |
|
20017
08446a986a56
Test basic functioning of unicode repr(). (If this breaks Jython,
Guido van Rossum <guido@python.org>
parents:
19999
diff
changeset
|
115 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
116 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
|
117 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
|
118 # 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 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
|
133 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
134 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
|
135 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
|
136 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
137 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
|
138 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
|
139 # 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
|
140 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
|
141 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
|
142 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
|
143 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
144 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
|
145 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
|
146 # 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
157 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
|
158 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
|
159 # 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
172 def test_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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
180 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
|
181 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
|
182 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
183 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
|
184 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
|
185 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
186 # Mixed arguments |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 |
|
27304
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_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
|
192 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
|
193 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
194 # mixed arguments |
|
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'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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
207 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
|
208 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
|
209 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
210 # 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
|
211 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
|
212 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
|
213 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
214 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
|
215 # Comparisons: |
|
64708
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
216 self.assertTrue(u'abc' == 'abc') |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
217 self.assertTrue('abc' == u'abc') |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
218 self.assertTrue(u'abc' == u'abc') |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
219 self.assertTrue(u'abcd' > 'abc') |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
220 self.assertTrue('abcd' > u'abc') |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
221 self.assertTrue(u'abcd' > u'abc') |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
222 self.assertTrue(u'abc' < 'abcd') |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
223 self.assertTrue('abc' < u'abcd') |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
224 self.assertTrue(u'abc' < u'abcd') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
225 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
226 if 0: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
227 # 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
|
228 # 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
|
229 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
230 # No surrogates, no fixup required. |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
231 self.assertTrue(u'\u0061' < u'\u20ac') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
232 # Non surrogate below surrogate value, no fixup required |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
233 self.assertTrue(u'\u0061' < u'\ud800\udc02') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
234 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
235 # 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
|
236 def test_lecmp(s, s2): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
237 self.assertTrue(s < s2) |
|
13410
5157eb7be20d
Tests for new surrogate support in the UTF-8 codec. By Bill Tutt.
Marc-André Lemburg <mal@egenix.com>
parents:
13400
diff
changeset
|
238 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
239 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
|
240 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
|
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\udc01' |
|
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\udc01' |
|
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\udc01' |
|
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\udd01' |
|
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\udd01' |
|
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\udd01' |
|
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\udd01' |
|
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) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
273 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
|
274 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
|
275 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
276 # Surrogates on both sides, no fixup required |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54267
diff
changeset
|
277 self.assertTrue(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
|
278 |
|
71869
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
279 def test_capitalize(self): |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
280 string_tests.CommonTest.test_capitalize(self) |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
281 # check that titlecased chars are lowered correctly |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
282 # \u1ffc is the titlecased char |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
283 self.checkequal(u'\u1ffc\u1ff3\u1ff3\u1ff3', |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
284 u'\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize') |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
285 # check with cased non-letter chars |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
286 self.checkequal(u'\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
287 u'\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize') |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
288 self.checkequal(u'\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
289 u'\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize') |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
290 self.checkequal(u'\u2160\u2171\u2172', |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
291 u'\u2160\u2161\u2162', 'capitalize') |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
292 self.checkequal(u'\u2160\u2171\u2172', |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
293 u'\u2170\u2171\u2172', 'capitalize') |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
294 # check with Ll chars with no upper - nothing changes here |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
295 self.checkequal(u'\u019b\u1d00\u1d86\u0221\u1fb7', |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
296 u'\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize') |
|
d3816fa1bcdf
#12266: move the tests in test_unicode.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69562
diff
changeset
|
297 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
298 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
|
299 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
|
300 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
|
301 |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
302 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
303 def test_islower_non_bmp(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
304 # non-BMP, uppercase |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
305 self.assertFalse(u'\U00010401'.islower()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
306 self.assertFalse(u'\U00010427'.islower()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
307 # non-BMP, lowercase |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
308 self.assertTrue(u'\U00010429'.islower()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
309 self.assertTrue(u'\U0001044E'.islower()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
310 # non-BMP, non-cased |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
311 self.assertFalse(u'\U0001F40D'.islower()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
312 self.assertFalse(u'\U0001F46F'.islower()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
313 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
314 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
|
315 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
|
316 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
|
317 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
|
318 |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
319 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
320 def test_isupper_non_bmp(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
321 # non-BMP, uppercase |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
322 self.assertTrue(u'\U00010401'.isupper()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
323 self.assertTrue(u'\U00010427'.isupper()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
324 # non-BMP, lowercase |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
325 self.assertFalse(u'\U00010429'.isupper()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
326 self.assertFalse(u'\U0001044E'.isupper()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
327 # non-BMP, non-cased |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
328 self.assertFalse(u'\U0001F40D'.isupper()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
329 self.assertFalse(u'\U0001F46F'.isupper()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
330 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
331 def test_istitle(self): |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
332 string_tests.MixinStrUnicodeUserStringTest.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
|
333 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
|
334 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
|
335 |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
336 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
337 def test_istitle_non_bmp(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
338 # non-BMP, uppercase + lowercase |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
339 self.assertTrue(u'\U00010401\U00010429'.istitle()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
340 self.assertTrue(u'\U00010427\U0001044E'.istitle()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
341 # apparently there are no titlecased (Lt) non-BMP chars in Unicode 6 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
342 for ch in [u'\U00010429', u'\U0001044E', u'\U0001F40D', u'\U0001F46F']: |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
343 self.assertFalse(ch.istitle(), '{!r} is not title'.format(ch)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
344 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
351 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
352 def test_isspace_non_bmp(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
353 # apparently there are no non-BMP spaces chars in Unicode 6 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
354 for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
355 u'\U0001F40D', u'\U0001F46F']: |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
356 self.assertFalse(ch.isspace(), '{!r} is not space.'.format(ch)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
357 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
358 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
359 def test_isalnum_non_bmp(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
360 for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
361 u'\U0001D7F6', u'\U000104A0', u'\U000104A0', u'\U0001F107']: |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
362 self.assertTrue(ch.isalnum(), '{!r} is alnum.'.format(ch)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
363 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
368 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
369 def test_isalpha_non_bmp(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
370 # non-BMP, cased |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
371 self.assertTrue(u'\U00010401'.isalpha()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
372 self.assertTrue(u'\U00010427'.isalpha()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
373 self.assertTrue(u'\U00010429'.isalpha()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
374 self.assertTrue(u'\U0001044E'.isalpha()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
375 # non-BMP, non-cased |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
376 self.assertFalse(u'\U0001F40D'.isalpha()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
377 self.assertFalse(u'\U0001F46F'.isalpha()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
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_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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
27797
diff
changeset
|
389 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
|
390 |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
391 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
392 def test_isdecimal_non_bmp(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
393 for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
394 u'\U0001F40D', u'\U0001F46F', u'\U00011065', u'\U0001F107']: |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
395 self.assertFalse(ch.isdecimal(), '{!r} is not decimal.'.format(ch)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
396 for ch in [u'\U0001D7F6', u'\U000104A0', u'\U000104A0']: |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
397 self.assertTrue(ch.isdecimal(), '{!r} is decimal.'.format(ch)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
398 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
399 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
|
400 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
|
401 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
|
402 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
|
403 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
|
404 |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
405 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
406 def test_isdigit_non_bmp(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
407 for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
408 u'\U0001F40D', u'\U0001F46F', u'\U00011065']: |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
409 self.assertFalse(ch.isdigit(), '{!r} is not a digit.'.format(ch)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
410 for ch in [u'\U0001D7F6', u'\U000104A0', u'\U000104A0', u'\U0001F107']: |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
411 self.assertTrue(ch.isdigit(), '{!r} is a digit.'.format(ch)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
412 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
413 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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 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
|
422 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
423 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
|
424 |
|
72038
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
425 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
426 def test_isnumeric_non_bmp(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
427 for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
428 u'\U0001F40D', u'\U0001F46F']: |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
429 self.assertFalse(ch.isnumeric(), '{!r} is not numeric.'.format(ch)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
430 for ch in [u'\U00010107', u'\U0001D7F6', u'\U00023b1b', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
431 u'\U000104A0', u'\U0001F107']: |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
432 self.assertTrue(ch.isnumeric(), '{!r} is numeric.'.format(ch)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
433 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
434 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
435 def test_surrogates(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
436 # this test actually passes on narrow too, but it's just by accident. |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
437 # Surrogates are seen as non-cased chars, so u'X\uD800X' is as |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
438 # uppercase as 'X X' |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
439 for s in (u'a\uD800b\uDFFF', u'a\uDFFFb\uD800', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
440 u'a\uD800b\uDFFFa', u'a\uDFFFb\uD800a'): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
441 self.assertTrue(s.islower()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
442 self.assertFalse(s.isupper()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
443 self.assertFalse(s.istitle()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
444 for s in (u'A\uD800B\uDFFF', u'A\uDFFFB\uD800', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
445 u'A\uD800B\uDFFFA', u'A\uDFFFB\uD800A'): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
446 self.assertFalse(s.islower()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
447 self.assertTrue(s.isupper()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
448 self.assertTrue(s.istitle()) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
449 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
450 for meth_name in ('islower', 'isupper', 'istitle'): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
451 meth = getattr(unicode, meth_name) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
452 for s in (u'\uD800', u'\uDFFF', u'\uD800\uD800', u'\uDFFF\uDFFF'): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
453 self.assertFalse(meth(s), '%r.%s() is False' % (s, meth_name)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
454 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
455 for meth_name in ('isalpha', 'isalnum', 'isdigit', 'isspace', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
456 'isdecimal', 'isnumeric'): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
457 meth = getattr(unicode, meth_name) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
458 for s in (u'\uD800', u'\uDFFF', u'\uD800\uD800', u'\uDFFF\uDFFF', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
459 u'a\uD800b\uDFFF', u'a\uDFFFb\uD800', |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
460 u'a\uD800b\uDFFFa', u'a\uDFFFb\uD800a'): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
461 self.assertFalse(meth(s), '%r.%s() is False' % (s, meth_name)) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
462 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
463 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
464 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
465 def test_lower(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
466 string_tests.CommonTest.test_lower(self) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
467 self.assertEqual(u'\U00010427'.lower(), u'\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
468 self.assertEqual(u'\U00010427\U00010427'.lower(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
469 u'\U0001044F\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
470 self.assertEqual(u'\U00010427\U0001044F'.lower(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
471 u'\U0001044F\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
472 self.assertEqual(u'X\U00010427x\U0001044F'.lower(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
473 u'x\U0001044Fx\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
474 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
475 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
476 def test_upper(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
477 string_tests.CommonTest.test_upper(self) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
478 self.assertEqual(u'\U0001044F'.upper(), u'\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
479 self.assertEqual(u'\U0001044F\U0001044F'.upper(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
480 u'\U00010427\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
481 self.assertEqual(u'\U00010427\U0001044F'.upper(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
482 u'\U00010427\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
483 self.assertEqual(u'X\U00010427x\U0001044F'.upper(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
484 u'X\U00010427X\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
485 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
486 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
487 def test_capitalize(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
488 string_tests.CommonTest.test_capitalize(self) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
489 self.assertEqual(u'\U0001044F'.capitalize(), u'\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
490 self.assertEqual(u'\U0001044F\U0001044F'.capitalize(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
491 u'\U00010427\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
492 self.assertEqual(u'\U00010427\U0001044F'.capitalize(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
493 u'\U00010427\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
494 self.assertEqual(u'\U0001044F\U00010427'.capitalize(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
495 u'\U00010427\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
496 self.assertEqual(u'X\U00010427x\U0001044F'.capitalize(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
497 u'X\U0001044Fx\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
498 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
499 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
500 def test_title(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
501 string_tests.MixinStrUnicodeUserStringTest.test_title(self) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
502 self.assertEqual(u'\U0001044F'.title(), u'\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
503 self.assertEqual(u'\U0001044F\U0001044F'.title(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
504 u'\U00010427\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
505 self.assertEqual(u'\U0001044F\U0001044F \U0001044F\U0001044F'.title(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
506 u'\U00010427\U0001044F \U00010427\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
507 self.assertEqual(u'\U00010427\U0001044F \U00010427\U0001044F'.title(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
508 u'\U00010427\U0001044F \U00010427\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
509 self.assertEqual(u'\U0001044F\U00010427 \U0001044F\U00010427'.title(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
510 u'\U00010427\U0001044F \U00010427\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
511 self.assertEqual(u'X\U00010427x\U0001044F X\U00010427x\U0001044F'.title(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
512 u'X\U0001044Fx\U0001044F X\U0001044Fx\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
513 |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
514 @requires_wide_build |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
515 def test_swapcase(self): |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
516 string_tests.CommonTest.test_swapcase(self) |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
517 self.assertEqual(u'\U0001044F'.swapcase(), u'\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
518 self.assertEqual(u'\U00010427'.swapcase(), u'\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
519 self.assertEqual(u'\U0001044F\U0001044F'.swapcase(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
520 u'\U00010427\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
521 self.assertEqual(u'\U00010427\U0001044F'.swapcase(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
522 u'\U0001044F\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
523 self.assertEqual(u'\U0001044F\U00010427'.swapcase(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
524 u'\U00010427\U0001044F') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
525 self.assertEqual(u'X\U00010427x\U0001044F'.swapcase(), |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
526 u'x\U0001044FX\U00010427') |
|
75a4941d4d61
#9200: backport tests but run them on wide builds only.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
71869
diff
changeset
|
527 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
528 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
|
529 # Testing Unicode contains method |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
530 self.assertIn('a', u'abdb') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
531 self.assertIn('a', u'bdab') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
532 self.assertIn('a', u'bdaba') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
533 self.assertIn('a', u'bdba') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
534 self.assertIn('a', u'bdba') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
535 self.assertIn(u'a', u'bdba') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
536 self.assertNotIn(u'a', u'bdb') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
537 self.assertNotIn(u'a', 'bdb') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
538 self.assertIn(u'a', 'bdba') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
539 self.assertIn(u'a', ('a',1,None)) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
540 self.assertIn(u'a', (1,None,'a')) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
541 self.assertIn(u'a', (1,None,u'a')) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
542 self.assertIn('a', ('a',1,None)) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
543 self.assertIn('a', (1,None,'a')) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
544 self.assertIn('a', (1,None,u'a')) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
545 self.assertNotIn('a', ('x',1,u'y')) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
546 self.assertNotIn('a', ('x',1,None)) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
547 self.assertNotIn(u'abcd', u'abcxxxx') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
548 self.assertIn(u'ab', u'abcd') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
549 self.assertIn('ab', u'abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
550 self.assertIn(u'ab', 'abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
551 self.assertIn(u'ab', (1,None,u'ab')) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
552 self.assertIn(u'', u'abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
553 self.assertIn('', u'abc') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
554 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
555 # 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
|
556 # 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
|
557 # someone has changed the default encoding |
|
57729
2b8f485b0d03
Issue #1680159: unicode coercion during an 'in' operation was masking
R. David Murray <rdmurray@bitdance.com>
parents:
56093
diff
changeset
|
558 self.assertRaises(UnicodeDecodeError, 'g\xe2teau'.__contains__, u'\xe2') |
|
2b8f485b0d03
Issue #1680159: unicode coercion during an 'in' operation was masking
R. David Murray <rdmurray@bitdance.com>
parents:
56093
diff
changeset
|
559 self.assertRaises(UnicodeDecodeError, u'g\xe2teau'.__contains__, '\xe2') |
|
24737
eaa87632b1e8
Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level.
Marc-André Lemburg <mal@egenix.com>
parents:
24703
diff
changeset
|
560 |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
561 self.assertIn(u'', '') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
562 self.assertIn('', u'') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
563 self.assertIn(u'', u'') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
564 self.assertIn(u'', 'abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
565 self.assertIn('', u'abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
566 self.assertIn(u'', u'abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
567 self.assertNotIn(u'\0', 'abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
568 self.assertNotIn('\0', u'abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
569 self.assertNotIn(u'\0', u'abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
570 self.assertIn(u'\0', '\0abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
571 self.assertIn('\0', u'\0abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
572 self.assertIn(u'\0', u'\0abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
573 self.assertIn(u'\0', 'abc\0') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
574 self.assertIn('\0', u'abc\0') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
575 self.assertIn(u'\0', u'abc\0') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
576 self.assertIn(u'a', '\0abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
577 self.assertIn('a', u'\0abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
578 self.assertIn(u'a', u'\0abc') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
579 self.assertIn(u'asdf', 'asdf') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
580 self.assertIn('asdf', u'asdf') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
581 self.assertIn(u'asdf', u'asdf') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
582 self.assertNotIn(u'asdf', 'asd') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
583 self.assertNotIn('asdf', u'asd') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
584 self.assertNotIn(u'asdf', u'asd') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
585 self.assertNotIn(u'asdf', '') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
586 self.assertNotIn('asdf', u'') |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58090
diff
changeset
|
587 self.assertNotIn(u'asdf', u'') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
588 |
|
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(TypeError, u"abc".__contains__) |
|
57729
2b8f485b0d03
Issue #1680159: unicode coercion during an 'in' operation was masking
R. David Murray <rdmurray@bitdance.com>
parents:
56093
diff
changeset
|
590 self.assertRaises(TypeError, u"abc".__contains__, object()) |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
591 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
592 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
|
593 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
|
594 # 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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 |
|
28478
8802de0da533
Fix PyString_Format() so that '%c' % u'a' returns u'a'
Walter Dörwald <walter@livinglogic.de>
parents:
28009
diff
changeset
|
606 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
|
607 self.assertRaises(OverflowError, u"%c".__mod__, (sys.maxunicode+1,)) |
|
63106
742fdf7f6540
Merged revisions 82980 via svnmerge from
Stefan Krah <stefan@bytereef.org>
parents:
62711
diff
changeset
|
608 self.assertRaises(ValueError, u"%.1\u1032f".__mod__, (1.0/3)) |
|
20563
9058e49c6c57
Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents:
20240
diff
changeset
|
609 |
|
59087
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
610 for num in range(0x00,0x80): |
|
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
611 char = chr(num) |
|
64708
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
612 self.assertEqual(u"%c" % char, unicode(char)) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
613 self.assertEqual(u"%c" % num, unicode(char)) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
614 self.assertTrue(char == u"%c" % char) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
615 self.assertTrue(char == u"%c" % num) |
|
59087
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
616 # Issue 7649 |
|
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
617 for num in range(0x80,0x100): |
|
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
618 uchar = unichr(num) |
|
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
619 self.assertEqual(uchar, u"%c" % num) # works only with ints |
|
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
620 self.assertEqual(uchar, u"%c" % uchar) # and unicode chars |
|
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
621 # the implicit decoding should fail for non-ascii chars |
|
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
622 self.assertRaises(UnicodeDecodeError, u"%c".__mod__, chr(num)) |
|
7780482a64da
Merged revisions 78392 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54268
diff
changeset
|
623 self.assertRaises(UnicodeDecodeError, u"%s".__mod__, chr(num)) |
|
20563
9058e49c6c57
Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents:
20240
diff
changeset
|
624 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
625 # 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 self.assertEqual('%s' % Wrapper(), u'\u1234') |
|
38096
5457ab9f8599
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
38055
diff
changeset
|
646 |
|
69562
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
647 def test_startswith_endswith_errors(self): |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
648 for meth in (u'foo'.startswith, u'foo'.endswith): |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
649 with self.assertRaises(UnicodeDecodeError): |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
650 meth('\xff') |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
651 with self.assertRaises(TypeError) as cm: |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
652 meth(['f']) |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
653 exc = str(cm.exception) |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
654 self.assertIn('unicode', exc) |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
655 self.assertIn('str', exc) |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
656 self.assertIn('tuple', exc) |
|
3ceeccbc2c3b
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Ezio Melotti
parents:
68256
diff
changeset
|
657 |
|
38055
fcc61835c6ac
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents:
37301
diff
changeset
|
658 @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
|
659 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
|
660 # 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
|
661 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
|
662 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
663 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
|
664 # 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
|
665 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
666 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
667 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
|
668 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
|
669 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
670 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
671 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
|
672 pass |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
18828
diff
changeset
|
673 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
674 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
675 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
|
676 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
|
677 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
678 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
679 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
680 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
|
681 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
|
682 ) |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
18828
diff
changeset
|
683 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
684 class UnicodeCompat: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
685 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
|
686 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
|
687 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
|
688 return self.x |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
18828
diff
changeset
|
689 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
690 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
691 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
|
692 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
|
693 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
694 class StringCompat: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
695 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
|
696 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
|
697 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
|
698 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
|
699 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
700 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
701 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
|
702 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
|
703 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
704 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
705 # 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
|
706 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
707 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
|
708 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
|
709 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
|
710 |
|
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
|
711 # %-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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
719 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
|
720 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
|
721 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
722 # 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
|
723 # 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
|
724 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
725 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
|
726 self.assertRaises( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
727 TypeError, |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
728 unicode, |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
729 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
|
730 'utf-8', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
731 'strict' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
732 ) |
|
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
|
733 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
734 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
735 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
|
736 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
|
737 ) |
|
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
|
738 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
739 if not sys.platform.startswith('java'): |
|
59432
e23cba03cc4b
Issue #7849: Now the utility ``check_warnings`` verifies if the warnings are
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59085
diff
changeset
|
740 with test_support.check_py3k_warnings(): |
|
63553
7c3b849d181a
Merged revisions 78758 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63106
diff
changeset
|
741 buf = buffer('character buffers are decoded to unicode') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
742 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
743 unicode( |
|
63553
7c3b849d181a
Merged revisions 78758 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63106
diff
changeset
|
744 buf, |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
745 'utf-8', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
746 'strict' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
747 ), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
748 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
|
749 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
750 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
751 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
|
752 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
753 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
|
754 utfTests = [ |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
755 (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
|
756 (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
|
757 (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
|
758 (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
|
759 (u'+', '+-'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
760 (u'+-', '+--'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
761 (u'+?', '+-?'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
762 (u'\?', '+AFw?'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
763 (u'+?', '+-?'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
764 (ur'\\?', '+AFwAXA?'), |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
765 (ur'\\\?', '+AFwAXABc?'), |
|
53740
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
766 (ur'++--', '+-+---'), |
|
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
767 (u'\U000abcde', '+2m/c3g-'), # surrogate pairs |
|
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
768 (u'/', '/'), |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
769 ] |
| 12051 | 770 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
771 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
|
772 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
|
773 |
|
73554
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
774 # Unpaired surrogates are passed through |
|
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
775 self.assertEqual(u'\uD801'.encode('utf-7'), '+2AE-') |
|
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
776 self.assertEqual(u'\uD801x'.encode('utf-7'), '+2AE-x') |
|
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
777 self.assertEqual(u'\uDC01'.encode('utf-7'), '+3AE-') |
|
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
778 self.assertEqual(u'\uDC01x'.encode('utf-7'), '+3AE-x') |
|
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
779 self.assertEqual('+2AE-'.decode('utf-7'), u'\uD801') |
|
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
780 self.assertEqual('+2AE-x'.decode('utf-7'), u'\uD801x') |
|
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
781 self.assertEqual('+3AE-'.decode('utf-7'), u'\uDC01') |
|
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
782 self.assertEqual('+3AE-x'.decode('utf-7'), u'\uDC01x') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
783 |
|
73554
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
784 self.assertEqual(u'\uD801\U000abcde'.encode('utf-7'), '+2AHab9ze-') |
|
050772822bde
Issue #13333: The UTF-7 decoder now accepts lone surrogates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72038
diff
changeset
|
785 self.assertEqual('+2AHab9ze-'.decode('utf-7'), u'\uD801\U000abcde') |
| 12331 | 786 |
|
53740
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
787 # Direct encoded characters |
|
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
788 set_d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'(),-./:?" |
|
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
789 # Optional direct characters |
|
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
790 set_o = '!"#$%&*;<=>@[]^_`{|}' |
|
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
791 for c in set_d: |
|
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
792 self.assertEqual(c.encode('utf7'), c.encode('ascii')) |
|
64708
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
793 self.assertEqual(c.encode('ascii').decode('utf7'), unicode(c)) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
794 self.assertTrue(c == c.encode('ascii').decode('utf7')) |
|
53740
12d8fd499722
Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal sequences.
Antoine Pitrou <solipsis@pitrou.net>
parents:
52161
diff
changeset
|
795 for c in set_o: |
|
64708
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
796 self.assertEqual(c.encode('ascii').decode('utf7'), unicode(c)) |
|
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
797 self.assertTrue(c == c.encode('ascii').decode('utf7')) |
|
48072
b71d76bf4506
#2242: utf7 decoding crashes on bogus input on some Windows/MSVC versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
46060
diff
changeset
|
798 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
799 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
|
800 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 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
|
806 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
807 (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
|
808 '\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
|
809 ) |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
810 self.assertEqual( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
811 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
|
812 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
|
813 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
|
814 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
|
815 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
|
816 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
|
817 '\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
|
818 '\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
|
819 '\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
|
820 '\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
|
821 '\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
|
822 '\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
|
823 '\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
|
824 '\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
|
825 '\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
|
826 '\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
|
827 ) |
|
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
|
828 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
829 # UTF-8 specific decoding tests |
|
64701
28e6a41c5ba0
Merged revisions 84470-84471,84566-84567,84759 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
63102
diff
changeset
|
830 self.assertEqual(unicode('\xf0\xa3\x91\x96', 'utf-8'), u'\U00023456') |
|
28e6a41c5ba0
Merged revisions 84470-84471,84566-84567,84759 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
63102
diff
changeset
|
831 self.assertEqual(unicode('\xf0\x90\x80\x82', 'utf-8'), u'\U00010002') |
|
28e6a41c5ba0
Merged revisions 84470-84471,84566-84567,84759 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
63102
diff
changeset
|
832 self.assertEqual(unicode('\xe2\x82\xac', 'utf-8'), u'\u20ac') |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
833 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
834 # 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
|
835 # * 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
|
836 # UTF8_ERROR cases in PyUnicode_DecodeUTF8 |
| 12051 | 837 |
|
62711
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
838 def test_utf8_decode_valid_sequences(self): |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
839 sequences = [ |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
840 # single byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
841 ('\x00', u'\x00'), ('a', u'a'), ('\x7f', u'\x7f'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
842 # 2 bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
843 ('\xc2\x80', u'\x80'), ('\xdf\xbf', u'\u07ff'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
844 # 3 bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
845 ('\xe0\xa0\x80', u'\u0800'), ('\xed\x9f\xbf', u'\ud7ff'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
846 ('\xee\x80\x80', u'\uE000'), ('\xef\xbf\xbf', u'\uffff'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
847 # 4 bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
848 ('\xF0\x90\x80\x80', u'\U00010000'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
849 ('\xf4\x8f\xbf\xbf', u'\U0010FFFF') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
850 ] |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
851 for seq, res in sequences: |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
852 self.assertEqual(seq.decode('utf-8'), res) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
853 |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
854 for ch in map(unichr, range(0, sys.maxunicode)): |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
855 self.assertEqual(ch, ch.encode('utf-8').decode('utf-8')) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
856 |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
857 def test_utf8_decode_invalid_sequences(self): |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
858 # continuation bytes in a sequence of 2, 3, or 4 bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
859 continuation_bytes = map(chr, range(0x80, 0xC0)) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
860 # start bytes of a 2-byte sequence equivalent to codepoints < 0x7F |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
861 invalid_2B_seq_start_bytes = map(chr, range(0xC0, 0xC2)) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
862 # start bytes of a 4-byte sequence equivalent to codepoints > 0x10FFFF |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
863 invalid_4B_seq_start_bytes = map(chr, range(0xF5, 0xF8)) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
864 invalid_start_bytes = ( |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
865 continuation_bytes + invalid_2B_seq_start_bytes + |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
866 invalid_4B_seq_start_bytes + map(chr, range(0xF7, 0x100)) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
867 ) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
868 |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
869 for byte in invalid_start_bytes: |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
870 self.assertRaises(UnicodeDecodeError, byte.decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
871 |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
872 for sb in invalid_2B_seq_start_bytes: |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
873 for cb in continuation_bytes: |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
874 self.assertRaises(UnicodeDecodeError, (sb+cb).decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
875 |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
876 for sb in invalid_4B_seq_start_bytes: |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
877 for cb1 in continuation_bytes[:3]: |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
878 for cb3 in continuation_bytes[:3]: |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
879 self.assertRaises(UnicodeDecodeError, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
880 (sb+cb1+'\x80'+cb3).decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
881 |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
882 for cb in map(chr, range(0x80, 0xA0)): |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
883 self.assertRaises(UnicodeDecodeError, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
884 ('\xE0'+cb+'\x80').decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
885 self.assertRaises(UnicodeDecodeError, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
886 ('\xE0'+cb+'\xBF').decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
887 # XXX: surrogates shouldn't be valid UTF-8! |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
888 # see http://www.unicode.org/versions/Unicode5.2.0/ch03.pdf |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
889 # (table 3-7) and http://www.rfc-editor.org/rfc/rfc3629.txt |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
890 #for cb in map(chr, range(0xA0, 0xC0)): |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
891 #self.assertRaises(UnicodeDecodeError, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
892 #('\xED'+cb+'\x80').decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
893 #self.assertRaises(UnicodeDecodeError, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
894 #('\xED'+cb+'\xBF').decode, 'utf-8') |
|
68052
dc8626e08577
Python 2 can encode/decode surrogates to utf-8. Add a test for this.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65662
diff
changeset
|
895 # but since they are valid on Python 2 add a test for that: |
|
dc8626e08577
Python 2 can encode/decode surrogates to utf-8. Add a test for this.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65662
diff
changeset
|
896 for cb, surrogate in zip(map(chr, range(0xA0, 0xC0)), |
|
dc8626e08577
Python 2 can encode/decode surrogates to utf-8. Add a test for this.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65662
diff
changeset
|
897 map(unichr, range(0xd800, 0xe000, 64))): |
|
dc8626e08577
Python 2 can encode/decode surrogates to utf-8. Add a test for this.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65662
diff
changeset
|
898 encoded = '\xED'+cb+'\x80' |
|
dc8626e08577
Python 2 can encode/decode surrogates to utf-8. Add a test for this.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65662
diff
changeset
|
899 self.assertEqual(encoded.decode('utf-8'), surrogate) |
|
dc8626e08577
Python 2 can encode/decode surrogates to utf-8. Add a test for this.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65662
diff
changeset
|
900 self.assertEqual(surrogate.encode('utf-8'), encoded) |
|
dc8626e08577
Python 2 can encode/decode surrogates to utf-8. Add a test for this.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65662
diff
changeset
|
901 |
|
62711
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
902 for cb in map(chr, range(0x80, 0x90)): |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
903 self.assertRaises(UnicodeDecodeError, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
904 ('\xF0'+cb+'\x80\x80').decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
905 self.assertRaises(UnicodeDecodeError, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
906 ('\xF0'+cb+'\xBF\xBF').decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
907 for cb in map(chr, range(0x90, 0xC0)): |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
908 self.assertRaises(UnicodeDecodeError, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
909 ('\xF4'+cb+'\x80\x80').decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
910 self.assertRaises(UnicodeDecodeError, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
911 ('\xF4'+cb+'\xBF\xBF').decode, 'utf-8') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
912 |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
913 def test_issue8271(self): |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
914 # Issue #8271: during the decoding of an invalid UTF-8 byte sequence, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
915 # only the start byte and the continuation byte(s) are now considered |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
916 # invalid, instead of the number of bytes specified by the start byte. |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
917 # See http://www.unicode.org/versions/Unicode5.2.0/ch03.pdf (page 95, |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
918 # table 3-8, Row 2) for more information about the algorithm used. |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
919 FFFD = u'\ufffd' |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
920 sequences = [ |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
921 # invalid start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
922 ('\x80', FFFD), # continuation byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
923 ('\x80\x80', FFFD*2), # 2 continuation bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
924 ('\xc0', FFFD), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
925 ('\xc0\xc0', FFFD*2), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
926 ('\xc1', FFFD), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
927 ('\xc1\xc0', FFFD*2), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
928 ('\xc0\xc1', FFFD*2), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
929 # with start byte of a 2-byte sequence |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
930 ('\xc2', FFFD), # only the start byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
931 ('\xc2\xc2', FFFD*2), # 2 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
932 ('\xc2\xc2\xc2', FFFD*3), # 2 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
933 ('\xc2\x41', FFFD+'A'), # invalid continuation byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
934 # with start byte of a 3-byte sequence |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
935 ('\xe1', FFFD), # only the start byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
936 ('\xe1\xe1', FFFD*2), # 2 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
937 ('\xe1\xe1\xe1', FFFD*3), # 3 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
938 ('\xe1\xe1\xe1\xe1', FFFD*4), # 4 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
939 ('\xe1\x80', FFFD), # only 1 continuation byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
940 ('\xe1\x41', FFFD+'A'), # invalid continuation byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
941 ('\xe1\x41\x80', FFFD+'A'+FFFD), # invalid cb followed by valid cb |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
942 ('\xe1\x41\x41', FFFD+'AA'), # 2 invalid continuation bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
943 ('\xe1\x80\x41', FFFD+'A'), # only 1 valid continuation byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
944 ('\xe1\x80\xe1\x41', FFFD*2+'A'), # 1 valid and the other invalid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
945 ('\xe1\x41\xe1\x80', FFFD+'A'+FFFD), # 1 invalid and the other valid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
946 # with start byte of a 4-byte sequence |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
947 ('\xf1', FFFD), # only the start byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
948 ('\xf1\xf1', FFFD*2), # 2 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
949 ('\xf1\xf1\xf1', FFFD*3), # 3 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
950 ('\xf1\xf1\xf1\xf1', FFFD*4), # 4 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
951 ('\xf1\xf1\xf1\xf1\xf1', FFFD*5), # 5 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
952 ('\xf1\x80', FFFD), # only 1 continuation bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
953 ('\xf1\x80\x80', FFFD), # only 2 continuation bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
954 ('\xf1\x80\x41', FFFD+'A'), # 1 valid cb and 1 invalid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
955 ('\xf1\x80\x41\x41', FFFD+'AA'), # 1 valid cb and 1 invalid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
956 ('\xf1\x80\x80\x41', FFFD+'A'), # 2 valid cb and 1 invalid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
957 ('\xf1\x41\x80', FFFD+'A'+FFFD), # 1 invalid cv and 1 valid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
958 ('\xf1\x41\x80\x80', FFFD+'A'+FFFD*2), # 1 invalid cb and 2 invalid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
959 ('\xf1\x41\x80\x41', FFFD+'A'+FFFD+'A'), # 2 invalid cb and 1 invalid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
960 ('\xf1\x41\x41\x80', FFFD+'AA'+FFFD), # 1 valid cb and 1 invalid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
961 ('\xf1\x41\xf1\x80', FFFD+'A'+FFFD), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
962 ('\xf1\x41\x80\xf1', FFFD+'A'+FFFD*2), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
963 ('\xf1\xf1\x80\x41', FFFD*2+'A'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
964 ('\xf1\x41\xf1\xf1', FFFD+'A'+FFFD*2), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
965 # with invalid start byte of a 4-byte sequence (rfc2279) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
966 ('\xf5', FFFD), # only the start byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
967 ('\xf5\xf5', FFFD*2), # 2 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
968 ('\xf5\x80', FFFD*2), # only 1 continuation byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
969 ('\xf5\x80\x80', FFFD*3), # only 2 continuation byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
970 ('\xf5\x80\x80\x80', FFFD*4), # 3 continuation bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
971 ('\xf5\x80\x41', FFFD*2+'A'), # 1 valid cb and 1 invalid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
972 ('\xf5\x80\x41\xf5', FFFD*2+'A'+FFFD), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
973 ('\xf5\x41\x80\x80\x41', FFFD+'A'+FFFD*2+'A'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
974 # with invalid start byte of a 5-byte sequence (rfc2279) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
975 ('\xf8', FFFD), # only the start byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
976 ('\xf8\xf8', FFFD*2), # 2 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
977 ('\xf8\x80', FFFD*2), # only one continuation byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
978 ('\xf8\x80\x41', FFFD*2 + 'A'), # 1 valid cb and 1 invalid |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
979 ('\xf8\x80\x80\x80\x80', FFFD*5), # invalid 5 bytes seq with 5 bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
980 # with invalid start byte of a 6-byte sequence (rfc2279) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
981 ('\xfc', FFFD), # only the start byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
982 ('\xfc\xfc', FFFD*2), # 2 start bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
983 ('\xfc\x80\x80', FFFD*3), # only 2 continuation bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
984 ('\xfc\x80\x80\x80\x80\x80', FFFD*6), # 6 continuation bytes |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
985 # invalid start byte |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
986 ('\xfe', FFFD), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
987 ('\xfe\x80\x80', FFFD*3), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
988 # other sequences |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
989 ('\xf1\x80\x41\x42\x43', u'\ufffd\x41\x42\x43'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
990 ('\xf1\x80\xff\x42\x43', u'\ufffd\ufffd\x42\x43'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
991 ('\xf1\x80\xc2\x81\x43', u'\ufffd\x81\x43'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
992 ('\x61\xF1\x80\x80\xE1\x80\xC2\x62\x80\x63\x80\xBF\x64', |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
993 u'\x61\uFFFD\uFFFD\uFFFD\x62\uFFFD\x63\uFFFD\uFFFD\x64'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
994 ] |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
995 for n, (seq, res) in enumerate(sequences): |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
996 self.assertRaises(UnicodeDecodeError, seq.decode, 'utf-8', 'strict') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
997 self.assertEqual(seq.decode('utf-8', 'replace'), res) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
998 self.assertEqual((seq+'b').decode('utf-8', 'replace'), res+'b') |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
999 self.assertEqual(seq.decode('utf-8', 'ignore'), |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
1000 res.replace(u'\uFFFD', '')) |
|
4de13feaea01
Merged revisions 81758-81759 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62176
diff
changeset
|
1001 |
|
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
|
1002 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
|
1003 # 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
|
1004 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
|
1005 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1006 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
|
1007 # 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
|
1008 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
|
1009 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
|
1010 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
|
1011 self.assertEqual(u'Andr\202 x'.encode('ascii','replace'), "Andr? x") |
|
56093
f64c0eb8cc62
add keyword arguments support to str/unicode encode and decode #6300
Benjamin Peterson <benjamin@python.org>
parents:
55002
diff
changeset
|
1012 self.assertEqual(u'Andr\202 x'.encode('ascii', 'replace'), |
|
f64c0eb8cc62
add keyword arguments support to str/unicode encode and decode #6300
Benjamin Peterson <benjamin@python.org>
parents:
55002
diff
changeset
|
1013 u'Andr\202 x'.encode('ascii', errors='replace')) |
|
f64c0eb8cc62
add keyword arguments support to str/unicode encode and decode #6300
Benjamin Peterson <benjamin@python.org>
parents:
55002
diff
changeset
|
1014 self.assertEqual(u'Andr\202 x'.encode('ascii', 'ignore'), |
|
f64c0eb8cc62
add keyword arguments support to str/unicode encode and decode #6300
Benjamin Peterson <benjamin@python.org>
parents:
55002
diff
changeset
|
1015 u'Andr\202 x'.encode(encoding='ascii', errors='ignore')) |
| 12051 | 1016 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1017 # 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
|
1018 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
|
1019 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
|
1020 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
|
1021 self.assertEqual(unicode('Andr\202 x','ascii','replace'), u'Andr\uFFFD x') |
|
56093
f64c0eb8cc62
add keyword arguments support to str/unicode encode and decode #6300
Benjamin Peterson <benjamin@python.org>
parents:
55002
diff
changeset
|
1022 self.assertEqual(u'abcde'.decode('ascii', 'ignore'), |
|
f64c0eb8cc62
add keyword arguments support to str/unicode encode and decode #6300
Benjamin Peterson <benjamin@python.org>
parents:
55002
diff
changeset
|
1023 u'abcde'.decode('ascii', errors='ignore')) |
|
f64c0eb8cc62
add keyword arguments support to str/unicode encode and decode #6300
Benjamin Peterson <benjamin@python.org>
parents:
55002
diff
changeset
|
1024 self.assertEqual(u'abcde'.decode('ascii', 'replace'), |
|
f64c0eb8cc62
add keyword arguments support to str/unicode encode and decode #6300
Benjamin Peterson <benjamin@python.org>
parents:
55002
diff
changeset
|
1025 u'abcde'.decode(encoding='ascii', errors='replace')) |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1026 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1027 # 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
|
1028 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
|
1029 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1030 # 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
|
1031 self.assertRaises(UnicodeError, "\\".decode, "unicode-escape") |
| 12051 | 1032 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1033 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
|
1034 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
|
1035 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
|
1036 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
|
1037 # 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
|
1038 import imp |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1039 self.assertRaises( |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1040 ImportError, |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1041 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
|
1042 "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
|
1043 [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
|
1044 ) |
|
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
|
1045 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1046 # 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
|
1047 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
|
1048 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1049 # 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
|
1050 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
|
1051 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1052 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
|
1053 # Encoding |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1054 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
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 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
|
1061 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1062 # 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
|
1063 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
|
1064 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
|
1065 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
|
1066 '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
|
1067 '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
|
1068 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
|
1069 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1070 # 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
|
1071 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
|
1072 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
|
1073 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
|
1074 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
|
1075 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1076 # 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
|
1077 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
|
1078 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
|
1079 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
|
1080 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
|
1081 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1082 # 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
|
1083 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
|
1084 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
|
1085 #'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
|
1086 '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
|
1087 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
|
1088 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1089 # 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
|
1090 # 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
|
1091 # 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
|
1092 # 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
|
1093 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
|
1094 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
|
1095 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
|
1096 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1097 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
|
1098 # 0-127 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1099 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
|
1100 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
|
1101 'cp037', 'cp1026', |
|
61884
c56fb63c648f
#8016: add the CP858 codec (approved by Benjamin). (Also add CP720 to the tests, it was missing there.)
Georg Brandl <georg@python.org>
parents:
59897
diff
changeset
|
1102 'cp437', 'cp500', 'cp720', 'cp737', 'cp775', 'cp850', |
|
c56fb63c648f
#8016: add the CP858 codec (approved by Benjamin). (Also add CP720 to the tests, it was missing there.)
Georg Brandl <georg@python.org>
parents:
59897
diff
changeset
|
1103 'cp852', 'cp855', 'cp858', 'cp860', 'cp861', 'cp862', |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1104 '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
|
1105 '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
|
1106 '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
|
1107 '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
|
1108 '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
|
1109 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1110 '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
|
1111 '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
|
1112 '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
|
1113 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1114 '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
|
1115 '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
|
1116 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1117 ### 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
|
1118 #'cp424', |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1119 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1120 ### 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
|
1121 #'cp875' |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1122 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1123 ): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1124 self.assertEqual(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
|
1125 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1126 # 128-255 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1127 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
|
1128 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
|
1129 'cp037', 'cp1026', |
|
61884
c56fb63c648f
#8016: add the CP858 codec (approved by Benjamin). (Also add CP720 to the tests, it was missing there.)
Georg Brandl <georg@python.org>
parents:
59897
diff
changeset
|
1130 'cp437', 'cp500', 'cp720', 'cp737', 'cp775', 'cp850', |
|
c56fb63c648f
#8016: add the CP858 codec (approved by Benjamin). (Also add CP720 to the tests, it was missing there.)
Georg Brandl <georg@python.org>
parents:
59897
diff
changeset
|
1131 'cp852', 'cp855', 'cp858', 'cp860', 'cp861', 'cp862', |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1132 '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
|
1133 '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
|
1134 '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
|
1135 '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
|
1136 '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
|
1137 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1138 ### 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
|
1139 #'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
|
1140 #'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
|
1141 #'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
|
1142 #'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
|
1143 #'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
|
1144 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1145 ### 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
|
1146 #'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
|
1147 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1148 ): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1149 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
|
1150 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1151 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
|
1152 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
|
1153 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
|
1154 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
|
1155 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
|
1156 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
|
1157 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1158 def test_printing(self): |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1159 class BitBucket: |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1160 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
|
1161 pass |
|
24598
12e146171f3d
Committing patch #591250 which provides "str1 in str2" when str1 is a
Barry Warsaw <barry@python.org>
parents:
24538
diff
changeset
|
1162 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1163 out = BitBucket() |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1164 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
|
1165 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
|
1166 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
|
1167 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
|
1168 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
|
1169 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
|
1170 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
|
1171 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
|
1172 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
|
1173 |
|
29164
4d9017ef7b5f
Consider \U-escapes in raw-unicode-escape. Fixes #444514.
Martin v. Löwis <martin@v.loewis.de>
parents:
28917
diff
changeset
|
1174 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
|
1175 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
|
1176 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
|
1177 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
|
1178 |
|
46060
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1179 y = r'\U00100000' |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1180 x = y.decode("raw-unicode-escape").encode("raw-unicode-escape") |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1181 self.assertEqual(x, y) |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1182 y = r'\U00010000' |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1183 x = y.decode("raw-unicode-escape").encode("raw-unicode-escape") |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1184 self.assertEqual(x, y) |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1185 |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1186 try: |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1187 '\U11111111'.decode("raw-unicode-escape") |
|
46028
8710ba7fba2b
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45468
diff
changeset
|
1188 except UnicodeDecodeError as e: |
|
46060
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1189 self.assertEqual(e.start, 0) |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1190 self.assertEqual(e.end, 10) |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1191 else: |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1192 self.fail("Should have raised UnicodeDecodeError") |
|
42285d63755a
#1477: ur'\U0010FFFF' used to raise in narrow unicode builds.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42026
diff
changeset
|
1193 |
|
34931
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1194 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
|
1195 # 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
|
1196 class Foo0: |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1197 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1198 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1199 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1200 class Foo1: |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1201 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1202 return u"foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1203 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1204 class Foo2(object): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1205 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1206 return u"foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1207 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1208 class Foo3(object): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1209 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1210 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1211 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1212 class Foo4(str): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1213 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1214 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1215 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1216 class Foo5(unicode): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1217 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1218 return "foo" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1219 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1220 class Foo6(str): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1221 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1222 return "foos" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1223 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1224 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1225 return u"foou" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1226 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1227 class Foo7(unicode): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1228 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1229 return "foos" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1230 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1231 return u"foou" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1232 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1233 class Foo8(unicode): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1234 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
|
1235 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
|
1236 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1237 return self |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1238 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1239 class Foo9(unicode): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1240 def __str__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1241 return "string" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1242 def __unicode__(self): |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1243 return "not unicode" |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1244 |
|
9a1b1e1ae653
Make subclasses of int, long, complex, float, and unicode perform type
Brett Cannon <bcannon@gmail.com>
parents:
33298
diff
changeset
|
1245 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
|
1246 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
|
1247 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
|
1248 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
|
1249 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
|
1250 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
|
1251 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
|
1252 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
|
1253 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
|
1254 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
|
1255 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
|
1256 |
|
37301
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1257 def test_unicode_repr(self): |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1258 class s1: |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1259 def __repr__(self): |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1260 return '\\n' |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1261 |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1262 class s2: |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1263 def __repr__(self): |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1264 return u'\\n' |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1265 |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1266 self.assertEqual(repr(s1()), '\\n') |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1267 self.assertEqual(repr(s2()), '\\n') |
|
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1268 |
|
42005
2bd9417dacd5
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
39621
diff
changeset
|
1269 def test_expandtabs_overflows_gracefully(self): |
|
2bd9417dacd5
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
39621
diff
changeset
|
1270 # This test only affects 32-bit platforms because expandtabs can only take |
|
2bd9417dacd5
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
39621
diff
changeset
|
1271 # an int as the max value, not a 64-bit C long. If expandtabs is changed |
|
2bd9417dacd5
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
39621
diff
changeset
|
1272 # to take a 64-bit long, this test should apply to all platforms. |
| 42026 | 1273 if sys.maxint > (1 << 32) or struct.calcsize('P') != 4: |
|
42005
2bd9417dacd5
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
39621
diff
changeset
|
1274 return |
|
2bd9417dacd5
Prevent expandtabs() on string and unicode objects from causing a segfault when
Neal Norwitz <nnorwitz@gmail.com>
parents:
39621
diff
changeset
|
1275 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
|
1276 |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1277 def test__format__(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1278 def test(value, format, expected): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1279 # 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
|
1280 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
|
1281 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
|
1282 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1283 test(u'', u'', u'') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1284 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
|
1285 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
|
1286 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
|
1287 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
|
1288 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
|
1289 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
|
1290 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
|
1291 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
|
1292 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
|
1293 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
|
1294 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
|
1295 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
|
1296 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
|
1297 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
|
1298 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
|
1299 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
|
1300 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
|
1301 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
|
1302 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
|
1303 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
|
1304 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
|
1305 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
|
1306 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
|
1307 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
|
1308 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1309 # test mixing unicode and str |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1310 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
|
1311 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
|
1312 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1313 def test_format(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1314 self.assertEqual(u''.format(), u'') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1315 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
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 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
|
1321 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
|
1322 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1323 # examples from the PEP: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1324 import datetime |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1325 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
|
1326 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
|
1327 u"My name is Fred") |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1328 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
|
1329 u"My name is Fred :-{}") |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1330 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1331 # 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
|
1332 #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
|
1333 #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
|
1334 # "The year is 2007") |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1335 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1336 # 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
|
1337 class C: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1338 def __init__(self, x=100): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1339 self._x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1340 def __format__(self, spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1341 return spec |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1342 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1343 class D: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1344 def __init__(self, x): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1345 self.x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1346 def __format__(self, spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1347 return str(self.x) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1348 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1349 # 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
|
1350 class E: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1351 def __init__(self, x): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1352 self.x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1353 def __str__(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1354 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
|
1355 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1356 # 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
|
1357 class F: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1358 def __init__(self, x): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1359 self.x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1360 def __repr__(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1361 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
|
1362 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1363 # 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
|
1364 class G: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1365 def __init__(self, x): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1366 self.x = x |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1367 def __str__(self): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1368 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
|
1369 def __format__(self, format_spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1370 if format_spec == 'd': |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1371 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
|
1372 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
|
1373 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1374 # 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
|
1375 class H: |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1376 def __format__(self, format_spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1377 return 1.0 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1378 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1379 class I(datetime.date): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1380 def __format__(self, format_spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1381 return self.strftime(format_spec) |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1382 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1383 class J(int): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1384 def __format__(self, format_spec): |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1385 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
|
1386 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1387 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1388 self.assertEqual(u''.format(), u'') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1389 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
|
1390 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
|
1391 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
|
1392 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
|
1393 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
|
1394 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
|
1395 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
|
1396 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
|
1397 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
|
1398 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
|
1399 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
|
1400 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
|
1401 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
|
1402 self.assertEqual(u'{{'.format(), u'{') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1403 self.assertEqual(u'}}'.format(), u'}') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1404 self.assertEqual(u'{{}}'.format(), u'{}') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1405 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
|
1406 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
|
1407 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
|
1408 self.assertEqual(u'}}{{'.format(), u'}{') |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1409 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
|
1410 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1411 # weird field names |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1412 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
|
1413 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
|
1414 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
|
1415 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1416 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
|
1417 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
|
1418 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
|
1419 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
|
1420 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
|
1421 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
|
1422 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
|
1423 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1424 # strings |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1425 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
|
1426 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
|
1427 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
|
1428 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
|
1429 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
|
1430 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
|
1431 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
|
1432 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
|
1433 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
|
1434 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
|
1435 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
|
1436 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
|
1437 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
|
1438 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
|
1439 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
|
1440 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
|
1441 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
|
1442 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
|
1443 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
|
1444 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
|
1445 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
|
1446 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
|
1447 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
|
1448 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1449 # 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
|
1450 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
|
1451 |
|
64707
274a0bf46871
Check PendingDeprecationWarning after issue #7994.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64701
diff
changeset
|
1452 # !r and !s coercions |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1453 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
|
1454 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
|
1455 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
|
1456 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
|
1457 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
|
1458 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
|
1459 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
|
1460 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1461 # test fallback to object.__format__ |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1462 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
|
1463 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
|
1464 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
|
1465 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
|
1466 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
|
1467 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
|
1468 |
|
64707
274a0bf46871
Check PendingDeprecationWarning after issue #7994.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64701
diff
changeset
|
1469 msg = 'object.__format__ with a non-empty format string is deprecated' |
|
274a0bf46871
Check PendingDeprecationWarning after issue #7994.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64701
diff
changeset
|
1470 with test_support.check_warnings((msg, PendingDeprecationWarning)): |
|
274a0bf46871
Check PendingDeprecationWarning after issue #7994.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64701
diff
changeset
|
1471 self.assertEqual(u'{0:^10}'.format(E(u'data')), u' E(data) ') |
|
274a0bf46871
Check PendingDeprecationWarning after issue #7994.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64701
diff
changeset
|
1472 self.assertEqual(u'{0:^10s}'.format(E(u'data')), u' E(data) ') |
|
274a0bf46871
Check PendingDeprecationWarning after issue #7994.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64701
diff
changeset
|
1473 self.assertEqual(u'{0:>15s}'.format(G(u'data')), u' string is data') |
|
274a0bf46871
Check PendingDeprecationWarning after issue #7994.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64701
diff
changeset
|
1474 |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1475 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
|
1476 month=8, |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1477 day=27)), |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1478 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
|
1479 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1480 # 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
|
1481 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
|
1482 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1483 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1484 # string format specifiers |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1485 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
|
1486 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1487 # computed format specifiers |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1488 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
|
1489 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
|
1490 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
|
1491 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
|
1492 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
|
1493 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1494 # test various errors |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1495 self.assertRaises(ValueError, u'{'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1496 self.assertRaises(ValueError, u'}'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1497 self.assertRaises(ValueError, u'a{'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1498 self.assertRaises(ValueError, u'a}'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1499 self.assertRaises(ValueError, u'{a'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1500 self.assertRaises(ValueError, u'}a'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1501 self.assertRaises(IndexError, u'{0}'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1502 self.assertRaises(IndexError, u'{1}'.format, u'abc') |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1503 self.assertRaises(KeyError, u'{x}'.format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1504 self.assertRaises(ValueError, u"}{".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1505 self.assertRaises(ValueError, u"{".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1506 self.assertRaises(ValueError, u"}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1507 self.assertRaises(ValueError, u"abc{0:{}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1508 self.assertRaises(ValueError, u"{0".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1509 self.assertRaises(IndexError, u"{0.}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1510 self.assertRaises(ValueError, u"{0.}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1511 self.assertRaises(IndexError, u"{0[}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1512 self.assertRaises(ValueError, u"{0[}".format, []) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1513 self.assertRaises(KeyError, u"{0]}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1514 self.assertRaises(ValueError, u"{0.[]}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1515 self.assertRaises(ValueError, u"{0..foo}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1516 self.assertRaises(ValueError, u"{0[0}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1517 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
|
1518 self.assertRaises(KeyError, u"{c]}".format) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1519 self.assertRaises(ValueError, u"{{ {{{0}}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1520 self.assertRaises(ValueError, u"{0}}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1521 self.assertRaises(KeyError, u"{foo}".format, bar=3) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1522 self.assertRaises(ValueError, u"{0!x}".format, 3) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1523 self.assertRaises(ValueError, u"{0!}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1524 self.assertRaises(ValueError, u"{0!rs}".format, 0) |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1525 self.assertRaises(ValueError, u"{!}".format) |
|
52161
1f96d733a743
Unicode format tests weren't actually testing unicode. This was probably due to the original backport from py3k.
Eric Smith <eric@trueblade.com>
parents:
52157
diff
changeset
|
1526 self.assertRaises(IndexError, u"{:}".format) |
|
1f96d733a743
Unicode format tests weren't actually testing unicode. This was probably due to the original backport from py3k.
Eric Smith <eric@trueblade.com>
parents:
52157
diff
changeset
|
1527 self.assertRaises(IndexError, u"{:s}".format) |
|
1f96d733a743
Unicode format tests weren't actually testing unicode. This was probably due to the original backport from py3k.
Eric Smith <eric@trueblade.com>
parents:
52157
diff
changeset
|
1528 self.assertRaises(IndexError, u"{}".format) |
|
62176
3e86254039b9
Merged revisions 81825 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
62170
diff
changeset
|
1529 big = u"23098475029384702983476098230754973209482573" |
|
3e86254039b9
Merged revisions 81825 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
62170
diff
changeset
|
1530 self.assertRaises(ValueError, (u"{" + big + u"}").format) |
|
3e86254039b9
Merged revisions 81825 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
62170
diff
changeset
|
1531 self.assertRaises(ValueError, (u"{[" + big + u"]}").format, [0]) |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1532 |
|
54268
d2d028f65c7c
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
52162
diff
changeset
|
1533 # issue 6089 |
|
d2d028f65c7c
Merged revisions 72848 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
52162
diff
changeset
|
1534 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
|
1535 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
|
1536 |
|
45381
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1537 # 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
|
1538 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
|
1539 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1540 # exceed maximum recursion depth |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1541 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
|
1542 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
|
1543 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
|
1544 |
|
b7231bf6bfb7
Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
42310
diff
changeset
|
1545 # string format spec errors |
|
52162
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1546 self.assertRaises(ValueError, u"{0:-s}".format, u'') |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1547 self.assertRaises(ValueError, format, u"", u"-") |
|
4e1a1576f1e5
Merged revisions 70368 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1548 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
|
1549 |
|
45391
3fc586307d66
Added code to correct combining str and unicode in ''.format(). Added test case.
Eric Smith <eric@trueblade.com>
parents:
45381
diff
changeset
|
1550 # 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
|
1551 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
|
1552 # 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
|
1553 # 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
|
1554 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
|
1555 # 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
|
1556 # 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
|
1557 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
|
1558 |
|
52157
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1559 def test_format_auto_numbering(self): |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1560 class C: |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1561 def __init__(self, x=100): |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1562 self._x = x |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1563 def __format__(self, spec): |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1564 return spec |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1565 |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1566 self.assertEqual(u'{}'.format(10), u'10') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1567 self.assertEqual(u'{:5}'.format('s'), u's ') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1568 self.assertEqual(u'{!r}'.format('s'), u"'s'") |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1569 self.assertEqual(u'{._x}'.format(C(10)), u'10') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1570 self.assertEqual(u'{[1]}'.format([1, 2]), u'2') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1571 self.assertEqual(u'{[a]}'.format({'a':4, 'b':2}), u'4') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1572 self.assertEqual(u'a{}b{}c'.format(0, 1), u'a0b1c') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1573 |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1574 self.assertEqual(u'a{:{}}b'.format('x', '^10'), u'a x b') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1575 self.assertEqual(u'a{:{}x}b'.format(20, '#'), u'a0x14b') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1576 |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1577 # can't mix and match numbering and auto-numbering |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1578 self.assertRaises(ValueError, u'{}{1}'.format, 1, 2) |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1579 self.assertRaises(ValueError, u'{1}{}'.format, 1, 2) |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1580 self.assertRaises(ValueError, u'{:{1}}'.format, 1, 2) |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1581 self.assertRaises(ValueError, u'{0:{}}'.format, 1, 2) |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1582 |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1583 # can mix and match auto-numbering and named |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1584 self.assertEqual(u'{f}{}'.format(4, f='test'), u'test4') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1585 self.assertEqual(u'{}{f}'.format(4, f='test'), u'4test') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1586 self.assertEqual(u'{:{f}}{g}{}'.format(1, 3, g='g', f=2), u' 1g3') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1587 self.assertEqual(u'{f:{}}{}{g}'.format(2, 4, f=1, g='g'), u' 14g') |
|
3f18d609ac1b
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
Eric Smith <eric@trueblade.com>
parents:
49031
diff
changeset
|
1588 |
|
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
|
1589 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
|
1590 # 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
|
1591 # 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
|
1592 # 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
|
1593 # 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
|
1594 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
|
1595 # 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
|
1596 # the signedness of Py_ssize_t. |
|
433220a60a8d
#3601: test_unicode.test_raiseMemError fails in UCS4
Antoine Pitrou <solipsis@pitrou.net>
parents:
48268
diff
changeset
|
1597 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
|
1598 self.assertRaises(MemoryError, alloc) |
|
d7d7139d5840
#3556: test_raiseMemError consumes an insane amount of memory
Antoine Pitrou <solipsis@pitrou.net>
parents:
48117
diff
changeset
|
1599 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
|
1600 |
|
59900
6151d09ce039
Merged revisions 79278,79280 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59087
diff
changeset
|
1601 def test_format_subclass(self): |
|
6151d09ce039
Merged revisions 79278,79280 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59087
diff
changeset
|
1602 class U(unicode): |
|
6151d09ce039
Merged revisions 79278,79280 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59087
diff
changeset
|
1603 def __unicode__(self): |
|
6151d09ce039
Merged revisions 79278,79280 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59087
diff
changeset
|
1604 return u'__unicode__ overridden' |
|
6151d09ce039
Merged revisions 79278,79280 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59087
diff
changeset
|
1605 u = U(u'xxx') |
|
64701
28e6a41c5ba0
Merged revisions 84470-84471,84566-84567,84759 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
63102
diff
changeset
|
1606 self.assertEqual("%s" % u, u'__unicode__ overridden') |
|
64708
44199aa8932b
Strengthen test_unicode with explicit type checking for assertEqual tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64707
diff
changeset
|
1607 self.assertEqual("{}".format(u), '__unicode__ overridden') |
|
59900
6151d09ce039
Merged revisions 79278,79280 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59087
diff
changeset
|
1608 |
|
73682
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1609 def test_encode_decimal(self): |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1610 from _testcapi import unicode_encodedecimal |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1611 self.assertEqual(unicode_encodedecimal(u'123'), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1612 b'123') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1613 self.assertEqual(unicode_encodedecimal(u'\u0663.\u0661\u0664'), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1614 b'3.14') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1615 self.assertEqual(unicode_encodedecimal(u"\N{EM SPACE}3.14\N{EN SPACE}"), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1616 b' 3.14 ') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1617 self.assertRaises(UnicodeEncodeError, |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1618 unicode_encodedecimal, u"123\u20ac", "strict") |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1619 self.assertEqual(unicode_encodedecimal(u"123\u20ac", "replace"), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1620 b'123?') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1621 self.assertEqual(unicode_encodedecimal(u"123\u20ac", "ignore"), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1622 b'123') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1623 self.assertEqual(unicode_encodedecimal(u"123\u20ac", "xmlcharrefreplace"), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1624 b'123€') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1625 self.assertEqual(unicode_encodedecimal(u"123\u20ac", "backslashreplace"), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1626 b'123\\u20ac') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1627 self.assertEqual(unicode_encodedecimal(u"123\u20ac\N{EM SPACE}", "replace"), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1628 b'123? ') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1629 self.assertEqual(unicode_encodedecimal(u"123\u20ac\u20ac", "replace"), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1630 b'123??') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1631 self.assertEqual(unicode_encodedecimal(u"123\u20ac\u0660", "replace"), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1632 b'123?0') |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73554
diff
changeset
|
1633 |
|
37301
f284e854fe72
Fixed bug #1459029 - unicode reprs were double-escaped.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36341
diff
changeset
|
1634 |
|
27304
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1635 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
|
1636 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
|
1637 |
|
a555230be3cb
Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents:
27176
diff
changeset
|
1638 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
|
1639 test_main() |
