annotate Lib/test/test_unicode.py @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents 61973d5f6e25
children fe10ece8ba68
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24538
8d5e0e3f6445 Add encoding declaration.
Martin v. Löwis <martin@v.loewis.de>
parents: 24364
diff changeset
1 # -*- coding: iso-8859-1 -*-
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 """ Test script for the Unicode implementation.
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 Written by Marc-Andre Lemburg (mal@lemburg.com).
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15910
diff changeset
8 """#"
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
9 import unittest, test.test_support
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
10 import sys, string, codecs
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
11
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
12 class UnicodeTest(unittest.TestCase):
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
14 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
15 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
16 # 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
17 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
18 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
19 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
20 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
21 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
22 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
23 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
24 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
25 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
26 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
27 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
28 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
29 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
30 latin1repr = (
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
31 "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
32 "\\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
33 "\\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
34 "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
35 "\\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
36 "\\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
37 "\\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
38 "\\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
39 "\\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
40 "\\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
41 "\\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
42 "\\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
43 "\\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
44 "\\xfe\\xff'")
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
45 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
46 self.assertEqual(testrepr, latin1repr)
20017
08446a986a56 Test basic functioning of unicode repr(). (If this breaks Jython,
Guido van Rossum <guido@python.org>
parents: 19999
diff changeset
47
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
48 def checkmethod(self, method, input, output, *args):
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 f = getattr(input, method)
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
50 value = f(*args)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
51 self.assertEqual(output, value)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
52 self.assert_(type(output) is type(value))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
53
23115
7121d7d572d0 Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents: 23075
diff changeset
54 # if the original is returned make sure that
7121d7d572d0 Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents: 23075
diff changeset
55 # this doesn't happen with subclasses
7121d7d572d0 Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents: 23075
diff changeset
56 if value is input:
7121d7d572d0 Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents: 23075
diff changeset
57 class usub(unicode):
7121d7d572d0 Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents: 23075
diff changeset
58 def __repr__(self):
7121d7d572d0 Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents: 23075
diff changeset
59 return 'usub(%r)' % unicode.__repr__(self)
7121d7d572d0 Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents: 23075
diff changeset
60 input = usub(input)
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
61 f = getattr(input, method)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
62 value = f(*args)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
63 self.assertEqual(output, value)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
64 self.assert_(input is not value)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
65
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
66 def test_capitalize(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
67 self.checkmethod('capitalize', u' hello ', u' hello ')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
68 self.checkmethod('capitalize', u'Hello ', u'Hello ')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
69 self.checkmethod('capitalize', u'hello ', u'Hello ')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
70 self.checkmethod('capitalize', u'aaaa', u'Aaaa')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
71 self.checkmethod('capitalize', u'AaAa', u'Aaaa')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
72
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
73 self.assertRaises(TypeError, u'hello'.capitalize, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
74
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
75 def test_count(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
76 self.checkmethod('count', u'aaa', 3, u'a')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
77 self.checkmethod('count', u'aaa', 0, u'b')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
78 self.checkmethod('count', 'aaa', 3, u'a')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
79 self.checkmethod('count', 'aaa', 0, u'b')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
80 self.checkmethod('count', u'aaa', 3, 'a')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
81 self.checkmethod('count', u'aaa', 0, 'b')
27797
61973d5f6e25 Add a few tests to test_count() to increase coverage in
Walter Dörwald <walter@livinglogic.de>
parents: 27796
diff changeset
82 self.checkmethod('count', u'aaa', 0, 'b')
61973d5f6e25 Add a few tests to test_count() to increase coverage in
Walter Dörwald <walter@livinglogic.de>
parents: 27796
diff changeset
83 self.checkmethod('count', u'aaa', 1, 'a', -1)
61973d5f6e25 Add a few tests to test_count() to increase coverage in
Walter Dörwald <walter@livinglogic.de>
parents: 27796
diff changeset
84 self.checkmethod('count', u'aaa', 3, 'a', -10)
61973d5f6e25 Add a few tests to test_count() to increase coverage in
Walter Dörwald <walter@livinglogic.de>
parents: 27796
diff changeset
85 self.checkmethod('count', u'aaa', 2, 'a', 0, -1)
61973d5f6e25 Add a few tests to test_count() to increase coverage in
Walter Dörwald <walter@livinglogic.de>
parents: 27796
diff changeset
86 self.checkmethod('count', u'aaa', 0, 'a', 0, -10)
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
87
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
88 self.assertRaises(TypeError, u'hello'.count)
27797
61973d5f6e25 Add a few tests to test_count() to increase coverage in
Walter Dörwald <walter@livinglogic.de>
parents: 27796
diff changeset
89 self.assertRaises(TypeError, u'hello'.count, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
91 def test_title(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
92 self.checkmethod('title', u' hello ', u' Hello ')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
93 self.checkmethod('title', u'Hello ', u'Hello ')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
94 self.checkmethod('title', u'hello ', u'Hello ')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
95 self.checkmethod('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
96 self.checkmethod('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
97 self.checkmethod('title', u"getInt", u'Getint')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
98
27796
0400ba78a897 Fix copy&paste error: call title instead of count
Walter Dörwald <walter@livinglogic.de>
parents: 27304
diff changeset
99 self.assertRaises(TypeError, u'hello'.title, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
101 def test_find(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
102 self.checkmethod('find', u'abcdefghiabc', 0, u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
103 self.checkmethod('find', u'abcdefghiabc', 9, u'abc', 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
104 self.checkmethod('find', u'abcdefghiabc', -1, u'def', 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
105
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
106 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
107 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
108
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
109 def test_rfind(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
110 self.checkmethod('rfind', u'abcdefghiabc', 9, u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
111 self.checkmethod('rfind', 'abcdefghiabc', 9, u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
112 self.checkmethod('rfind', 'abcdefghiabc', 12, u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
113 self.checkmethod('rfind', u'abcdefghiabc', 12, '')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
114 self.checkmethod('rfind', u'abcdefghiabc', 12, u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
115
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
116 self.assertRaises(TypeError, u'hello'.rfind)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
117 self.assertRaises(TypeError, u'hello'.rfind, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
119 def test_index(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
120 self.checkmethod('index', u'abcdefghiabc', 0, u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
121 self.checkmethod('index', u'abcdefghiabc', 3, u'def')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
122 self.checkmethod('index', u'abcdefghiabc', 0, u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
123 self.checkmethod('index', u'abcdefghiabc', 9, u'abc', 1)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
125 self.assertRaises(ValueError, u'abcdefghiabc'.index, u'hib')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
126 self.assertRaises(ValueError, u'abcdefghiab'.index, u'abc', 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
127 self.assertRaises(ValueError, u'abcdefghi'.index, u'ghi', 8)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
128 self.assertRaises(ValueError, u'abcdefghi'.index, u'ghi', -1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
129
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
130 self.assertRaises(TypeError, u'hello'.index)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
131 self.assertRaises(TypeError, u'hello'.index, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
133 def test_rindex(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
134 self.checkmethod('rindex', u'abcdefghiabc', 12, u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
135 self.checkmethod('rindex', u'abcdefghiabc', 3, u'def')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
136 self.checkmethod('rindex', u'abcdefghiabc', 9, u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
137 self.checkmethod('rindex', u'abcdefghiabc', 0, u'abc', 0, -1)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
139 self.assertRaises(ValueError, u'abcdefghiabc'.rindex, u'hib')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
140 self.assertRaises(ValueError, u'defghiabc'.rindex, u'def', 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
141 self.assertRaises(ValueError, u'defghiabc'.rindex, u'abc', 0, -1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
142 self.assertRaises(ValueError, u'abcdefghi'.rindex, u'ghi', 0, 8)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
143 self.assertRaises(ValueError, u'abcdefghi'.rindex, u'ghi', 0, -1)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
145 self.assertRaises(TypeError, u'hello'.rindex)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
146 self.assertRaises(TypeError, u'hello'.rindex, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
148 def test_lower(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
149 self.checkmethod('lower', u'HeLLo', u'hello')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
150 self.checkmethod('lower', u'hello', u'hello')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
151
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
152 self.assertRaises(TypeError, u"hello".lower, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
153
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
154 def test_upper(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
155 self.checkmethod('upper', u'HeLLo', u'HELLO')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
156 self.checkmethod('upper', u'HELLO', u'HELLO')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
157
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
158 self.assertRaises(TypeError, u'hello'.upper, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
159
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
160 def test_translate(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
161 if 0:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
162 transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
15608
ff0767753d81 Test more split argument combinations:
Guido van Rossum <guido@python.org>
parents: 15452
diff changeset
163
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
164 self.checkmethod('maketrans', u'abc', transtable, u'xyz')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
165 self.checkmethod('maketrans', u'abc', ValueError, u'xyzq')
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
167 self.checkmethod('translate', u'xyzabcdef', u'xyzxyz', transtable, u'def')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
168
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
169 table = string.maketrans('a', u'A')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
170 self.checkmethod('translate', u'abc', u'Abc', table)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
171 self.checkmethod('translate', u'xyz', u'xyz', table)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
172
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
173 self.checkmethod('translate', u"abababc", u'bbbc', {ord('a'):None})
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
174 self.checkmethod('translate', u"abababc", u'iiic', {ord('a'):None, ord('b'):ord('i')})
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
175 self.checkmethod('translate', u"abababc", u'iiix', {ord('a'):None, ord('b'):ord('i'), ord('c'):u'x'})
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
176 self.checkmethod('translate', u"abababc", u'<i><i><i>c', {ord('a'):None, ord('b'):u'<i>'})
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
177 self.checkmethod('translate', u"abababc", u'c', {ord('a'):None, ord('b'):u''})
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
178
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
179 self.assertRaises(TypeError, u'hello'.translate)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
180
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
181 def test_split(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
182 self.checkmethod(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
183 'split',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
184 u'this is the split function',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
185 [u'this', u'is', u'the', u'split', u'function']
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
186 )
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
187 self.checkmethod('split', u'a|b|c|d', [u'a', u'b', u'c', u'd'], u'|')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
188 self.checkmethod('split', u'a|b|c|d', [u'a', u'b', u'c|d'], u'|', 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
189 self.checkmethod('split', u'a b c d', [u'a', u'b c d'], None, 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
190 self.checkmethod('split', u'a b c d', [u'a', u'b', u'c d'], None, 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
191 self.checkmethod('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
192 self.checkmethod('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
193 self.checkmethod('split', u'a b c d', [u'a b c d'], None, 0)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
194 self.checkmethod('split', u'a b c d', [u'a', u'b', u'c d'], None, 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
195 self.checkmethod('split', u'a b c d ', [u'a', u'b', u'c', u'd'])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
196 self.checkmethod('split', u'a//b//c//d', [u'a', u'b', u'c', u'd'], u'//')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
197 self.checkmethod('split', u'a//b//c//d', [u'a', u'b', u'c', u'd'], '//')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
198 self.checkmethod('split', 'a//b//c//d', [u'a', u'b', u'c', u'd'], u'//')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
199 self.checkmethod('split', u'endcase test', [u'endcase ', u''], u'test')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
200 self.checkmethod('split', u'endcase test', [u'endcase ', u''], 'test')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
201 self.checkmethod('split', 'endcase test', [u'endcase ', u''], u'test')
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 self.assertRaises(TypeError, u"hello".split, 42, 42, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
205 def test_join(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
206 # join now works with any sequence type
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
207 class Sequence:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
208 def __init__(self, seq): self.seq = seq
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
209 def __len__(self): return len(self.seq)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
210 def __getitem__(self, i): return self.seq[i]
23225
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 23115
diff changeset
211
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.checkmethod('join', u' ', u'a b c d', [u'a', u'b', u'c', u'd'])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
213 self.checkmethod('join', u' ', u'a b c d', ['a', 'b', u'c', u'd'])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
214 self.checkmethod('join', u'', u'abcd', (u'a', u'b', u'c', u'd'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
215 self.checkmethod('join', u' ', u'w x y z', Sequence('wxyz'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
216 self.assertRaises(TypeError, u' '.join, 7)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
217 self.assertRaises(TypeError, u' '.join, Sequence([7, u'hello', 123L]))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
218 self.checkmethod('join', ' ', u'a b c d', [u'a', u'b', u'c', u'd'])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
219 self.checkmethod('join', ' ', u'a b c d', ['a', 'b', u'c', u'd'])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
220 self.checkmethod('join', '', u'abcd', (u'a', u'b', u'c', u'd'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
221 self.checkmethod('join', ' ', u'w x y z', Sequence(u'wxyz'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
222 self.assertRaises(TypeError, ' '.join, TypeError)
23225
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 23115
diff changeset
223
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
224 result = u''
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
225 for i in range(10):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
226 if i > 0:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
227 result = result + u':'
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
228 result = result + u'x'*10
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
230 self.checkmethod('join', u':', result, [u'x' * 10] * 10)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
231 self.checkmethod('join', u':', result, (u'x' * 10,) * 10)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
232
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
233 self.assertRaises(TypeError, u"hello".join)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
235 def test_strip(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
236 self.checkmethod('strip', u' hello ', u'hello')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
237 self.checkmethod('lstrip', u' hello ', u'hello ')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
238 self.checkmethod('rstrip', u' hello ', u' hello')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
239 self.checkmethod('strip', u'hello', u'hello')
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
241 # strip/lstrip/rstrip with None arg
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
242 self.checkmethod('strip', u' hello ', u'hello', None)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
243 self.checkmethod('lstrip', u' hello ', u'hello ', None)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
244 self.checkmethod('rstrip', u' hello ', u' hello', None)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
245 self.checkmethod('strip', u'hello', u'hello', None)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
246
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
247 # strip/lstrip/rstrip with unicode arg
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
248 self.checkmethod('strip', u'xyzzyhelloxyzzy', u'hello', u'xyz')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
249 self.checkmethod('lstrip', u'xyzzyhelloxyzzy', u'helloxyzzy', u'xyz')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
250 self.checkmethod('rstrip', u'xyzzyhelloxyzzy', u'xyzzyhello', u'xyz')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
251 self.checkmethod('strip', u'hello', u'hello', u'xyz')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
252
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
253 # strip/lstrip/rstrip with str arg
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
254 self.checkmethod('strip', u'xyzzyhelloxyzzy', u'hello', 'xyz')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
255 self.checkmethod('lstrip', u'xyzzyhelloxyzzy', u'helloxyzzy', 'xyz')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
256 self.checkmethod('rstrip', u'xyzzyhelloxyzzy', u'xyzzyhello', 'xyz')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
257 self.checkmethod('strip', u'hello', u'hello', 'xyz')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
258
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
259 self.assertRaises(TypeError, u"hello".strip, 42, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
260 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
261
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
262 def test_swapcase(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
263 self.checkmethod('swapcase', u'HeLLo cOmpUteRs', u'hEllO CoMPuTErS')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
264
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
265 self.assertRaises(TypeError, u"hello".swapcase, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
266
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
267 def test_replace(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
268 self.checkmethod('replace', u'one!two!three!', u'one@two!three!', u'!', u'@', 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
269 self.checkmethod('replace', u'one!two!three!', u'onetwothree', '!', '')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
270 self.checkmethod('replace', u'one!two!three!', u'one@two@three!', u'!', u'@', 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
271 self.checkmethod('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
272 self.checkmethod('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
273 self.checkmethod('replace', u'one!two!three!', u'one!two!three!', u'!', u'@', 0)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
274 self.checkmethod('replace', u'one!two!three!', u'one@two@three@', u'!', u'@')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
275 self.checkmethod('replace', u'one!two!three!', u'one!two!three!', u'x', u'@')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
276 self.checkmethod('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
277 self.checkmethod('replace', u'abc', u'-a-b-c-', u'', u'-')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
278 self.checkmethod('replace', u'abc', u'-a-b-c', u'', u'-', 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
279 self.checkmethod('replace', u'abc', u'abc', u'', u'-', 0)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
280 self.checkmethod('replace', u'abc', u'abc', u'ab', u'--', 0)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
281 self.checkmethod('replace', u'abc', u'abc', u'xy', u'--')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
282 self.checkmethod('replace', u'', u'', u'', u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
283
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
284 # method call forwarded from str implementation because of unicode argument
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
285 self.checkmethod('replace', 'one!two!three!', u'one@two!three!', u'!', u'@', 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
286 self.assertRaises(TypeError, 'replace'.replace, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
287 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
288
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
289 self.assertRaises(TypeError, u"hello".replace)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
290 self.assertRaises(TypeError, u"hello".replace, 42, u"h")
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
291 self.assertRaises(TypeError, u"hello".replace, u"h", 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
292
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
293 def test_startswith(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
294 self.checkmethod('startswith', u'hello', True, u'he')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
295 self.checkmethod('startswith', u'hello', True, u'hello')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
296 self.checkmethod('startswith', u'hello', False, u'hello world')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
297 self.checkmethod('startswith', u'hello', True, u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
298 self.checkmethod('startswith', u'hello', False, u'ello')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
299 self.checkmethod('startswith', u'hello', True, u'ello', 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
300 self.checkmethod('startswith', u'hello', True, u'o', 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
301 self.checkmethod('startswith', u'hello', False, u'o', 5)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
302 self.checkmethod('startswith', u'hello', True, u'', 5)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
303 self.checkmethod('startswith', u'hello', False, u'lo', 6)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
304 self.checkmethod('startswith', u'helloworld', True, u'lowo', 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
305 self.checkmethod('startswith', u'helloworld', True, u'lowo', 3, 7)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
306 self.checkmethod('startswith', u'helloworld', False, u'lowo', 3, 6)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
307
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
308 self.assertRaises(TypeError, u"hello".startswith)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
309 self.assertRaises(TypeError, u"hello".startswith, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
310
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
311 def test_endswith(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
312 self.checkmethod('endswith', u'hello', True, u'lo')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
313 self.checkmethod('endswith', u'hello', False, u'he')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
314 self.checkmethod('endswith', u'hello', True, u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
315 self.checkmethod('endswith', u'hello', False, u'hello world')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
316 self.checkmethod('endswith', u'helloworld', False, u'worl')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
317 self.checkmethod('endswith', u'helloworld', True, u'worl', 3, 9)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
318 self.checkmethod('endswith', u'helloworld', True, u'world', 3, 12)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
319 self.checkmethod('endswith', u'helloworld', True, u'lowo', 1, 7)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
320 self.checkmethod('endswith', u'helloworld', True, u'lowo', 2, 7)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
321 self.checkmethod('endswith', u'helloworld', True, u'lowo', 3, 7)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
322 self.checkmethod('endswith', u'helloworld', False, u'lowo', 4, 7)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
323 self.checkmethod('endswith', u'helloworld', False, u'lowo', 3, 8)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
324 self.checkmethod('endswith', u'ab', False, u'ab', 0, 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
325 self.checkmethod('endswith', u'ab', False, u'ab', 0, 0)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
326 self.checkmethod('endswith', 'helloworld', True, u'd')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
327 self.checkmethod('endswith', 'helloworld', False, u'l')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
328
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
329 self.assertRaises(TypeError, u"hello".endswith)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
330 self.assertRaises(TypeError, u"hello".endswith, 42)
22661
c16bea79f4db As part of fixing bug #536241, add a test case for string.zfill() with Unicode
Andrew M. Kuchling <amk@amk.ca>
parents: 22423
diff changeset
331
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
332 def test_expandtabs(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
333 self.checkmethod('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
334 self.checkmethod('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 8)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
335 self.checkmethod('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
336 self.checkmethod('expandtabs', u'abc\r\nab\tdef\ng\thi', u'abc\r\nab def\ng hi', 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
337 self.checkmethod('expandtabs', u'abc\r\nab\r\ndef\ng\r\nhi', u'abc\r\nab\r\ndef\ng\r\nhi', 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
338
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
339 self.assertRaises(TypeError, u"hello".expandtabs, 42, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
340
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
341 def test_capwords(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
342 if 0:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
343 self.checkmethod('capwords', u'abc def ghi', u'Abc Def Ghi')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
344 self.checkmethod('capwords', u'abc\tdef\nghi', u'Abc Def Ghi')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
345 self.checkmethod('capwords', u'abc\t def \nghi', u'Abc Def Ghi')
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
346
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
347 def test_zfill(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
348 self.checkmethod('zfill', u'123', u'123', 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
349 self.checkmethod('zfill', u'123', u'123', 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
350 self.checkmethod('zfill', u'123', u'0123', 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
351 self.checkmethod('zfill', u'+123', u'+123', 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
352 self.checkmethod('zfill', u'+123', u'+123', 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
353 self.checkmethod('zfill', u'+123', u'+0123', 5)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
354 self.checkmethod('zfill', u'-123', u'-123', 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
355 self.checkmethod('zfill', u'-123', u'-123', 4)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
356 self.checkmethod('zfill', u'-123', u'-0123', 5)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
357 self.checkmethod('zfill', u'', u'000', 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
358 self.checkmethod('zfill', u'34', u'34', 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
359 self.checkmethod('zfill', u'34', u'00034', 5)
13890
8f0fc0b5f784 Removing UTF-16 aware Unicode comparison code. This kind of compare
Marc-André Lemburg <mal@egenix.com>
parents: 13410
diff changeset
360
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
361 self.assertRaises(TypeError, u"123".zfill)
13410
5157eb7be20d Tests for new surrogate support in the UTF-8 codec. By Bill Tutt.
Marc-André Lemburg <mal@egenix.com>
parents: 13400
diff changeset
362
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
363 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
364 # Comparisons:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
365 self.assertEqual(u'abc', 'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
366 self.assertEqual('abc', u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
367 self.assertEqual(u'abc', u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
368 self.assert_(u'abcd' > 'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
369 self.assert_('abcd' > u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
370 self.assert_(u'abcd' > u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
371 self.assert_(u'abc' < 'abcd')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
372 self.assert_('abc' < u'abcd')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
373 self.assert_(u'abc' < u'abcd')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
374
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
375 if 0:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
376 # 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
377 # 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
378
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
379 # No surrogates, no fixup required.
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
380 self.assert_(u'\u0061' < u'\u20ac')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
381 # Non surrogate below surrogate value, no fixup required
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
382 self.assert_(u'\u0061' < u'\ud800\udc02')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
383
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
384 # 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
385 def test_lecmp(s, s2):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
386 self.assert_(s < s2)
13410
5157eb7be20d Tests for new surrogate support in the UTF-8 codec. By Bill Tutt.
Marc-André Lemburg <mal@egenix.com>
parents: 13400
diff changeset
387
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
388 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
389 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
390 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
391 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
392 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
393 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
394 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
395 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
396 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
397 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
398 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
399 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
400 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
401 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
402 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
403 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
404 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
405 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
406 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
407 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
408 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
409 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
410 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
411 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
412 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
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 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
421
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
422 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
423 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
424
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
425 # Surrogates on both sides, no fixup required
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
426 self.assert_(u'\ud800\udc02' < u'\ud84d\udc56')
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
427
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
428 def test_ljust(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
429 self.checkmethod('ljust', u'abc', u'abc ', 10)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
430 self.checkmethod('ljust', u'abc', u'abc ', 6)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
431 self.checkmethod('ljust', u'abc', u'abc', 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
432
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
433 self.assertRaises(TypeError, u"abc".ljust)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
434
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
435 def test_rjust(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
436 self.checkmethod('rjust', u'abc', u' abc', 10)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
437 self.checkmethod('rjust', u'abc', u' abc', 6)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
438 self.checkmethod('rjust', u'abc', u'abc', 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
439
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
440 self.assertRaises(TypeError, u"abc".rjust)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
441
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
442 def test_center(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
443 self.checkmethod('center', u'abc', u' abc ', 10)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
444 self.checkmethod('center', u'abc', u' abc ', 6)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
445 self.checkmethod('center', u'abc', u'abc', 2)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
446
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
447 self.assertRaises(TypeError, u"abc".center)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
448
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
449 def test_islower(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
450 self.checkmethod('islower', u'', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
451 self.checkmethod('islower', u'a', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
452 self.checkmethod('islower', u'A', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
453 self.checkmethod('islower', u'\n', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
454 self.checkmethod('islower', u'\u1FFc', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
455 self.checkmethod('islower', u'abc', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
456 self.checkmethod('islower', u'aBc', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
457 self.checkmethod('islower', u'abc\n', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
458
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
459 self.assertRaises(TypeError, u"abc".islower, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
460
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
461 def test_isupper(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
462 self.checkmethod('isupper', u'', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
463 self.checkmethod('isupper', u'a', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
464 self.checkmethod('isupper', u'A', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
465 self.checkmethod('isupper', u'\n', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
466 if sys.platform[:4] != 'java':
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
467 self.checkmethod('isupper', u'\u1FFc', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
468 self.checkmethod('isupper', u'ABC', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
469 self.checkmethod('isupper', u'AbC', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
470 self.checkmethod('isupper', u'ABC\n', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
471
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
472 self.assertRaises(TypeError, u"abc".isupper, 42)
13353
0b289e00d52a Added tests for the new .isalpha() and .isalnum() methods.
Marc-André Lemburg <mal@egenix.com>
parents: 13189
diff changeset
473
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
474 def test_istitle(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
475 self.checkmethod('istitle', u'', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
476 self.checkmethod('istitle', u'a', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
477 self.checkmethod('istitle', u'A', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
478 self.checkmethod('istitle', u'\n', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
479 self.checkmethod('istitle', u'\u1FFc', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
480 self.checkmethod('istitle', u'A Titlecased Line', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
481 self.checkmethod('istitle', u'A\nTitlecased Line', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
482 self.checkmethod('istitle', u'A Titlecased, Line', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
483 self.checkmethod('istitle', u'Greek \u1FFcitlecases ...', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
484 self.checkmethod('istitle', u'Not a capitalized String', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
485 self.checkmethod('istitle', u'Not\ta Titlecase String', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
486 self.checkmethod('istitle', u'Not--a Titlecase String', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
487 self.checkmethod('istitle', u'NOT', False)
13353
0b289e00d52a Added tests for the new .isalpha() and .isalnum() methods.
Marc-André Lemburg <mal@egenix.com>
parents: 13189
diff changeset
488
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
489 self.assertRaises(TypeError, u"abc".istitle, 42)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
490
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
491 def test_isspace(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
492 self.checkmethod('isspace', u'', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
493 self.checkmethod('isspace', u'a', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
494 self.checkmethod('isspace', u' ', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
495 self.checkmethod('isspace', u'\t', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
496 self.checkmethod('isspace', u'\r', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
497 self.checkmethod('isspace', u'\n', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
498 self.checkmethod('isspace', u' \t\r\n', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
499 self.checkmethod('isspace', u' \t\r\na', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
500
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
501 self.assertRaises(TypeError, u"abc".isspace, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
502
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
503 def test_isalpha(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
504 self.checkmethod('isalpha', u'', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
505 self.checkmethod('isalpha', u'a', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
506 self.checkmethod('isalpha', u'A', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
507 self.checkmethod('isalpha', u'\n', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
508 self.checkmethod('isalpha', u'\u1FFc', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
509 self.checkmethod('isalpha', u'abc', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
510 self.checkmethod('isalpha', u'aBc123', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
511 self.checkmethod('isalpha', u'abc\n', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
512
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
513 self.assertRaises(TypeError, u"abc".isalpha, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
514
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
515 def test_isalnum(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
516 self.checkmethod('isalnum', u'', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
517 self.checkmethod('isalnum', u'a', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
518 self.checkmethod('isalnum', u'A', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
519 self.checkmethod('isalnum', u'\n', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
520 self.checkmethod('isalnum', u'123abc456', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
521 self.checkmethod('isalnum', u'a1b3c', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
522 self.checkmethod('isalnum', u'aBc000 ', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
523 self.checkmethod('isalnum', u'abc\n', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
524
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
525 self.assertRaises(TypeError, u"abc".isalnum, 42)
12001
e362f326048c Marc-Andre Lemburg: Add tests for mixed use of char in string.
Guido van Rossum <guido@python.org>
parents: 11992
diff changeset
526
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
527 def test_isdecimal(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
528 self.checkmethod('isdecimal', u'', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
529 self.checkmethod('isdecimal', u'a', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
530 self.checkmethod('isdecimal', u'0', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
531 self.checkmethod('isdecimal', u'\u2460', False) # CIRCLED DIGIT ONE
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
532 self.checkmethod('isdecimal', u'\xbc', False) # VULGAR FRACTION ONE QUARTER
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
533 self.checkmethod('isdecimal', u'\u0660', True) # ARABIC-INDIC DIGIT ZERO
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
534 self.checkmethod('isdecimal', u'0123456789', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
535 self.checkmethod('isdecimal', u'0123456789a', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
536
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
537 self.assertRaises(TypeError, u"abc".isdecimal, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
538
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
539 def test_isdigit(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
540 self.checkmethod('isdigit', u'', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
541 self.checkmethod('isdigit', u'a', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
542 self.checkmethod('isdigit', u'0', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
543 self.checkmethod('isdigit', u'\u2460', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
544 self.checkmethod('isdigit', u'\xbc', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
545 self.checkmethod('isdigit', u'\u0660', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
546 self.checkmethod('isdigit', u'0123456789', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
547 self.checkmethod('isdigit', u'0123456789a', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
548
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
549 self.assertRaises(TypeError, u"abc".isdigit, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
550
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
551 def test_isnumeric(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
552 self.checkmethod('isnumeric', u'', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
553 self.checkmethod('isnumeric', u'a', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
554 self.checkmethod('isnumeric', u'0', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
555 self.checkmethod('isnumeric', u'\u2460', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
556 self.checkmethod('isnumeric', u'\xbc', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
557 self.checkmethod('isnumeric', u'\u0660', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
558 self.checkmethod('isnumeric', u'0123456789', True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
559 self.checkmethod('isnumeric', u'0123456789a', False)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
560
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
561 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
562
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
563 def test_splitlines(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
564 self.checkmethod('splitlines', u"abc\ndef\n\rghi", [u'abc', u'def', u'', u'ghi'])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
565 self.checkmethod('splitlines', u"abc\ndef\n\r\nghi", [u'abc', u'def', u'', u'ghi'])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
566 self.checkmethod('splitlines', u"abc\ndef\r\nghi", [u'abc', u'def', u'ghi'])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
567 self.checkmethod('splitlines', u"abc\ndef\r\nghi\n", [u'abc', u'def', u'ghi'])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
568 self.checkmethod('splitlines', u"abc\ndef\r\nghi\n\r", [u'abc', u'def', u'ghi', u''])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
569 self.checkmethod('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'', u'abc', u'def', u'ghi', u''])
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
570 self.checkmethod('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'\n', u'abc\n', u'def\r\n', u'ghi\n', u'\r'], True)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
571
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
572 self.assertRaises(TypeError, u"abc".splitlines, 42, 42)
12917
2a2caaee6797 Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12897
diff changeset
573
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
574 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
575 # Testing Unicode contains method
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
576 self.assert_('a' in u'abdb')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
577 self.assert_('a' in u'bdab')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
578 self.assert_('a' in u'bdaba')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
579 self.assert_('a' in u'bdba')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
580 self.assert_('a' in u'bdba')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
581 self.assert_(u'a' in u'bdba')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
582 self.assert_(u'a' not in u'bdb')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
583 self.assert_(u'a' not in 'bdb')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
584 self.assert_(u'a' in 'bdba')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
585 self.assert_(u'a' in ('a',1,None))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
586 self.assert_(u'a' in (1,None,'a'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
587 self.assert_(u'a' in (1,None,u'a'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
588 self.assert_('a' in ('a',1,None))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
589 self.assert_('a' in (1,None,'a'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
590 self.assert_('a' in (1,None,u'a'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
591 self.assert_('a' not in ('x',1,u'y'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
592 self.assert_('a' not in ('x',1,None))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
593 self.assert_(u'abcd' not in u'abcxxxx')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
594 self.assert_(u'ab' in u'abcd')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
595 self.assert_('ab' in u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
596 self.assert_(u'ab' in 'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
597 self.assert_(u'ab' in (1,None,u'ab'))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
598 self.assert_(u'' in u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
599 self.assert_('' in u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
600
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
601 # 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
602 # 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
603 # someone has changed the default encoding
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
604 self.assertRaises(UnicodeError, 'g\xe2teau'.__contains__, u'\xe2')
24737
eaa87632b1e8 Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level.
Marc-André Lemburg <mal@egenix.com>
parents: 24703
diff changeset
605
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
606 self.assert_(u'' in '')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
607 self.assert_('' in u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
608 self.assert_(u'' in u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
609 self.assert_(u'' in 'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
610 self.assert_('' in u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
611 self.assert_(u'' in u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
612 self.assert_(u'\0' not in 'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
613 self.assert_('\0' not in u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
614 self.assert_(u'\0' not in u'abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
615 self.assert_(u'\0' in '\0abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
616 self.assert_('\0' in u'\0abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
617 self.assert_(u'\0' in u'\0abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
618 self.assert_(u'\0' in 'abc\0')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
619 self.assert_('\0' in u'abc\0')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
620 self.assert_(u'\0' in u'abc\0')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
621 self.assert_(u'a' in '\0abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
622 self.assert_('a' in u'\0abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
623 self.assert_(u'a' in u'\0abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
624 self.assert_(u'asdf' in 'asdf')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
625 self.assert_('asdf' in u'asdf')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
626 self.assert_(u'asdf' in u'asdf')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
627 self.assert_(u'asdf' not in 'asd')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
628 self.assert_('asdf' not in u'asd')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
629 self.assert_(u'asdf' not in u'asd')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
630 self.assert_(u'asdf' not in '')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
631 self.assert_('asdf' not in u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
632 self.assert_(u'asdf' not in u'')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
633
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
634 self.assertRaises(TypeError, u"abc".__contains__)
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
diff changeset
635
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
636 def test_formatting(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
637 # 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
638 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
639 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
640 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
641 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
642 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
643 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
644 self.assertEqual(u"%c" % (u"a",), u'a')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
645 self.assertEqual(u"%c" % ("a",), u'a')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
646 self.assertEqual(u"%c" % (34,), u'"')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
647 self.assertEqual(u"%c" % (36,), u'$')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
648 self.assertEqual(u"%d".__mod__(10), u'10')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
649 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
650 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
651 self.assertEqual(u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"}, 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
652 self.assertEqual(u"%(x)s, %(ä)s" % {'x':u"abc", u'ä':"def"}, u'abc, def')
20563
9058e49c6c57 Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents: 20240
diff changeset
653
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
654 for ordinal in (-100, 0x200000):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
655 self.assertRaises(ValueError, u"%c".__mod__, ordinal)
20563
9058e49c6c57 Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents: 20240
diff changeset
656
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
657 # float formatting
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
658 for prec in xrange(100):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
659 format = u'%%.%if' % prec
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
660 value = 0.01
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
661 for x in xrange(60):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
662 value = value * 3.141592655 / 3.0 * 10.0
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
663 # The formatfloat() code in stringobject.c and
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
664 # unicodeobject.c uses a 120 byte buffer and switches from
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
665 # 'f' formatting to 'g' at precision 50, so we expect
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
666 # OverflowErrors for the ranges x < 50 and prec >= 67.
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
667 if x < 50 and prec >= 67:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
668 self.assertRaises(OverflowError, format.__mod__, value)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
669 else:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
670 format % value
20563
9058e49c6c57 Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents: 20240
diff changeset
671
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
672 # 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
673 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
674 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
675 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
676 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
677 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
678 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
679 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
680 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
681 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
682 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
683 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
684 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
685 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
686 self.assertEqual('%i %*.*s' % (10, 5,3,u'abc',), u'10 abc')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
687 self.assertEqual('%i%s %*.*s' % (10, 3, 5,3,u'abc',), u'103 abc')
20563
9058e49c6c57 Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents: 20240
diff changeset
688
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
689 self.assertEqual(u'%3ld' % 42, u' 42')
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(u'%07.2f' % 42, u'0042.00')
20563
9058e49c6c57 Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents: 20240
diff changeset
691
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
692 self.assertRaises(TypeError, u"abc".__mod__)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
693 self.assertRaises(TypeError, u"%(foo)s".__mod__, 42)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
694 self.assertRaises(TypeError, u"%s%s".__mod__, (42,))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
695 self.assertRaises(TypeError, u"%c".__mod__, (None,))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
696 self.assertRaises(ValueError, u"%c".__mod__, (sys.maxunicode+1,))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
697 self.assertRaises(ValueError, u"%(foo".__mod__, {})
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
698 self.assertRaises(TypeError, u"%(foo)s %(bar)s".__mod__, (u"foo", 42))
20563
9058e49c6c57 Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents: 20240
diff changeset
699
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
700 # argument names with properly nested brackets are supported
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
701 self.assertEqual(u"%((foo))s" % {u"(foo)": u"bar"}, u"bar")
20563
9058e49c6c57 Additional test and documentation for the unicode() changes.
Marc-André Lemburg <mal@egenix.com>
parents: 20240
diff changeset
702
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
703 # 100 is a magic number in PyUnicode_Format, this forces a resize
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
704 self.assertEqual(u"%sx" % (103*u"a"), 103*u"a"+u"x")
12051
d89556c04ef9 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 12025
diff changeset
705
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
706 self.assertRaises(TypeError, u"%*s".__mod__, (u"foo", u"bar"))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
707 self.assertRaises(TypeError, u"%10.*f".__mod__, (u"foo", 42.))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
708 self.assertRaises(ValueError, u"%10".__mod__, (42,))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
709
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
710 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
711 # 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
712
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
713 self.assertEqual(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
714 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
715 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
716 )
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
717
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
718 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
719 pass
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 18828
diff changeset
720
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
721 self.assertEqual(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
722 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
723 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
724 )
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
725
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
726 self.assertEqual(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
727 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
728 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
729 )
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 18828
diff changeset
730
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
731 class UnicodeCompat:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
732 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
733 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
734 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
735 return self.x
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 18828
diff changeset
736
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
737 self.assertEqual(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
738 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
739 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
740
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
741 class StringCompat:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
742 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
743 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
744 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
745 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
746
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
747 self.assertEqual(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
748 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
749 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
750 )
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
751
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
752 # 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
753
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
754 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
755 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
756 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
757
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
758 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
759 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
760
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
761 # 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
762 # 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
763
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
764 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
765 self.assertRaises(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
766 TypeError,
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
767 unicode,
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
768 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
769 'utf-8',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
770 'strict'
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
771 )
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
772
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
773 self.assertEqual(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
774 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
775 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
776 )
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
777
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
778 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
779 self.assertEqual(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
780 unicode(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
781 buffer('character buffers are decoded to unicode'),
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
782 'utf-8',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
783 'strict'
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
784 ),
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
785 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
786 )
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
787
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
788 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
789
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
790 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
791 utfTests = [
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
792 (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
793 (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
794 (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
795 (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
796 (u'+', '+-'),
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
797 (u'+-', '+--'),
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
798 (u'+?', '+-?'),
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
799 (u'\?', '+AFw?'),
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
800 (u'+?', '+-?'),
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
801 (ur'\\?', '+AFwAXA?'),
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
802 (ur'\\\?', '+AFwAXABc?'),
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
803 (ur'++--', '+-+---')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
804 ]
12051
d89556c04ef9 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 12025
diff changeset
805
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
806 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
807 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
808
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
809 # surrogates not supported
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
810 self.assertRaises(UnicodeError, unicode, '+3ADYAA-', 'utf-7')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
811
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
812 self.assertEqual(unicode('+3ADYAA-', 'utf-7', 'replace'), u'\ufffd')
12331
d195f17f2927 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 12248
diff changeset
813
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
814 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
815 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
816 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
817 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
818 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
819 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
820 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
821 self.assertEqual(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
822 (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
823 '\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
824 )
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
825 self.assertEqual(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
826 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
827 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
828 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
829 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
830 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
831 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
832 '\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
833 '\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
834 '\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
835 '\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
836 '\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
837 '\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
838 '\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
839 '\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
840 '\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
841 '\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
842 )
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
843
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
844 # UTF-8 specific decoding tests
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
845 self.assertEqual(unicode('\xf0\xa3\x91\x96', 'utf-8'), u'\U00023456' )
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
846 self.assertEqual(unicode('\xf0\x90\x80\x82', 'utf-8'), u'\U00010002' )
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
847 self.assertEqual(unicode('\xe2\x82\xac', 'utf-8'), u'\u20ac' )
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
848
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
849 # 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
850 # * 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
851 # UTF8_ERROR cases in PyUnicode_DecodeUTF8
12051
d89556c04ef9 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 12025
diff changeset
852
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
853 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
854 # 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
855 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
856 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
857 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
858 self.assertEqual(u'Andr\202 x'.encode('ascii','replace'), "Andr? x")
12051
d89556c04ef9 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 12025
diff changeset
859
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
860 # 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
861 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
862 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
863 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
864 self.assertEqual(unicode('Andr\202 x','ascii','replace'), u'Andr\uFFFD x')
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
865
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
866 # 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
867 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
868
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
869 # 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
870 self.assertRaises(UnicodeError, "\\".decode, "unicode-escape")
12051
d89556c04ef9 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 12025
diff changeset
871
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
872 # Error handling (bad decoder return)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
873 def search_function(encoding):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
874 def decode1(input, errors="strict"):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
875 return 42 # not a tuple
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
876 def encode1(input, errors="strict"):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
877 return 42 # not a tuple
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
878 def encode2(input, errors="strict"):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
879 return (42, 42) # no unicode
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
880 def decode2(input, errors="strict"):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
881 return (42, 42) # no unicode
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
882 if encoding=="test.unicode1":
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
883 return (encode1, decode1, None, None)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
884 elif encoding=="test.unicode2":
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
885 return (encode2, decode2, None, None)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
886 else:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
887 return None
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
888 codecs.register(search_function)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
889 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
890 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
891 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
892 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
893 # 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
894 import imp
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
895 self.assertRaises(
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
896 ImportError,
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
897 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
898 "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
899 [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
900 )
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
901
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
902 # 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
903 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
904
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
905 # 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
906 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
907
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
908 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
909 # Encoding
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
910 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
911 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
912 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
913 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
914 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
915 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
916 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
917
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
918 # Roundtrip safety for BMP (just the first 1024 chars)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
919 u = u''.join(map(unichr, xrange(1024)))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
920 for encoding in ('utf-7', '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
921 'raw_unicode_escape', '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
922 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
923
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
924 # Roundtrip safety for BMP (just the first 256 chars)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
925 u = 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
926 for encoding in ('latin-1',):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
927 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
928
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
929 # Roundtrip safety for BMP (just the first 128 chars)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
930 u = u''.join(map(unichr, xrange(128)))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
931 for encoding in ('ascii',):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
932 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
933
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
934 # 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
935 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
936 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
937 #'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
938 '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
939 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
940
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
941 # 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
942 # 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
943 # 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
944 # 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
945 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
946 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
947 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
948
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
949 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
950 # 0-127
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
951 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
952 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
953 'cp037', 'cp1026',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
954 'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
955 'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
956 '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
957 '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
958 '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
959 '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
960 '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
961
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
962 '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
963 '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
964 '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
965
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
966 '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
967 '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
968
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
969 ### 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
970 #'cp424',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
971
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
972 ### 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
973 #'cp875'
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
974
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
975 ):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
976 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
977
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
978 # 128-255
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
979 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
980 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
981 'cp037', 'cp1026',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
982 'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
983 'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
984 '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
985 '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
986 '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
987 '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
988 '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
989
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
990 ### 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
991 #'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
992 #'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
993 #'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
994 #'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
995 #'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
996
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
997 ### 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
998 #'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
999
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1000 ):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1001 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
1002
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1003 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
1004 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
1005 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
1006 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
1007 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
1008 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
1009
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1010 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
1011 class BitBucket:
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1012 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
1013 pass
24598
12e146171f3d Committing patch #591250 which provides "str1 in str2" when str1 is a
Barry Warsaw <barry@python.org>
parents: 24538
diff changeset
1014
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1015 out = BitBucket()
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1016 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
1017 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
1018 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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 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
1025
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1026 def test_mul(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1027 self.checkmethod('__mul__', u'abc', u'', -1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1028 self.checkmethod('__mul__', u'abc', u'', 0)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1029 self.checkmethod('__mul__', u'abc', u'abc', 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1030 self.checkmethod('__mul__', u'abc', u'abcabcabc', 3)
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(OverflowError, (10000*u'abc').__mul__, sys.maxint)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1032
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1033 def test_subscript(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1034 self.checkmethod('__getitem__', u'abc', u'a', 0)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1035 self.checkmethod('__getitem__', u'abc', u'c', -1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1036 self.checkmethod('__getitem__', u'abc', u'a', 0L)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1037 self.checkmethod('__getitem__', u'abc', u'abc', slice(0, 3))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1038 self.checkmethod('__getitem__', u'abc', u'abc', slice(0, 1000))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1039 self.checkmethod('__getitem__', u'abc', u'a', slice(0, 1))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1040 self.checkmethod('__getitem__', u'abc', u'', slice(0, 0))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1041 # FIXME What about negative indizes? This is handled differently by [] and __getitem__(slice)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1042
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1043 self.assertRaises(TypeError, u"abc".__getitem__, "def")
24598
12e146171f3d Committing patch #591250 which provides "str1 in str2" when str1 is a
Barry Warsaw <barry@python.org>
parents: 24538
diff changeset
1044
27304
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1045 def test_slice(self):
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1046 self.checkmethod('__getslice__', u'abc', u'abc', 0, 1000)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1047 self.checkmethod('__getslice__', u'abc', u'abc', 0, 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1048 self.checkmethod('__getslice__', u'abc', u'ab', 0, 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1049 self.checkmethod('__getslice__', u'abc', u'bc', 1, 3)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1050 self.checkmethod('__getslice__', u'abc', u'b', 1, 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1051 self.checkmethod('__getslice__', u'abc', u'', 2, 2)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1052 self.checkmethod('__getslice__', u'abc', u'', 1000, 1000)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1053 self.checkmethod('__getslice__', u'abc', u'', 2000, 1000)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1054 self.checkmethod('__getslice__', u'abc', u'', 2, 1)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1055 # FIXME What about negative indizes? This is handled differently by [] and __getslice__
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1056
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1057 def test_main():
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1058 suite = unittest.TestSuite()
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1059 suite.addTest(unittest.makeSuite(UnicodeTest))
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1060 test.test_support.run_suite(suite)
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1061
a555230be3cb Port test_unicode.py to PyUnit and add tests for error
Walter Dörwald <walter@livinglogic.de>
parents: 27176
diff changeset
1062 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
1063 test_main()