Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
test.test_unicode.UnicodeTest Class Reference
Inheritance diagram for test.test_unicode.UnicodeTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_unicode.UnicodeTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def checkequalnofix
def test_literals
def test_ascii
def test_repr
def test_iterators
def test_count
def test_find
def test_rfind
def test_index
def test_rindex
def test_maketrans_translate
def test_split
def test_join
def test_replace
def test_bytes_comparison
def test_comparison
def test_islower
def test_isupper
def test_istitle
def test_isspace
def test_isalpha
def test_isdecimal
def test_isdigit
def test_isnumeric
def test_isidentifier
def test_isprintable
def test_contains
def test_format
def test_format_map
def test_format_auto_numbering
def test_formatting
def test_startswith_endswith_errors
def test_format_float
def test_constructor
def test_codecs_utf7
def test_codecs_utf8
def test_utf8_decode_valid_sequences
def test_utf8_decode_invalid_sequences
def test_issue8271
def test_codecs_idna
def test_codecs_errors
def test_codecs
def test_codecs_charmap
def test_concatenation
def test_printing
def test_ucs4
def test_conversion
def test_unicode_repr
def test_printable_repr
def test_expandtabs_overflows_gracefully
def test_raiseMemError
def test_format_subclass
def test_from_format
def test_aswidechar
def test_aswidecharstring
def test_hash
def test_capitalize
def test_lower
def test_upper
def test_expandtabs
def test_additional_split
def test_additional_rsplit
def test_strip
def test_ljust
def test_rjust
def test_center
def test_swapcase
def test_zfill
def fixtype
def checkequal
def checkraises
def checkcall
def test_rsplit
def test_isalnum
def test_title
def test_splitlines
def test_startswith
def test_endswith
def test___contains__
def test_subscript
def test_slice
def test_extended_getslice
def test_mul
def test_floatformatting
def test_inplace_rewrites
def test_partition
def test_rpartition
def test_none_arguments
def test_find_etc_raise_correct_error_messages
def test_bug1001011

Public Attributes

 sval
 x
 mapping

Static Public Attributes

 type2test = str

Private Attributes

 _x

Detailed Description

Definition at line 36 of file test_unicode.py.


Member Function Documentation

def test.string_tests.BaseTest.checkcall (   self,
  obj,
  methodname,
  args 
) [inherited]

Reimplemented in test.test_userstring.UserStringTest.

Definition at line 83 of file string_tests.py.

00083 
00084     def checkcall(self, obj, methodname, *args):
00085         obj = self.fixtype(obj)
00086         args = self.fixtype(args)
00087         getattr(obj, methodname)(*args)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.string_tests.BaseTest.checkequal (   self,
  result,
  obj,
  methodname,
  args 
) [inherited]

Reimplemented in test.test_userstring.UserStringTest.

Definition at line 50 of file string_tests.py.

00050 
00051     def checkequal(self, result, obj, methodname, *args):
00052         result = self.fixtype(result)
00053         obj = self.fixtype(obj)
00054         args = self.fixtype(args)
00055         realresult = getattr(obj, methodname)(*args)
00056         self.assertEqual(
00057             result,
00058             realresult
00059         )
00060         # if the original is returned make sure that
00061         # this doesn't happen with subclasses
00062         if obj is realresult:
00063             try:
00064                 class subtype(self.__class__.type2test):
00065                     pass
00066             except TypeError:
00067                 pass  # Skip this if we can't subclass
00068             else:
00069                 obj = subtype(obj)
00070                 realresult = getattr(obj, methodname)(*args)
00071                 self.assertIsNot(obj, realresult)

Here is the call graph for this function:

def test.test_unicode.UnicodeTest.checkequalnofix (   self,
  result,
  object,
  methodname,
  args 
)

Definition at line 40 of file test_unicode.py.

00040 
00041     def checkequalnofix(self, result, object, methodname, *args):
00042         method = getattr(object, methodname)
00043         realresult = method(*args)
00044         self.assertEqual(realresult, result)
00045         self.assertTrue(type(realresult) is type(result))
00046 
00047         # if the original is returned make sure that
00048         # this doesn't happen with subclasses
00049         if realresult is object:
00050             class usub(str):
00051                 def __repr__(self):
00052                     return 'usub(%r)' % str.__repr__(self)
00053             object = usub(object)
00054             method = getattr(object, methodname)
00055             realresult = method(*args)
00056             self.assertEqual(realresult, result)
00057             self.assertTrue(object is not realresult)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.string_tests.BaseTest.checkraises (   self,
  exc,
  obj,
  methodname,
  args 
) [inherited]

Reimplemented in test.test_userstring.UserStringTest.

Definition at line 73 of file string_tests.py.

00073 
00074     def checkraises(self, exc, obj, methodname, *args):
00075         obj = self.fixtype(obj)
00076         args = self.fixtype(args)
00077         self.assertRaises(
00078             exc,
00079             getattr(obj, methodname),
00080             *args
00081         )

Here is the call graph for this function:

def test.string_tests.BaseTest.fixtype (   self,
  obj 
) [inherited]

Reimplemented in test.test_bytes.FixedStringTest.

Definition at line 34 of file string_tests.py.

00034 
00035     def fixtype(self, obj):
00036         if isinstance(obj, str):
00037             return self.__class__.type2test(obj)
00038         elif isinstance(obj, list):
00039             return [self.fixtype(x) for x in obj]
00040         elif isinstance(obj, tuple):
00041             return tuple([self.fixtype(x) for x in obj])
00042         elif isinstance(obj, dict):
00043             return dict([
00044                (self.fixtype(key), self.fixtype(value))
00045                for (key, value) in obj.items()
00046             ])
00047         else:
00048             return obj

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 992 of file string_tests.py.

00992 
00993     def test___contains__(self):
00994         self.checkequal(True, '', '__contains__', '')
00995         self.checkequal(True, 'abc', '__contains__', '')
00996         self.checkequal(False, 'abc', '__contains__', '\0')
00997         self.checkequal(True, '\0abc', '__contains__', '\0')
00998         self.checkequal(True, 'abc\0', '__contains__', '\0')
00999         self.checkequal(True, '\0abc', '__contains__', 'a')
01000         self.checkequal(True, 'asdf', '__contains__', 'asdf')
01001         self.checkequal(False, 'asd', '__contains__', 'asdf')
01002         self.checkequal(False, '', '__contains__', 'asdf')

Here is the call graph for this function:

Definition at line 698 of file string_tests.py.

00698 
00699     def test_additional_rsplit(self):
00700         self.checkequal(['this', 'is', 'the', 'rsplit', 'function'],
00701                          'this is the rsplit function', 'rsplit')
00702 
00703         # by whitespace
00704         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'rsplit')
00705         self.checkequal(['a b c', 'd'], 'a b c d', 'rsplit', None, 1)
00706         self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2)
00707         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 3)
00708         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 4)
00709         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None,
00710                         sys.maxsize-20)
00711         self.checkequal(['a b c d'], 'a b c d', 'rsplit', None, 0)
00712         self.checkequal(['a b c d'], 'a b c d  ', 'rsplit', None, 0)
00713         self.checkequal(['a  b', 'c', 'd'], 'a  b  c  d', 'rsplit', None, 2)
00714 
00715         self.checkequal([], '         ', 'rsplit')
00716         self.checkequal(['a'], '  a    ', 'rsplit')
00717         self.checkequal(['a', 'b'], '  a    b   ', 'rsplit')
00718         self.checkequal(['  a', 'b'], '  a    b   ', 'rsplit', None, 1)
00719         self.checkequal(['  a    b','c'], '  a    b   c   ', 'rsplit',
00720                         None, 1)
00721         self.checkequal(['  a', 'b', 'c'], '  a    b   c   ', 'rsplit',
00722                         None, 2)
00723         self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'rsplit', None, 88)
00724         aaa = ' a '*20
00725         self.checkequal(['a']*20, aaa, 'rsplit')
00726         self.checkequal([aaa[:-4]] + ['a'], aaa, 'rsplit', None, 1)
00727         self.checkequal([' a  a'] + ['a']*18, aaa, 'rsplit', None, 18)
00728 
00729         # mixed use of str and unicode
00730         self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', ' ', 2)

Here is the call graph for this function:

Definition at line 667 of file string_tests.py.

00667 
00668     def test_additional_split(self):
00669         self.checkequal(['this', 'is', 'the', 'split', 'function'],
00670             'this is the split function', 'split')
00671 
00672         # by whitespace
00673         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'split')
00674         self.checkequal(['a', 'b c d'], 'a b c d', 'split', None, 1)
00675         self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2)
00676         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 3)
00677         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 4)
00678         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None,
00679                         sys.maxsize-1)
00680         self.checkequal(['a b c d'], 'a b c d', 'split', None, 0)
00681         self.checkequal(['a b c d'], '  a b c d', 'split', None, 0)
00682         self.checkequal(['a', 'b', 'c  d'], 'a  b  c  d', 'split', None, 2)
00683 
00684         self.checkequal([], '         ', 'split')
00685         self.checkequal(['a'], '  a    ', 'split')
00686         self.checkequal(['a', 'b'], '  a    b   ', 'split')
00687         self.checkequal(['a', 'b   '], '  a    b   ', 'split', None, 1)
00688         self.checkequal(['a', 'b   c   '], '  a    b   c   ', 'split', None, 1)
00689         self.checkequal(['a', 'b', 'c   '], '  a    b   c   ', 'split', None, 2)
00690         self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'split')
00691         aaa = ' a '*20
00692         self.checkequal(['a']*20, aaa, 'split')
00693         self.checkequal(['a'] + [aaa[4:]], aaa, 'split', None, 1)
00694         self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19)
00695 
00696         # mixed use of str and unicode
00697         self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', ' ', 2)

Here is the call graph for this function:

Definition at line 67 of file test_unicode.py.

00067 
00068     def test_ascii(self):
00069         if not sys.platform.startswith('java'):
00070             # Test basic sanity of repr()
00071             self.assertEqual(ascii('abc'), "'abc'")
00072             self.assertEqual(ascii('ab\\c'), "'ab\\\\c'")
00073             self.assertEqual(ascii('ab\\'), "'ab\\\\'")
00074             self.assertEqual(ascii('\\c'), "'\\\\c'")
00075             self.assertEqual(ascii('\\'), "'\\\\'")
00076             self.assertEqual(ascii('\n'), "'\\n'")
00077             self.assertEqual(ascii('\r'), "'\\r'")
00078             self.assertEqual(ascii('\t'), "'\\t'")
00079             self.assertEqual(ascii('\b'), "'\\x08'")
00080             self.assertEqual(ascii("'\""), """'\\'"'""")
00081             self.assertEqual(ascii("'\""), """'\\'"'""")
00082             self.assertEqual(ascii("'"), '''"'"''')
00083             self.assertEqual(ascii('"'), """'"'""")
00084             latin1repr = (
00085                 "'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r"
00086                 "\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a"
00087                 "\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHI"
00088                 "JKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f"
00089                 "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d"
00090                 "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b"
00091                 "\\x9c\\x9d\\x9e\\x9f\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9"
00092                 "\\xaa\\xab\\xac\\xad\\xae\\xaf\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7"
00093                 "\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5"
00094                 "\\xc6\\xc7\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\\xd0\\xd1\\xd2\\xd3"
00095                 "\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\\xe0\\xe1"
00096                 "\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef"
00097                 "\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd"
00098                 "\\xfe\\xff'")
00099             testrepr = ascii(''.join(map(chr, range(256))))
00100             self.assertEqual(testrepr, latin1repr)
00101             # Test ascii works on wide unicode escapes without overflow.
00102             self.assertEqual(ascii("\U00010000" * 39 + "\uffff" * 4096),
00103                              ascii("\U00010000" * 39 + "\uffff" * 4096))
00104 
00105             class WrongRepr:
00106                 def __repr__(self):
00107                     return b'byte-repr'
00108             self.assertRaises(TypeError, ascii, WrongRepr())

Here is the call graph for this function:

Definition at line 1491 of file test_unicode.py.

01491 
01492     def test_aswidechar(self):
01493         from _testcapi import unicode_aswidechar
01494         support.import_module('ctypes')
01495         from ctypes import c_wchar, sizeof
01496 
01497         wchar, size = unicode_aswidechar('abcdef', 2)
01498         self.assertEqual(size, 2)
01499         self.assertEqual(wchar, 'ab')
01500 
01501         wchar, size = unicode_aswidechar('abc', 3)
01502         self.assertEqual(size, 3)
01503         self.assertEqual(wchar, 'abc')
01504 
01505         wchar, size = unicode_aswidechar('abc', 4)
01506         self.assertEqual(size, 3)
01507         self.assertEqual(wchar, 'abc\0')
01508 
01509         wchar, size = unicode_aswidechar('abc', 10)
01510         self.assertEqual(size, 3)
01511         self.assertEqual(wchar, 'abc\0')
01512 
01513         wchar, size = unicode_aswidechar('abc\0def', 20)
01514         self.assertEqual(size, 7)
01515         self.assertEqual(wchar, 'abc\0def\0')
01516 
01517         nonbmp = chr(0x10ffff)
01518         if sizeof(c_wchar) == 2:
01519             buflen = 3
01520             nchar = 2
01521         else: # sizeof(c_wchar) == 4
01522             buflen = 2
01523             nchar = 1
01524         wchar, size = unicode_aswidechar(nonbmp, buflen)
01525         self.assertEqual(size, nchar)
01526         self.assertEqual(wchar, nonbmp + '\0')

Here is the call graph for this function:

Definition at line 1528 of file test_unicode.py.

01528 
01529     def test_aswidecharstring(self):
01530         from _testcapi import unicode_aswidecharstring
01531         support.import_module('ctypes')
01532         from ctypes import c_wchar, sizeof
01533 
01534         wchar, size = unicode_aswidecharstring('abc')
01535         self.assertEqual(size, 3)
01536         self.assertEqual(wchar, 'abc\0')
01537 
01538         wchar, size = unicode_aswidecharstring('abc\0def')
01539         self.assertEqual(size, 7)
01540         self.assertEqual(wchar, 'abc\0def\0')
01541 
01542         nonbmp = chr(0x10ffff)
01543         if sizeof(c_wchar) == 2:
01544             nchar = 2
01545         else: # sizeof(c_wchar) == 4
01546             nchar = 1
01547         wchar, size = unicode_aswidecharstring(nonbmp)
01548         self.assertEqual(size, nchar)
01549         self.assertEqual(wchar, nonbmp + '\0')
01550 

Here is the call graph for this function:

Definition at line 1247 of file string_tests.py.

01247 
01248     def test_bug1001011(self):
01249         # Make sure join returns a NEW object for single item sequences
01250         # involving a subclass.
01251         # Make sure that it is of the appropriate type.
01252         # Check the optimisation still occurs for standard objects.
01253         t = self.type2test
01254         class subclass(t):
01255             pass
01256         s1 = subclass("abcd")
01257         s2 = t().join([s1])
01258         self.assertIsNot(s1, s2)
01259         self.assertIs(type(s2), t)
01260 
01261         s1 = t("abcd")
01262         s2 = t().join([s1])
01263         self.assertIs(s1, s2)
01264 
01265         # Should also test mixed-type join.
01266         if t is str:
01267             s1 = subclass("abcd")
01268             s2 = "".join([s1])
01269             self.assertIsNot(s1, s2)
01270             self.assertIs(type(s2), t)
01271 
01272             s1 = t("abcd")
01273             s2 = "".join([s1])
01274             self.assertIs(s1, s2)

Here is the call graph for this function:

Definition at line 278 of file test_unicode.py.

00278 
00279     def test_bytes_comparison(self):
00280         with support.check_warnings():
00281             warnings.simplefilter('ignore', BytesWarning)
00282             self.assertEqual('abc' == b'abc', False)
00283             self.assertEqual('abc' != b'abc', True)
00284             self.assertEqual('abc' == bytearray(b'abc'), False)
00285             self.assertEqual('abc' != bytearray(b'abc'), True)

Here is the call graph for this function:

Definition at line 637 of file string_tests.py.

00637 
00638     def test_capitalize(self):
00639         self.checkequal(' hello ', ' hello ', 'capitalize')
00640         self.checkequal('Hello ', 'Hello ','capitalize')
00641         self.checkequal('Hello ', 'hello ','capitalize')
00642         self.checkequal('Aaaa', 'aaaa', 'capitalize')
00643         self.checkequal('Aaaa', 'AaAa', 'capitalize')
00644 
00645         self.checkraises(TypeError, 'hello', 'capitalize', 42)

Here is the call graph for this function:

def test.string_tests.CommonTest.test_center (   self) [inherited]

Definition at line 769 of file string_tests.py.

00769 
00770     def test_center(self):
00771         self.checkequal('   abc    ', 'abc', 'center', 10)
00772         self.checkequal(' abc  ', 'abc', 'center', 6)
00773         self.checkequal('abc', 'abc', 'center', 3)
00774         self.checkequal('abc', 'abc', 'center', 2)
00775         self.checkequal('***abc****', 'abc', 'center', 10, '*')
00776         self.checkraises(TypeError, 'abc', 'center')

Here is the call graph for this function:

Definition at line 1195 of file test_unicode.py.

01195 
01196     def test_codecs(self):
01197         # Encoding
01198         self.assertEqual('hello'.encode('ascii'), b'hello')
01199         self.assertEqual('hello'.encode('utf-7'), b'hello')
01200         self.assertEqual('hello'.encode('utf-8'), b'hello')
01201         self.assertEqual('hello'.encode('utf8'), b'hello')
01202         self.assertEqual('hello'.encode('utf-16-le'), b'h\000e\000l\000l\000o\000')
01203         self.assertEqual('hello'.encode('utf-16-be'), b'\000h\000e\000l\000l\000o')
01204         self.assertEqual('hello'.encode('latin-1'), b'hello')
01205 
01206         # Roundtrip safety for BMP (just the first 1024 chars)
01207         for c in range(1024):
01208             u = chr(c)
01209             for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le',
01210                              'utf-16-be', 'raw_unicode_escape',
01211                              'unicode_escape', 'unicode_internal'):
01212                 self.assertEqual(str(u.encode(encoding),encoding), u)
01213 
01214         # Roundtrip safety for BMP (just the first 256 chars)
01215         for c in range(256):
01216             u = chr(c)
01217             for encoding in ('latin-1',):
01218                 self.assertEqual(str(u.encode(encoding),encoding), u)
01219 
01220         # Roundtrip safety for BMP (just the first 128 chars)
01221         for c in range(128):
01222             u = chr(c)
01223             for encoding in ('ascii',):
01224                 self.assertEqual(str(u.encode(encoding),encoding), u)
01225 
01226         # Roundtrip safety for non-BMP (just a few chars)
01227         u = '\U00010001\U00020002\U00030003\U00040004\U00050005'
01228         for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
01229                          #'raw_unicode_escape',
01230                          'unicode_escape', 'unicode_internal'):
01231             self.assertEqual(str(u.encode(encoding),encoding), u)
01232 
01233         # UTF-8 must be roundtrip safe for all UCS-2 code points
01234         # This excludes surrogates: in the full range, there would be
01235         # a surrogate pair (\udbff\udc00), which gets converted back
01236         # to a non-BMP character (\U0010fc00)
01237         u = ''.join(map(chr, list(range(0,0xd800)) +
01238                              list(range(0xe000,0x10000))))
01239         for encoding in ('utf-8',):
01240             self.assertEqual(str(u.encode(encoding),encoding), u)

Here is the call graph for this function:

Definition at line 1241 of file test_unicode.py.

01241 
01242     def test_codecs_charmap(self):
01243         # 0-127
01244         s = bytes(range(128))
01245         for encoding in (
01246             'cp037', 'cp1026',
01247             'cp437', 'cp500', 'cp720', 'cp737', 'cp775', 'cp850',
01248             'cp852', 'cp855', 'cp858', 'cp860', 'cp861', 'cp862',
01249             'cp863', 'cp865', 'cp866',
01250             'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
01251             'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6',
01252             'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1',
01253             'mac_cyrillic', 'mac_latin2',
01254 
01255             'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
01256             'cp1256', 'cp1257', 'cp1258',
01257             'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
01258 
01259             'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
01260             'cp1006', 'iso8859_8',
01261 
01262             ### These have undefined mappings:
01263             #'cp424',
01264 
01265             ### These fail the round-trip:
01266             #'cp875'
01267 
01268             ):
01269             self.assertEqual(str(s, encoding).encode(encoding), s)
01270 
01271         # 128-255
01272         s = bytes(range(128, 256))
01273         for encoding in (
01274             'cp037', 'cp1026',
01275             'cp437', 'cp500', 'cp720', 'cp737', 'cp775', 'cp850',
01276             'cp852', 'cp855', 'cp858', 'cp860', 'cp861', 'cp862',
01277             'cp863', 'cp865', 'cp866',
01278             'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
01279             'iso8859_2', 'iso8859_4', 'iso8859_5',
01280             'iso8859_9', 'koi8_r', 'latin_1',
01281             'mac_cyrillic', 'mac_latin2',
01282 
01283             ### These have undefined mappings:
01284             #'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
01285             #'cp1256', 'cp1257', 'cp1258',
01286             #'cp424', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
01287             #'iso8859_3', 'iso8859_6', 'iso8859_7',
01288             #'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
01289 
01290             ### These fail the round-trip:
01291             #'cp1006', 'cp875', 'iso8859_8',
01292 
01293             ):
01294             self.assertEqual(str(s, encoding).encode(encoding), s)

Here is the call graph for this function:

Definition at line 1148 of file test_unicode.py.

01148 
01149     def test_codecs_errors(self):
01150         # Error handling (encoding)
01151         self.assertRaises(UnicodeError, 'Andr\202 x'.encode, 'ascii')
01152         self.assertRaises(UnicodeError, 'Andr\202 x'.encode, 'ascii','strict')
01153         self.assertEqual('Andr\202 x'.encode('ascii','ignore'), b"Andr x")
01154         self.assertEqual('Andr\202 x'.encode('ascii','replace'), b"Andr? x")
01155         self.assertEqual('Andr\202 x'.encode('ascii', 'replace'),
01156                          'Andr\202 x'.encode('ascii', errors='replace'))
01157         self.assertEqual('Andr\202 x'.encode('ascii', 'ignore'),
01158                          'Andr\202 x'.encode(encoding='ascii', errors='ignore'))
01159 
01160         # Error handling (decoding)
01161         self.assertRaises(UnicodeError, str, b'Andr\202 x', 'ascii')
01162         self.assertRaises(UnicodeError, str, b'Andr\202 x', 'ascii', 'strict')
01163         self.assertEqual(str(b'Andr\202 x', 'ascii', 'ignore'), "Andr x")
01164         self.assertEqual(str(b'Andr\202 x', 'ascii', 'replace'), 'Andr\uFFFD x')
01165 
01166         # Error handling (unknown character names)
01167         self.assertEqual(b"\\N{foo}xx".decode("unicode-escape", "ignore"), "xx")
01168 
01169         # Error handling (truncated escape sequence)
01170         self.assertRaises(UnicodeError, b"\\".decode, "unicode-escape")
01171 
01172         self.assertRaises(TypeError, b"hello".decode, "test.unicode1")
01173         self.assertRaises(TypeError, str, b"hello", "test.unicode2")
01174         self.assertRaises(TypeError, "hello".encode, "test.unicode1")
01175         self.assertRaises(TypeError, "hello".encode, "test.unicode2")
01176         # executes PyUnicode_Encode()
01177         import imp
01178         self.assertRaises(
01179             ImportError,
01180             imp.find_module,
01181             "non-existing module",
01182             ["non-existing dir"]
01183         )
01184 
01185         # Error handling (wrong arguments)
01186         self.assertRaises(TypeError, "hello".encode, 42, 42, 42)
01187 
01188         # Error handling (lone surrogate in PyUnicode_TransformDecimalToASCII())
01189         self.assertRaises(UnicodeError, int, "\ud800")
01190         self.assertRaises(UnicodeError, int, "\udf00")
01191         self.assertRaises(UnicodeError, float, "\ud800")
01192         self.assertRaises(UnicodeError, float, "\udf00")
01193         self.assertRaises(UnicodeError, complex, "\ud800")
01194         self.assertRaises(UnicodeError, complex, "\udf00")

Here is the call graph for this function:

Definition at line 1144 of file test_unicode.py.

01144 
01145     def test_codecs_idna(self):
01146         # Test whether trailing dot is preserved
01147         self.assertEqual("www.python.org.".encode("idna"), b"www.python.org.")

Here is the call graph for this function:

Definition at line 912 of file test_unicode.py.

00912 
00913     def test_codecs_utf7(self):
00914         utfTests = [
00915             ('A\u2262\u0391.', b'A+ImIDkQ.'),             # RFC2152 example
00916             ('Hi Mom -\u263a-!', b'Hi Mom -+Jjo--!'),     # RFC2152 example
00917             ('\u65E5\u672C\u8A9E', b'+ZeVnLIqe-'),        # RFC2152 example
00918             ('Item 3 is \u00a31.', b'Item 3 is +AKM-1.'), # RFC2152 example
00919             ('+', b'+-'),
00920             ('+-', b'+--'),
00921             ('+?', b'+-?'),
00922             ('\?', b'+AFw?'),
00923             ('+?', b'+-?'),
00924             (r'\\?', b'+AFwAXA?'),
00925             (r'\\\?', b'+AFwAXABc?'),
00926             (r'++--', b'+-+---'),
00927             ('\U000abcde', b'+2m/c3g-'),                  # surrogate pairs
00928             ('/', b'/'),
00929         ]
00930 
00931         for (x, y) in utfTests:
00932             self.assertEqual(x.encode('utf-7'), y)
00933 
00934         # Unpaired surrogates not supported
00935         self.assertRaises(UnicodeError, str, b'+3ADYAA-', 'utf-7')
00936 
00937         self.assertEqual(str(b'+3ADYAA-', 'utf-7', 'replace'), '\ufffd\ufffd')
00938 
00939         # Issue #2242: crash on some Windows/MSVC versions
00940         self.assertEqual(b'+\xc1'.decode('utf-7'), '\xc1')
00941 
00942         # Direct encoded characters
00943         set_d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'(),-./:?"
00944         # Optional direct characters
00945         set_o = '!"#$%&*;<=>@[]^_`{|}'
00946         for c in set_d:
00947             self.assertEqual(c.encode('utf7'), c.encode('ascii'))
00948             self.assertEqual(c.encode('ascii').decode('utf7'), c)
00949         for c in set_o:
00950             self.assertEqual(c.encode('ascii').decode('utf7'), c)

Here is the call graph for this function:

Definition at line 951 of file test_unicode.py.

00951 
00952     def test_codecs_utf8(self):
00953         self.assertEqual(''.encode('utf-8'), b'')
00954         self.assertEqual('\u20ac'.encode('utf-8'), b'\xe2\x82\xac')
00955         if sys.maxunicode == 65535:
00956             self.assertEqual('\ud800\udc02'.encode('utf-8'), b'\xf0\x90\x80\x82')
00957             self.assertEqual('\ud84d\udc56'.encode('utf-8'), b'\xf0\xa3\x91\x96')
00958         self.assertEqual('\ud800'.encode('utf-8', 'surrogatepass'), b'\xed\xa0\x80')
00959         self.assertEqual('\udc00'.encode('utf-8', 'surrogatepass'), b'\xed\xb0\x80')
00960         if sys.maxunicode == 65535:
00961             self.assertEqual(
00962                 ('\ud800\udc02'*1000).encode('utf-8'),
00963                 b'\xf0\x90\x80\x82'*1000)
00964         self.assertEqual(
00965             '\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f'
00966             '\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00'
00967             '\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c'
00968             '\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067'
00969             '\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das'
00970             ' Nunstuck git und'.encode('utf-8'),
00971             b'\xe6\xad\xa3\xe7\xa2\xba\xe3\x81\xab\xe8\xa8\x80\xe3\x81'
00972             b'\x86\xe3\x81\xa8\xe7\xbf\xbb\xe8\xa8\xb3\xe3\x81\xaf\xe3'
00973             b'\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x81\xbe'
00974             b'\xe3\x81\x9b\xe3\x82\x93\xe3\x80\x82\xe4\xb8\x80\xe9\x83'
00975             b'\xa8\xe3\x81\xaf\xe3\x83\x89\xe3\x82\xa4\xe3\x83\x84\xe8'
00976             b'\xaa\x9e\xe3\x81\xa7\xe3\x81\x99\xe3\x81\x8c\xe3\x80\x81'
00977             b'\xe3\x81\x82\xe3\x81\xa8\xe3\x81\xaf\xe3\x81\xa7\xe3\x81'
00978             b'\x9f\xe3\x82\x89\xe3\x82\x81\xe3\x81\xa7\xe3\x81\x99\xe3'
00979             b'\x80\x82\xe5\xae\x9f\xe9\x9a\x9b\xe3\x81\xab\xe3\x81\xaf'
00980             b'\xe3\x80\x8cWenn ist das Nunstuck git und'
00981         )
00982 
00983         # UTF-8 specific decoding tests
00984         self.assertEqual(str(b'\xf0\xa3\x91\x96', 'utf-8'), '\U00023456' )
00985         self.assertEqual(str(b'\xf0\x90\x80\x82', 'utf-8'), '\U00010002' )
00986         self.assertEqual(str(b'\xe2\x82\xac', 'utf-8'), '\u20ac' )
00987 
00988         # Other possible utf-8 test cases:
00989         # * strict decoding testing for all of the
00990         #   UTF8_ERROR cases in PyUnicode_DecodeUTF8

Here is the call graph for this function:

Definition at line 286 of file test_unicode.py.

00286 
00287     def test_comparison(self):
00288         # Comparisons:
00289         self.assertEqual('abc', 'abc')
00290         self.assertTrue('abcd' > 'abc')
00291         self.assertTrue('abc' < 'abcd')
00292 
00293         if 0:
00294             # Move these tests to a Unicode collation module test...
00295             # Testing UTF-16 code point order comparisons...
00296 
00297             # No surrogates, no fixup required.
00298             self.assertTrue('\u0061' < '\u20ac')
00299             # Non surrogate below surrogate value, no fixup required
00300             self.assertTrue('\u0061' < '\ud800\udc02')
00301 
00302             # Non surrogate above surrogate value, fixup required
00303             def test_lecmp(s, s2):
00304                 self.assertTrue(s < s2)
00305 
00306             def test_fixup(s):
00307                 s2 = '\ud800\udc01'
00308                 test_lecmp(s, s2)
00309                 s2 = '\ud900\udc01'
00310                 test_lecmp(s, s2)
00311                 s2 = '\uda00\udc01'
00312                 test_lecmp(s, s2)
00313                 s2 = '\udb00\udc01'
00314                 test_lecmp(s, s2)
00315                 s2 = '\ud800\udd01'
00316                 test_lecmp(s, s2)
00317                 s2 = '\ud900\udd01'
00318                 test_lecmp(s, s2)
00319                 s2 = '\uda00\udd01'
00320                 test_lecmp(s, s2)
00321                 s2 = '\udb00\udd01'
00322                 test_lecmp(s, s2)
00323                 s2 = '\ud800\ude01'
00324                 test_lecmp(s, s2)
00325                 s2 = '\ud900\ude01'
00326                 test_lecmp(s, s2)
00327                 s2 = '\uda00\ude01'
00328                 test_lecmp(s, s2)
00329                 s2 = '\udb00\ude01'
00330                 test_lecmp(s, s2)
00331                 s2 = '\ud800\udfff'
00332                 test_lecmp(s, s2)
00333                 s2 = '\ud900\udfff'
00334                 test_lecmp(s, s2)
00335                 s2 = '\uda00\udfff'
00336                 test_lecmp(s, s2)
00337                 s2 = '\udb00\udfff'
00338                 test_lecmp(s, s2)
00339 
00340                 test_fixup('\ue000')
00341                 test_fixup('\uff61')
00342 
00343         # Surrogates on both sides, no fixup required
00344         self.assertTrue('\ud800\udc02' < '\ud84d\udc56')

Here is the call graph for this function:

Definition at line 1295 of file test_unicode.py.

01295 
01296     def test_concatenation(self):
01297         self.assertEqual(("abc" "def"), "abcdef")
01298         self.assertEqual(("abc" "def"), "abcdef")
01299         self.assertEqual(("abc" "def"), "abcdef")
01300         self.assertEqual(("abc" "def" "ghi"), "abcdefghi")
01301         self.assertEqual(("abc" "def" "ghi"), "abcdefghi")

Here is the call graph for this function:

Definition at line 842 of file test_unicode.py.

00842 
00843     def test_constructor(self):
00844         # unicode(obj) tests (this maps to PyObject_Unicode() at C level)
00845 
00846         self.assertEqual(
00847             str('unicode remains unicode'),
00848             'unicode remains unicode'
00849         )
00850 
00851         class UnicodeSubclass(str):
00852             pass
00853 
00854         self.assertEqual(
00855             str(UnicodeSubclass('unicode subclass becomes unicode')),
00856             'unicode subclass becomes unicode'
00857         )
00858 
00859         self.assertEqual(
00860             str('strings are converted to unicode'),
00861             'strings are converted to unicode'
00862         )
00863 
00864         class StringCompat:
00865             def __init__(self, x):
00866                 self.x = x
00867             def __str__(self):
00868                 return self.x
00869 
00870         self.assertEqual(
00871             str(StringCompat('__str__ compatible objects are recognized')),
00872             '__str__ compatible objects are recognized'
00873         )
00874 
00875         # unicode(obj) is compatible to str():
00876 
00877         o = StringCompat('unicode(obj) is compatible to str()')
00878         self.assertEqual(str(o), 'unicode(obj) is compatible to str()')
00879         self.assertEqual(str(o), 'unicode(obj) is compatible to str()')
00880 
00881         for obj in (123, 123.45, 123):
00882             self.assertEqual(str(obj), str(str(obj)))
00883 
00884         # unicode(obj, encoding, error) tests (this maps to
00885         # PyUnicode_FromEncodedObject() at C level)
00886 
00887         if not sys.platform.startswith('java'):
00888             self.assertRaises(
00889                 TypeError,
00890                 str,
00891                 'decoding unicode is not supported',
00892                 'utf-8',
00893                 'strict'
00894             )
00895 
00896         self.assertEqual(
00897             str(b'strings are decoded to unicode', 'utf-8', 'strict'),
00898             'strings are decoded to unicode'
00899         )
00900 
00901         if not sys.platform.startswith('java'):
00902             self.assertEqual(
00903                 str(
00904                     memoryview(b'character buffers are decoded to unicode'),
00905                     'utf-8',
00906                     'strict'
00907                 ),
00908                 'character buffers are decoded to unicode'
00909             )
00910 
00911         self.assertRaises(TypeError, str, 42, 42, 42)

Here is the call graph for this function:

Definition at line 426 of file test_unicode.py.

00426 
00427     def test_contains(self):
00428         # Testing Unicode contains method
00429         self.assertIn('a', 'abdb')
00430         self.assertIn('a', 'bdab')
00431         self.assertIn('a', 'bdaba')
00432         self.assertIn('a', 'bdba')
00433         self.assertNotIn('a', 'bdb')
00434         self.assertIn('a', 'bdba')
00435         self.assertIn('a', ('a',1,None))
00436         self.assertIn('a', (1,None,'a'))
00437         self.assertIn('a', ('a',1,None))
00438         self.assertIn('a', (1,None,'a'))
00439         self.assertNotIn('a', ('x',1,'y'))
00440         self.assertNotIn('a', ('x',1,None))
00441         self.assertNotIn('abcd', 'abcxxxx')
00442         self.assertIn('ab', 'abcd')
00443         self.assertIn('ab', 'abc')
00444         self.assertIn('ab', (1,None,'ab'))
00445         self.assertIn('', 'abc')
00446         self.assertIn('', '')
00447         self.assertIn('', 'abc')
00448         self.assertNotIn('\0', 'abc')
00449         self.assertIn('\0', '\0abc')
00450         self.assertIn('\0', 'abc\0')
00451         self.assertIn('a', '\0abc')
00452         self.assertIn('asdf', 'asdf')
00453         self.assertNotIn('asdf', 'asd')
00454         self.assertNotIn('asdf', '')
00455 
00456         self.assertRaises(TypeError, "abc".__contains__)

Here is the call graph for this function:

Definition at line 1338 of file test_unicode.py.

01338 
01339     def test_conversion(self):
01340         # Make sure __unicode__() works properly
01341         class Foo0:
01342             def __str__(self):
01343                 return "foo"
01344 
01345         class Foo1:
01346             def __str__(self):
01347                 return "foo"
01348 
01349         class Foo2(object):
01350             def __str__(self):
01351                 return "foo"
01352 
01353         class Foo3(object):
01354             def __str__(self):
01355                 return "foo"
01356 
01357         class Foo4(str):
01358             def __str__(self):
01359                 return "foo"
01360 
01361         class Foo5(str):
01362             def __str__(self):
01363                 return "foo"
01364 
01365         class Foo6(str):
01366             def __str__(self):
01367                 return "foos"
01368 
01369             def __str__(self):
01370                 return "foou"
01371 
01372         class Foo7(str):
01373             def __str__(self):
01374                 return "foos"
01375             def __str__(self):
01376                 return "foou"
01377 
01378         class Foo8(str):
01379             def __new__(cls, content=""):
01380                 return str.__new__(cls, 2*content)
01381             def __str__(self):
01382                 return self
01383 
01384         class Foo9(str):
01385             def __str__(self):
01386                 return "not unicode"
01387 
01388         self.assertEqual(str(Foo0()), "foo")
01389         self.assertEqual(str(Foo1()), "foo")
01390         self.assertEqual(str(Foo2()), "foo")
01391         self.assertEqual(str(Foo3()), "foo")
01392         self.assertEqual(str(Foo4("bar")), "foo")
01393         self.assertEqual(str(Foo5("bar")), "foo")
01394         self.assertEqual(str(Foo6("bar")), "foou")
01395         self.assertEqual(str(Foo7("bar")), "foou")
01396         self.assertEqual(str(Foo8("foo")), "foofoo")
01397         self.assertEqual(str(Foo9("foo")), "not unicode")

Here is the call graph for this function:

Reimplemented from test.string_tests.BaseTest.

Definition at line 159 of file test_unicode.py.

00159 
00160     def test_count(self):
00161         string_tests.CommonTest.test_count(self)
00162         # check mixed argument types
00163         self.checkequalnofix(3,  'aaa', 'count', 'a')
00164         self.checkequalnofix(0,  'aaa', 'count', 'b')
00165         self.checkequalnofix(3, 'aaa', 'count',  'a')
00166         self.checkequalnofix(0, 'aaa', 'count',  'b')
00167         self.checkequalnofix(0, 'aaa', 'count',  'b')
00168         self.checkequalnofix(1, 'aaa', 'count',  'a', -1)
00169         self.checkequalnofix(3, 'aaa', 'count',  'a', -10)
00170         self.checkequalnofix(2, 'aaa', 'count',  'a', 0, -1)
00171         self.checkequalnofix(0, 'aaa', 'count',  'a', 0, -10)

Here is the call graph for this function:

Definition at line 943 of file string_tests.py.

00943 
00944     def test_endswith(self):
00945         self.checkequal(True, 'hello', 'endswith', 'lo')
00946         self.checkequal(False, 'hello', 'endswith', 'he')
00947         self.checkequal(True, 'hello', 'endswith', '')
00948         self.checkequal(False, 'hello', 'endswith', 'hello world')
00949         self.checkequal(False, 'helloworld', 'endswith', 'worl')
00950         self.checkequal(True, 'helloworld', 'endswith', 'worl', 3, 9)
00951         self.checkequal(True, 'helloworld', 'endswith', 'world', 3, 12)
00952         self.checkequal(True, 'helloworld', 'endswith', 'lowo', 1, 7)
00953         self.checkequal(True, 'helloworld', 'endswith', 'lowo', 2, 7)
00954         self.checkequal(True, 'helloworld', 'endswith', 'lowo', 3, 7)
00955         self.checkequal(False, 'helloworld', 'endswith', 'lowo', 4, 7)
00956         self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, 8)
00957         self.checkequal(False, 'ab', 'endswith', 'ab', 0, 1)
00958         self.checkequal(False, 'ab', 'endswith', 'ab', 0, 0)
00959 
00960         # test negative indices
00961         self.checkequal(True, 'hello', 'endswith', 'lo', -2)
00962         self.checkequal(False, 'hello', 'endswith', 'he', -2)
00963         self.checkequal(True, 'hello', 'endswith', '', -3, -3)
00964         self.checkequal(False, 'hello', 'endswith', 'hello world', -10, -2)
00965         self.checkequal(False, 'helloworld', 'endswith', 'worl', -6)
00966         self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, -1)
00967         self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, 9)
00968         self.checkequal(True, 'helloworld', 'endswith', 'world', -7, 12)
00969         self.checkequal(True, 'helloworld', 'endswith', 'lowo', -99, -3)
00970         self.checkequal(True, 'helloworld', 'endswith', 'lowo', -8, -3)
00971         self.checkequal(True, 'helloworld', 'endswith', 'lowo', -7, -3)
00972         self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, -4)
00973         self.checkequal(False, 'helloworld', 'endswith', 'lowo', -8, -2)
00974 
00975         self.checkraises(TypeError, 'hello', 'endswith')
00976         self.checkraises(TypeError, 'hello', 'endswith', 42)
00977 
00978         # test tuple arguments
00979         self.checkequal(False, 'hello', 'endswith', ('he', 'ha'))
00980         self.checkequal(True, 'hello', 'endswith', ('lo', 'llo'))
00981         self.checkequal(True, 'hello', 'endswith', ('hellox', 'hello'))
00982         self.checkequal(False, 'hello', 'endswith', ())
00983         self.checkequal(True, 'helloworld', 'endswith', ('hellowo',
00984                                                            'rld', 'lowo'), 3)
00985         self.checkequal(False, 'helloworld', 'endswith', ('hellowo', 'ello',
00986                                                             'rld'), 3, -1)
00987         self.checkequal(True, 'hello', 'endswith', ('hell', 'ell'), 0, -1)
00988         self.checkequal(False, 'hello', 'endswith', ('he', 'hel'), 0, 1)
00989         self.checkequal(True, 'hello', 'endswith', ('he', 'hell'), 0, 4)
00990 
00991         self.checkraises(TypeError, 'hello', 'endswith', (42,))

Here is the call graph for this function:

Reimplemented from test.string_tests.BaseTest.

Definition at line 656 of file string_tests.py.

00656 
00657     def test_expandtabs(self):
00658         self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
00659         self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
00660         self.checkequal('abc\rab  def\ng   hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 4)
00661         self.checkequal('abc\r\nab  def\ng   hi', 'abc\r\nab\tdef\ng\thi', 'expandtabs', 4)
00662         self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
00663         self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
00664         self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4)
00665 
00666         self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42)

Here is the call graph for this function:

Definition at line 1414 of file test_unicode.py.

01414 
01415     def test_expandtabs_overflows_gracefully(self):
01416         # This test only affects 32-bit platforms because expandtabs can only take
01417         # an int as the max value, not a 64-bit C long.  If expandtabs is changed
01418         # to take a 64-bit long, this test should apply to all platforms.
01419         if sys.maxsize > (1 << 32) or struct.calcsize('P') != 4:
01420             return
01421         self.assertRaises(OverflowError, 't\tt\t'.expandtabs, sys.maxsize)

Here is the call graph for this function:

Definition at line 1027 of file string_tests.py.

01027 
01028     def test_extended_getslice(self):
01029         # Test extended slicing by comparing with list slicing.
01030         s = string.ascii_letters + string.digits
01031         indices = (0, None, 1, 3, 41, -1, -2, -37)
01032         for start in indices:
01033             for stop in indices:
01034                 # Skip step 0 (invalid)
01035                 for step in indices[1:]:
01036                     L = list(s)[start:stop:step]
01037                     self.checkequal("".join(L), s, '__getitem__',
01038                                     slice(start, stop, step))

Here is the call graph for this function:

Reimplemented from test.string_tests.BaseTest.

Definition at line 172 of file test_unicode.py.

00172 
00173     def test_find(self):
00174         self.checkequalnofix(0,  'abcdefghiabc', 'find', 'abc')
00175         self.checkequalnofix(9,  'abcdefghiabc', 'find', 'abc', 1)
00176         self.checkequalnofix(-1, 'abcdefghiabc', 'find', 'def', 4)
00177 
00178         self.assertRaises(TypeError, 'hello'.find)
00179         self.assertRaises(TypeError, 'hello'.find, 42)

Here is the call graph for this function:

Definition at line 1224 of file string_tests.py.

01224 
01225     def test_find_etc_raise_correct_error_messages(self):
01226         # issue 11828
01227         s = 'hello'
01228         x = 'x'
01229         self.assertRaisesRegex(TypeError, r'^find\(', s.find,
01230                                 x, None, None, None)
01231         self.assertRaisesRegex(TypeError, r'^rfind\(', s.rfind,
01232                                 x, None, None, None)
01233         self.assertRaisesRegex(TypeError, r'^index\(', s.index,
01234                                 x, None, None, None)
01235         self.assertRaisesRegex(TypeError, r'^rindex\(', s.rindex,
01236                                 x, None, None, None)
01237         self.assertRaisesRegex(TypeError, r'^count\(', s.count,
01238                                 x, None, None, None)
01239         self.assertRaisesRegex(TypeError, r'^startswith\(', s.startswith,
01240                                 x, None, None, None)
01241         self.assertRaisesRegex(TypeError, r'^endswith\(', s.endswith,
01242                                 x, None, None, None)
01243 

Here is the call graph for this function:

Definition at line 1128 of file string_tests.py.

01128 
01129     def test_floatformatting(self):
01130         # float formatting
01131         for prec in range(100):
01132             format = '%%.%if' % prec
01133             value = 0.01
01134             for x in range(60):
01135                 value = value * 3.14159265359 / 3.0 * 10.0
01136                 self.checkcall(format, "__mod__", value)

Here is the call graph for this function:

Definition at line 457 of file test_unicode.py.

00457 
00458     def test_format(self):
00459         self.assertEqual(''.format(), '')
00460         self.assertEqual('a'.format(), 'a')
00461         self.assertEqual('ab'.format(), 'ab')
00462         self.assertEqual('a{{'.format(), 'a{')
00463         self.assertEqual('a}}'.format(), 'a}')
00464         self.assertEqual('{{b'.format(), '{b')
00465         self.assertEqual('}}b'.format(), '}b')
00466         self.assertEqual('a{{b'.format(), 'a{b')
00467 
00468         # examples from the PEP:
00469         import datetime
00470         self.assertEqual("My name is {0}".format('Fred'), "My name is Fred")
00471         self.assertEqual("My name is {0[name]}".format(dict(name='Fred')),
00472                          "My name is Fred")
00473         self.assertEqual("My name is {0} :-{{}}".format('Fred'),
00474                          "My name is Fred :-{}")
00475 
00476         d = datetime.date(2007, 8, 18)
00477         self.assertEqual("The year is {0.year}".format(d),
00478                          "The year is 2007")
00479 
00480         # classes we'll use for testing
00481         class C:
00482             def __init__(self, x=100):
00483                 self._x = x
00484             def __format__(self, spec):
00485                 return spec
00486 
00487         class D:
00488             def __init__(self, x):
00489                 self.x = x
00490             def __format__(self, spec):
00491                 return str(self.x)
00492 
00493         # class with __str__, but no __format__
00494         class E:
00495             def __init__(self, x):
00496                 self.x = x
00497             def __str__(self):
00498                 return 'E(' + self.x + ')'
00499 
00500         # class with __repr__, but no __format__ or __str__
00501         class F:
00502             def __init__(self, x):
00503                 self.x = x
00504             def __repr__(self):
00505                 return 'F(' + self.x + ')'
00506 
00507         # class with __format__ that forwards to string, for some format_spec's
00508         class G:
00509             def __init__(self, x):
00510                 self.x = x
00511             def __str__(self):
00512                 return "string is " + self.x
00513             def __format__(self, format_spec):
00514                 if format_spec == 'd':
00515                     return 'G(' + self.x + ')'
00516                 return object.__format__(self, format_spec)
00517 
00518         class I(datetime.date):
00519             def __format__(self, format_spec):
00520                 return self.strftime(format_spec)
00521 
00522         class J(int):
00523             def __format__(self, format_spec):
00524                 return int.__format__(self * 2, format_spec)
00525 
00526 
00527         self.assertEqual(''.format(), '')
00528         self.assertEqual('abc'.format(), 'abc')
00529         self.assertEqual('{0}'.format('abc'), 'abc')
00530         self.assertEqual('{0:}'.format('abc'), 'abc')
00531 #        self.assertEqual('{ 0 }'.format('abc'), 'abc')
00532         self.assertEqual('X{0}'.format('abc'), 'Xabc')
00533         self.assertEqual('{0}X'.format('abc'), 'abcX')
00534         self.assertEqual('X{0}Y'.format('abc'), 'XabcY')
00535         self.assertEqual('{1}'.format(1, 'abc'), 'abc')
00536         self.assertEqual('X{1}'.format(1, 'abc'), 'Xabc')
00537         self.assertEqual('{1}X'.format(1, 'abc'), 'abcX')
00538         self.assertEqual('X{1}Y'.format(1, 'abc'), 'XabcY')
00539         self.assertEqual('{0}'.format(-15), '-15')
00540         self.assertEqual('{0}{1}'.format(-15, 'abc'), '-15abc')
00541         self.assertEqual('{0}X{1}'.format(-15, 'abc'), '-15Xabc')
00542         self.assertEqual('{{'.format(), '{')
00543         self.assertEqual('}}'.format(), '}')
00544         self.assertEqual('{{}}'.format(), '{}')
00545         self.assertEqual('{{x}}'.format(), '{x}')
00546         self.assertEqual('{{{0}}}'.format(123), '{123}')
00547         self.assertEqual('{{{{0}}}}'.format(), '{{0}}')
00548         self.assertEqual('}}{{'.format(), '}{')
00549         self.assertEqual('}}x{{'.format(), '}x{')
00550 
00551         # weird field names
00552         self.assertEqual("{0[foo-bar]}".format({'foo-bar':'baz'}), 'baz')
00553         self.assertEqual("{0[foo bar]}".format({'foo bar':'baz'}), 'baz')
00554         self.assertEqual("{0[ ]}".format({' ':3}), '3')
00555 
00556         self.assertEqual('{foo._x}'.format(foo=C(20)), '20')
00557         self.assertEqual('{1}{0}'.format(D(10), D(20)), '2010')
00558         self.assertEqual('{0._x.x}'.format(C(D('abc'))), 'abc')
00559         self.assertEqual('{0[0]}'.format(['abc', 'def']), 'abc')
00560         self.assertEqual('{0[1]}'.format(['abc', 'def']), 'def')
00561         self.assertEqual('{0[1][0]}'.format(['abc', ['def']]), 'def')
00562         self.assertEqual('{0[1][0].x}'.format(['abc', [D('def')]]), 'def')
00563 
00564         # strings
00565         self.assertEqual('{0:.3s}'.format('abc'), 'abc')
00566         self.assertEqual('{0:.3s}'.format('ab'), 'ab')
00567         self.assertEqual('{0:.3s}'.format('abcdef'), 'abc')
00568         self.assertEqual('{0:.0s}'.format('abcdef'), '')
00569         self.assertEqual('{0:3.3s}'.format('abc'), 'abc')
00570         self.assertEqual('{0:2.3s}'.format('abc'), 'abc')
00571         self.assertEqual('{0:2.2s}'.format('abc'), 'ab')
00572         self.assertEqual('{0:3.2s}'.format('abc'), 'ab ')
00573         self.assertEqual('{0:x<0s}'.format('result'), 'result')
00574         self.assertEqual('{0:x<5s}'.format('result'), 'result')
00575         self.assertEqual('{0:x<6s}'.format('result'), 'result')
00576         self.assertEqual('{0:x<7s}'.format('result'), 'resultx')
00577         self.assertEqual('{0:x<8s}'.format('result'), 'resultxx')
00578         self.assertEqual('{0: <7s}'.format('result'), 'result ')
00579         self.assertEqual('{0:<7s}'.format('result'), 'result ')
00580         self.assertEqual('{0:>7s}'.format('result'), ' result')
00581         self.assertEqual('{0:>8s}'.format('result'), '  result')
00582         self.assertEqual('{0:^8s}'.format('result'), ' result ')
00583         self.assertEqual('{0:^9s}'.format('result'), ' result  ')
00584         self.assertEqual('{0:^10s}'.format('result'), '  result  ')
00585         self.assertEqual('{0:10000}'.format('a'), 'a' + ' ' * 9999)
00586         self.assertEqual('{0:10000}'.format(''), ' ' * 10000)
00587         self.assertEqual('{0:10000000}'.format(''), ' ' * 10000000)
00588 
00589         # format specifiers for user defined type
00590         self.assertEqual('{0:abc}'.format(C()), 'abc')
00591 
00592         # !r, !s and !a coercions
00593         self.assertEqual('{0!s}'.format('Hello'), 'Hello')
00594         self.assertEqual('{0!s:}'.format('Hello'), 'Hello')
00595         self.assertEqual('{0!s:15}'.format('Hello'), 'Hello          ')
00596         self.assertEqual('{0!s:15s}'.format('Hello'), 'Hello          ')
00597         self.assertEqual('{0!r}'.format('Hello'), "'Hello'")
00598         self.assertEqual('{0!r:}'.format('Hello'), "'Hello'")
00599         self.assertEqual('{0!r}'.format(F('Hello')), 'F(Hello)')
00600         self.assertEqual('{0!r}'.format('\u0378'), "'\\u0378'") # nonprintable
00601         self.assertEqual('{0!r}'.format('\u0374'), "'\u0374'")  # printable
00602         self.assertEqual('{0!r}'.format(F('\u0374')), 'F(\u0374)')
00603         self.assertEqual('{0!a}'.format('Hello'), "'Hello'")
00604         self.assertEqual('{0!a}'.format('\u0378'), "'\\u0378'") # nonprintable
00605         self.assertEqual('{0!a}'.format('\u0374'), "'\\u0374'") # printable
00606         self.assertEqual('{0!a:}'.format('Hello'), "'Hello'")
00607         self.assertEqual('{0!a}'.format(F('Hello')), 'F(Hello)')
00608         self.assertEqual('{0!a}'.format(F('\u0374')), 'F(\\u0374)')
00609 
00610         # test fallback to object.__format__
00611         self.assertEqual('{0}'.format({}), '{}')
00612         self.assertEqual('{0}'.format([]), '[]')
00613         self.assertEqual('{0}'.format([1]), '[1]')
00614 
00615         self.assertEqual('{0:d}'.format(G('data')), 'G(data)')
00616         self.assertEqual('{0!s}'.format(G('data')), 'string is data')
00617 
00618         msg = 'object.__format__ with a non-empty format string is deprecated'
00619         with support.check_warnings((msg, PendingDeprecationWarning)):
00620             self.assertEqual('{0:^10}'.format(E('data')), ' E(data)  ')
00621             self.assertEqual('{0:^10s}'.format(E('data')), ' E(data)  ')
00622             self.assertEqual('{0:>15s}'.format(G('data')), ' string is data')
00623 
00624         self.assertEqual("{0:date: %Y-%m-%d}".format(I(year=2007,
00625                                                        month=8,
00626                                                        day=27)),
00627                          "date: 2007-08-27")
00628 
00629         # test deriving from a builtin type and overriding __format__
00630         self.assertEqual("{0}".format(J(10)), "20")
00631 
00632 
00633         # string format specifiers
00634         self.assertEqual('{0:}'.format('a'), 'a')
00635 
00636         # computed format specifiers
00637         self.assertEqual("{0:.{1}}".format('hello world', 5), 'hello')
00638         self.assertEqual("{0:.{1}s}".format('hello world', 5), 'hello')
00639         self.assertEqual("{0:.{precision}s}".format('hello world', precision=5), 'hello')
00640         self.assertEqual("{0:{width}.{precision}s}".format('hello world', width=10, precision=5), 'hello     ')
00641         self.assertEqual("{0:{width}.{precision}s}".format('hello world', width='10', precision='5'), 'hello     ')
00642 
00643         # test various errors
00644         self.assertRaises(ValueError, '{'.format)
00645         self.assertRaises(ValueError, '}'.format)
00646         self.assertRaises(ValueError, 'a{'.format)
00647         self.assertRaises(ValueError, 'a}'.format)
00648         self.assertRaises(ValueError, '{a'.format)
00649         self.assertRaises(ValueError, '}a'.format)
00650         self.assertRaises(IndexError, '{0}'.format)
00651         self.assertRaises(IndexError, '{1}'.format, 'abc')
00652         self.assertRaises(KeyError,   '{x}'.format)
00653         self.assertRaises(ValueError, "}{".format)
00654         self.assertRaises(ValueError, "abc{0:{}".format)
00655         self.assertRaises(ValueError, "{0".format)
00656         self.assertRaises(IndexError, "{0.}".format)
00657         self.assertRaises(ValueError, "{0.}".format, 0)
00658         self.assertRaises(IndexError, "{0[}".format)
00659         self.assertRaises(ValueError, "{0[}".format, [])
00660         self.assertRaises(KeyError,   "{0]}".format)
00661         self.assertRaises(ValueError, "{0.[]}".format, 0)
00662         self.assertRaises(ValueError, "{0..foo}".format, 0)
00663         self.assertRaises(ValueError, "{0[0}".format, 0)
00664         self.assertRaises(ValueError, "{0[0:foo}".format, 0)
00665         self.assertRaises(KeyError,   "{c]}".format)
00666         self.assertRaises(ValueError, "{{ {{{0}}".format, 0)
00667         self.assertRaises(ValueError, "{0}}".format, 0)
00668         self.assertRaises(KeyError,   "{foo}".format, bar=3)
00669         self.assertRaises(ValueError, "{0!x}".format, 3)
00670         self.assertRaises(ValueError, "{0!}".format, 0)
00671         self.assertRaises(ValueError, "{0!rs}".format, 0)
00672         self.assertRaises(ValueError, "{!}".format)
00673         self.assertRaises(IndexError, "{:}".format)
00674         self.assertRaises(IndexError, "{:s}".format)
00675         self.assertRaises(IndexError, "{}".format)
00676         big = "23098475029384702983476098230754973209482573"
00677         self.assertRaises(ValueError, ("{" + big + "}").format)
00678         self.assertRaises(ValueError, ("{[" + big + "]}").format, [0])
00679 
00680         # issue 6089
00681         self.assertRaises(ValueError, "{0[0]x}".format, [None])
00682         self.assertRaises(ValueError, "{0[0](10)}".format, [None])
00683 
00684         # can't have a replacement on the field name portion
00685         self.assertRaises(TypeError, '{0[{1}]}'.format, 'abcdefg', 4)
00686 
00687         # exceed maximum recursion depth
00688         self.assertRaises(ValueError, "{0:{1:{2}}}".format, 'abc', 's', '')
00689         self.assertRaises(ValueError, "{0:{1:{2:{3:{4:{5:{6}}}}}}}".format,
00690                           0, 1, 2, 3, 4, 5, 6, 7)
00691 
00692         # string format spec errors
00693         self.assertRaises(ValueError, "{0:-s}".format, '')
00694         self.assertRaises(ValueError, format, "", "-")
00695         self.assertRaises(ValueError, "{0:=s}".format, '')
00696 
00697         # Alternate formatting is not supported
00698         self.assertRaises(ValueError, format, '', '#')
00699         self.assertRaises(ValueError, format, '', '#20')

Here is the call graph for this function:

Definition at line 745 of file test_unicode.py.

00745 
00746     def test_format_auto_numbering(self):
00747         class C:
00748             def __init__(self, x=100):
00749                 self._x = x
00750             def __format__(self, spec):
00751                 return spec
00752 
00753         self.assertEqual('{}'.format(10), '10')
00754         self.assertEqual('{:5}'.format('s'), 's    ')
00755         self.assertEqual('{!r}'.format('s'), "'s'")
00756         self.assertEqual('{._x}'.format(C(10)), '10')
00757         self.assertEqual('{[1]}'.format([1, 2]), '2')
00758         self.assertEqual('{[a]}'.format({'a':4, 'b':2}), '4')
00759         self.assertEqual('a{}b{}c'.format(0, 1), 'a0b1c')
00760 
00761         self.assertEqual('a{:{}}b'.format('x', '^10'), 'a    x     b')
00762         self.assertEqual('a{:{}x}b'.format(20, '#'), 'a0x14b')
00763 
00764         # can't mix and match numbering and auto-numbering
00765         self.assertRaises(ValueError, '{}{1}'.format, 1, 2)
00766         self.assertRaises(ValueError, '{1}{}'.format, 1, 2)
00767         self.assertRaises(ValueError, '{:{1}}'.format, 1, 2)
00768         self.assertRaises(ValueError, '{0:{}}'.format, 1, 2)
00769 
00770         # can mix and match auto-numbering and named
00771         self.assertEqual('{f}{}'.format(4, f='test'), 'test4')
00772         self.assertEqual('{}{f}'.format(4, f='test'), '4test')
00773         self.assertEqual('{:{f}}{g}{}'.format(1, 3, g='g', f=2), ' 1g3')
00774         self.assertEqual('{f:{}}{}{g}'.format(2, 4, f=1, g='g'), ' 14g')

Here is the call graph for this function:

Definition at line 838 of file test_unicode.py.

00838 
00839     def test_format_float(self):
00840         # should not format with a comma, but always with C locale
00841         self.assertEqual('1.0', '%.1f' % 1.0)

Here is the call graph for this function:

Definition at line 700 of file test_unicode.py.

00700 
00701     def test_format_map(self):
00702         self.assertEqual(''.format_map({}), '')
00703         self.assertEqual('a'.format_map({}), 'a')
00704         self.assertEqual('ab'.format_map({}), 'ab')
00705         self.assertEqual('a{{'.format_map({}), 'a{')
00706         self.assertEqual('a}}'.format_map({}), 'a}')
00707         self.assertEqual('{{b'.format_map({}), '{b')
00708         self.assertEqual('}}b'.format_map({}), '}b')
00709         self.assertEqual('a{{b'.format_map({}), 'a{b')
00710 
00711         # using mappings
00712         class Mapping(dict):
00713             def __missing__(self, key):
00714                 return key
00715         self.assertEqual('{hello}'.format_map(Mapping()), 'hello')
00716         self.assertEqual('{a} {world}'.format_map(Mapping(a='hello')), 'hello world')
00717 
00718         class InternalMapping:
00719             def __init__(self):
00720                 self.mapping = {'a': 'hello'}
00721             def __getitem__(self, key):
00722                 return self.mapping[key]
00723         self.assertEqual('{a}'.format_map(InternalMapping()), 'hello')
00724 
00725 
00726         class C:
00727             def __init__(self, x=100):
00728                 self._x = x
00729             def __format__(self, spec):
00730                 return spec
00731         self.assertEqual('{foo._x}'.format_map({'foo': C(20)}), '20')
00732 
00733         # test various errors
00734         self.assertRaises(TypeError, '{'.format_map)
00735         self.assertRaises(TypeError, '}'.format_map)
00736         self.assertRaises(TypeError, 'a{'.format_map)
00737         self.assertRaises(TypeError, 'a}'.format_map)
00738         self.assertRaises(TypeError, '{a'.format_map)
00739         self.assertRaises(TypeError, '}a'.format_map)
00740 
00741         # issue #12579: can't supply positional params to format_map
00742         self.assertRaises(ValueError, '{}'.format_map, {'a' : 2})
00743         self.assertRaises(ValueError, '{}'.format_map, 'a')
00744         self.assertRaises(ValueError, '{a} {}'.format_map, {"a" : 2, "b" : 1})

Here is the call graph for this function:

Definition at line 1434 of file test_unicode.py.

01434 
01435     def test_format_subclass(self):
01436         class S(str):
01437             def __str__(self):
01438                 return '__str__ overridden'
01439         s = S('xxx')
01440         self.assertEqual("%s" % s, '__str__ overridden')
01441         self.assertEqual("{}".format(s), '__str__ overridden')

Here is the call graph for this function:

Reimplemented from test.string_tests.MixinStrUnicodeUserStringTest.

Definition at line 775 of file test_unicode.py.

00775 
00776     def test_formatting(self):
00777         string_tests.MixinStrUnicodeUserStringTest.test_formatting(self)
00778         # Testing Unicode formatting strings...
00779         self.assertEqual("%s, %s" % ("abc", "abc"), 'abc, abc')
00780         self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", 1, 2, 3), 'abc, abc, 1, 2.000000,  3.00')
00781         self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", 1, -2, 3), 'abc, abc, 1, -2.000000,  3.00')
00782         self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", -1, -2, 3.5), 'abc, abc, -1, -2.000000,  3.50')
00783         self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", -1, -2, 3.57), 'abc, abc, -1, -2.000000,  3.57')
00784         self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", -1, -2, 1003.57), 'abc, abc, -1, -2.000000, 1003.57')
00785         if not sys.platform.startswith('java'):
00786             self.assertEqual("%r, %r" % (b"abc", "abc"), "b'abc', 'abc'")
00787             self.assertEqual("%r" % ("\u1234",), "'\u1234'")
00788             self.assertEqual("%a" % ("\u1234",), "'\\u1234'")
00789         self.assertEqual("%(x)s, %(y)s" % {'x':"abc", 'y':"def"}, 'abc, def')
00790         self.assertEqual("%(x)s, %(\xfc)s" % {'x':"abc", '\xfc':"def"}, 'abc, def')
00791 
00792         self.assertEqual('%c' % 0x1234, '\u1234')
00793         self.assertEqual('%c' % 0x21483, '\U00021483')
00794         self.assertRaises(OverflowError, "%c".__mod__, (0x110000,))
00795         self.assertEqual('%c' % '\U00021483', '\U00021483')
00796         self.assertRaises(TypeError, "%c".__mod__, "aa")
00797         self.assertRaises(ValueError, "%.1\u1032f".__mod__, (1.0/3))
00798         self.assertRaises(TypeError, "%i".__mod__, "aa")
00799 
00800         # formatting jobs delegated from the string implementation:
00801         self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...')
00802         self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...')
00803         self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...')
00804         self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...')
00805         self.assertEqual('...%(foo)s...' % {'foo':"abc",'def':123},  '...abc...')
00806         self.assertEqual('...%(foo)s...' % {'foo':"abc",'def':123}, '...abc...')
00807         self.assertEqual('...%s...%s...%s...%s...' % (1,2,3,"abc"), '...1...2...3...abc...')
00808         self.assertEqual('...%%...%%s...%s...%s...%s...%s...' % (1,2,3,"abc"), '...%...%s...1...2...3...abc...')
00809         self.assertEqual('...%s...' % "abc", '...abc...')
00810         self.assertEqual('%*s' % (5,'abc',), '  abc')
00811         self.assertEqual('%*s' % (-5,'abc',), 'abc  ')
00812         self.assertEqual('%*.*s' % (5,2,'abc',), '   ab')
00813         self.assertEqual('%*.*s' % (5,3,'abc',), '  abc')
00814         self.assertEqual('%i %*.*s' % (10, 5,3,'abc',), '10   abc')
00815         self.assertEqual('%i%s %*.*s' % (10, 3, 5, 3, 'abc',), '103   abc')
00816         self.assertEqual('%c' % 'a', 'a')
00817         class Wrapper:
00818             def __str__(self):
00819                 return '\u1234'
00820         self.assertEqual('%s' % Wrapper(), '\u1234')
00821 
00822         # issue 3382
00823         NAN = float('nan')
00824         INF = float('inf')
00825         self.assertEqual('%f' % NAN, 'nan')
00826         self.assertEqual('%F' % NAN, 'NAN')
00827         self.assertEqual('%f' % INF, 'inf')
00828         self.assertEqual('%F' % INF, 'INF')

Here is the call graph for this function:

Definition at line 1443 of file test_unicode.py.

01443 
01444     def test_from_format(self):
01445         support.import_module('ctypes')
01446         from ctypes import pythonapi, py_object, c_int
01447         if sys.maxunicode == 65535:
01448             name = "PyUnicodeUCS2_FromFormat"
01449         else:
01450             name = "PyUnicodeUCS4_FromFormat"
01451         _PyUnicode_FromFormat = getattr(pythonapi, name)
01452         _PyUnicode_FromFormat.restype = py_object
01453 
01454         def PyUnicode_FromFormat(format, *args):
01455             cargs = tuple(
01456                 py_object(arg) if isinstance(arg, str) else arg
01457                 for arg in args)
01458             return _PyUnicode_FromFormat(format, *cargs)
01459 
01460         # ascii format, non-ascii argument
01461         text = PyUnicode_FromFormat(b'ascii\x7f=%U', 'unicode\xe9')
01462         self.assertEqual(text, 'ascii\x7f=unicode\xe9')
01463 
01464         # non-ascii format, ascii argument: ensure that PyUnicode_FromFormatV()
01465         # raises an error
01466         self.assertRaisesRegex(ValueError,
01467             '^PyUnicode_FromFormatV\(\) expects an ASCII-encoded format '
01468             'string, got a non-ASCII byte: 0xe9$',
01469             PyUnicode_FromFormat, b'unicode\xe9=%s', 'ascii')
01470 
01471         self.assertEqual(PyUnicode_FromFormat(b'%c', c_int(0xabcd)), '\uabcd')
01472         self.assertEqual(PyUnicode_FromFormat(b'%c', c_int(0x10ffff)), '\U0010ffff')
01473 
01474         # other tests
01475         text = PyUnicode_FromFormat(b'%%A:%A', 'abc\xe9\uabcd\U0010ffff')
01476         self.assertEqual(text, r"%A:'abc\xe9\uabcd\U0010ffff'")
01477 
01478         text = PyUnicode_FromFormat(b'repr=%V', 'abc', b'xyz')
01479         self.assertEqual(text, 'repr=abc')
01480 
01481         # Test string decode from parameter of %s using utf-8.
01482         # b'\xe4\xba\xba\xe6\xb0\x91' is utf-8 encoded byte sequence of
01483         # '\u4eba\u6c11'
01484         text = PyUnicode_FromFormat(b'repr=%V', None, b'\xe4\xba\xba\xe6\xb0\x91')
01485         self.assertEqual(text, 'repr=\u4eba\u6c11')
01486 
01487         #Test replace error handler.
01488         text = PyUnicode_FromFormat(b'repr=%V', None, b'abc\xff')
01489         self.assertEqual(text, 'repr=abc\ufffd')

Here is the call graph for this function:

def test.string_tests.CommonTest.test_hash (   self) [inherited]

Definition at line 628 of file string_tests.py.

00628 
00629     def test_hash(self):
00630         # SF bug 1054139:  += optimization was not invalidating cached hash value
00631         a = self.type2test('DNSSEC')
00632         b = self.type2test('')
00633         for c in a:
00634             b += c
00635             hash(b)
00636         self.assertEqual(hash(a), hash(b))

Here is the call graph for this function:

Reimplemented from test.string_tests.BaseTest.

Definition at line 187 of file test_unicode.py.

00187 
00188     def test_index(self):
00189         string_tests.CommonTest.test_index(self)
00190         self.checkequalnofix(0, 'abcdefghiabc', 'index',  '')
00191         self.checkequalnofix(3, 'abcdefghiabc', 'index',  'def')
00192         self.checkequalnofix(0, 'abcdefghiabc', 'index',  'abc')
00193         self.checkequalnofix(9, 'abcdefghiabc', 'index',  'abc', 1)
00194         self.assertRaises(ValueError, 'abcdefghiabc'.index, 'hib')
00195         self.assertRaises(ValueError, 'abcdefghiab'.index,  'abc', 1)
00196         self.assertRaises(ValueError, 'abcdefghi'.index,  'ghi', 8)
00197         self.assertRaises(ValueError, 'abcdefghi'.index,  'ghi', -1)

Here is the call graph for this function:

Definition at line 1137 of file string_tests.py.

01137 
01138     def test_inplace_rewrites(self):
01139         # Check that strings don't copy and modify cached single-character strings
01140         self.checkequal('a', 'A', 'lower')
01141         self.checkequal(True, 'A', 'isupper')
01142         self.checkequal('A', 'a', 'upper')
01143         self.checkequal(True, 'a', 'islower')
01144 
01145         self.checkequal('a', 'A', 'replace', 'A', 'a')
01146         self.checkequal(True, 'A', 'isupper')
01147 
01148         self.checkequal('A', 'a', 'capitalize')
01149         self.checkequal(True, 'a', 'islower')
01150 
01151         self.checkequal('A', 'a', 'swapcase')
01152         self.checkequal(True, 'a', 'islower')
01153 
01154         self.checkequal('A', 'a', 'title')
01155         self.checkequal(True, 'a', 'islower')

Here is the call graph for this function:

Definition at line 858 of file string_tests.py.

00858 
00859     def test_isalnum(self):
00860         self.checkequal(False, '', 'isalnum')
00861         self.checkequal(True, 'a', 'isalnum')
00862         self.checkequal(True, 'A', 'isalnum')
00863         self.checkequal(False, '\n', 'isalnum')
00864         self.checkequal(True, '123abc456', 'isalnum')
00865         self.checkequal(True, 'a1b3c', 'isalnum')
00866         self.checkequal(False, 'aBc000 ', 'isalnum')
00867         self.checkequal(False, 'abc\n', 'isalnum')
00868         self.checkraises(TypeError, 'abc', 'isalnum', 42)

Here is the call graph for this function:

Reimplemented from test.string_tests.MixinStrUnicodeUserStringTest.

Definition at line 365 of file test_unicode.py.

00365 
00366     def test_isalpha(self):
00367         string_tests.MixinStrUnicodeUserStringTest.test_isalpha(self)
00368         self.checkequalnofix(True, '\u1FFc', 'isalpha')

Here is the call graph for this function:

Definition at line 369 of file test_unicode.py.

00369 
00370     def test_isdecimal(self):
00371         self.checkequalnofix(False, '', 'isdecimal')
00372         self.checkequalnofix(False, 'a', 'isdecimal')
00373         self.checkequalnofix(True, '0', 'isdecimal')
00374         self.checkequalnofix(False, '\u2460', 'isdecimal') # CIRCLED DIGIT ONE
00375         self.checkequalnofix(False, '\xbc', 'isdecimal') # VULGAR FRACTION ONE QUARTER
00376         self.checkequalnofix(True, '\u0660', 'isdecimal') # ARABIC-INDIC DIGIT ZERO
00377         self.checkequalnofix(True, '0123456789', 'isdecimal')
00378         self.checkequalnofix(False, '0123456789a', 'isdecimal')
00379 
00380         self.checkraises(TypeError, 'abc', 'isdecimal', 42)

Here is the call graph for this function:

Reimplemented from test.string_tests.MixinStrUnicodeUserStringTest.

Definition at line 381 of file test_unicode.py.

00381 
00382     def test_isdigit(self):
00383         string_tests.MixinStrUnicodeUserStringTest.test_isdigit(self)
00384         self.checkequalnofix(True, '\u2460', 'isdigit')
00385         self.checkequalnofix(False, '\xbc', 'isdigit')
00386         self.checkequalnofix(True, '\u0660', 'isdigit')

Here is the call graph for this function:

Definition at line 399 of file test_unicode.py.

00399 
00400     def test_isidentifier(self):
00401         self.assertTrue("a".isidentifier())
00402         self.assertTrue("Z".isidentifier())
00403         self.assertTrue("_".isidentifier())
00404         self.assertTrue("b0".isidentifier())
00405         self.assertTrue("bc".isidentifier())
00406         self.assertTrue("b_".isidentifier())
00407         self.assertTrue("ยต".isidentifier())
00408         self.assertTrue("๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข".isidentifier())
00409 
00410         self.assertFalse(" ".isidentifier())
00411         self.assertFalse("[".isidentifier())
00412         self.assertFalse("ยฉ".isidentifier())
00413         self.assertFalse("0".isidentifier())

Here is the call graph for this function:

Reimplemented from test.string_tests.MixinStrUnicodeUserStringTest.

Definition at line 345 of file test_unicode.py.

00345 
00346     def test_islower(self):
00347         string_tests.MixinStrUnicodeUserStringTest.test_islower(self)
00348         self.checkequalnofix(False, '\u1FFc', 'islower')

Here is the call graph for this function:

Definition at line 387 of file test_unicode.py.

00387 
00388     def test_isnumeric(self):
00389         self.checkequalnofix(False, '', 'isnumeric')
00390         self.checkequalnofix(False, 'a', 'isnumeric')
00391         self.checkequalnofix(True, '0', 'isnumeric')
00392         self.checkequalnofix(True, '\u2460', 'isnumeric')
00393         self.checkequalnofix(True, '\xbc', 'isnumeric')
00394         self.checkequalnofix(True, '\u0660', 'isnumeric')
00395         self.checkequalnofix(True, '0123456789', 'isnumeric')
00396         self.checkequalnofix(False, '0123456789a', 'isnumeric')
00397 
00398         self.assertRaises(TypeError, "abc".isnumeric, 42)

Here is the call graph for this function:

Definition at line 414 of file test_unicode.py.

00414 
00415     def test_isprintable(self):
00416         self.assertTrue("".isprintable())
00417         self.assertTrue(" ".isprintable())
00418         self.assertTrue("abcdefg".isprintable())
00419         self.assertFalse("abcdefg\n".isprintable())
00420         # some defined Unicode character
00421         self.assertTrue("\u0374".isprintable())
00422         # undefined character
00423         self.assertFalse("\u0378".isprintable())
00424         # single surrogate character
00425         self.assertFalse("\ud800".isprintable())

Here is the call graph for this function:

Reimplemented from test.string_tests.MixinStrUnicodeUserStringTest.

Definition at line 359 of file test_unicode.py.

00359 
00360     def test_isspace(self):
00361         string_tests.MixinStrUnicodeUserStringTest.test_isspace(self)
00362         self.checkequalnofix(True, '\u2000', 'isspace')
00363         self.checkequalnofix(True, '\u200a', 'isspace')
00364         self.checkequalnofix(False, '\u2014', 'isspace')

Here is the call graph for this function:

Definition at line 1055 of file test_unicode.py.

01055 
01056     def test_issue8271(self):
01057         # Issue #8271: during the decoding of an invalid UTF-8 byte sequence,
01058         # only the start byte and the continuation byte(s) are now considered
01059         # invalid, instead of the number of bytes specified by the start byte.
01060         # See http://www.unicode.org/versions/Unicode5.2.0/ch03.pdf (page 95,
01061         # table 3-8, Row 2) for more information about the algorithm used.
01062         FFFD = '\ufffd'
01063         sequences = [
01064             # invalid start bytes
01065             (b'\x80', FFFD), # continuation byte
01066             (b'\x80\x80', FFFD*2), # 2 continuation bytes
01067             (b'\xc0', FFFD),
01068             (b'\xc0\xc0', FFFD*2),
01069             (b'\xc1', FFFD),
01070             (b'\xc1\xc0', FFFD*2),
01071             (b'\xc0\xc1', FFFD*2),
01072             # with start byte of a 2-byte sequence
01073             (b'\xc2', FFFD), # only the start byte
01074             (b'\xc2\xc2', FFFD*2), # 2 start bytes
01075             (b'\xc2\xc2\xc2', FFFD*3), # 2 start bytes
01076             (b'\xc2\x41', FFFD+'A'), # invalid continuation byte
01077             # with start byte of a 3-byte sequence
01078             (b'\xe1', FFFD), # only the start byte
01079             (b'\xe1\xe1', FFFD*2), # 2 start bytes
01080             (b'\xe1\xe1\xe1', FFFD*3), # 3 start bytes
01081             (b'\xe1\xe1\xe1\xe1', FFFD*4), # 4 start bytes
01082             (b'\xe1\x80', FFFD), # only 1 continuation byte
01083             (b'\xe1\x41', FFFD+'A'), # invalid continuation byte
01084             (b'\xe1\x41\x80', FFFD+'A'+FFFD), # invalid cb followed by valid cb
01085             (b'\xe1\x41\x41', FFFD+'AA'), # 2 invalid continuation bytes
01086             (b'\xe1\x80\x41', FFFD+'A'), # only 1 valid continuation byte
01087             (b'\xe1\x80\xe1\x41', FFFD*2+'A'), # 1 valid and the other invalid
01088             (b'\xe1\x41\xe1\x80', FFFD+'A'+FFFD), # 1 invalid and the other valid
01089             # with start byte of a 4-byte sequence
01090             (b'\xf1', FFFD), # only the start byte
01091             (b'\xf1\xf1', FFFD*2), # 2 start bytes
01092             (b'\xf1\xf1\xf1', FFFD*3), # 3 start bytes
01093             (b'\xf1\xf1\xf1\xf1', FFFD*4), # 4 start bytes
01094             (b'\xf1\xf1\xf1\xf1\xf1', FFFD*5), # 5 start bytes
01095             (b'\xf1\x80', FFFD), # only 1 continuation bytes
01096             (b'\xf1\x80\x80', FFFD), # only 2 continuation bytes
01097             (b'\xf1\x80\x41', FFFD+'A'), # 1 valid cb and 1 invalid
01098             (b'\xf1\x80\x41\x41', FFFD+'AA'), # 1 valid cb and 1 invalid
01099             (b'\xf1\x80\x80\x41', FFFD+'A'), # 2 valid cb and 1 invalid
01100             (b'\xf1\x41\x80', FFFD+'A'+FFFD), # 1 invalid cv and 1 valid
01101             (b'\xf1\x41\x80\x80', FFFD+'A'+FFFD*2), # 1 invalid cb and 2 invalid
01102             (b'\xf1\x41\x80\x41', FFFD+'A'+FFFD+'A'), # 2 invalid cb and 1 invalid
01103             (b'\xf1\x41\x41\x80', FFFD+'AA'+FFFD), # 1 valid cb and 1 invalid
01104             (b'\xf1\x41\xf1\x80', FFFD+'A'+FFFD),
01105             (b'\xf1\x41\x80\xf1', FFFD+'A'+FFFD*2),
01106             (b'\xf1\xf1\x80\x41', FFFD*2+'A'),
01107             (b'\xf1\x41\xf1\xf1', FFFD+'A'+FFFD*2),
01108             # with invalid start byte of a 4-byte sequence (rfc2279)
01109             (b'\xf5', FFFD), # only the start byte
01110             (b'\xf5\xf5', FFFD*2), # 2 start bytes
01111             (b'\xf5\x80', FFFD*2), # only 1 continuation byte
01112             (b'\xf5\x80\x80', FFFD*3), # only 2 continuation byte
01113             (b'\xf5\x80\x80\x80', FFFD*4), # 3 continuation bytes
01114             (b'\xf5\x80\x41', FFFD*2+'A'), #  1 valid cb and 1 invalid
01115             (b'\xf5\x80\x41\xf5', FFFD*2+'A'+FFFD),
01116             (b'\xf5\x41\x80\x80\x41', FFFD+'A'+FFFD*2+'A'),
01117             # with invalid start byte of a 5-byte sequence (rfc2279)
01118             (b'\xf8', FFFD), # only the start byte
01119             (b'\xf8\xf8', FFFD*2), # 2 start bytes
01120             (b'\xf8\x80', FFFD*2), # only one continuation byte
01121             (b'\xf8\x80\x41', FFFD*2 + 'A'), # 1 valid cb and 1 invalid
01122             (b'\xf8\x80\x80\x80\x80', FFFD*5), # invalid 5 bytes seq with 5 bytes
01123             # with invalid start byte of a 6-byte sequence (rfc2279)
01124             (b'\xfc', FFFD), # only the start byte
01125             (b'\xfc\xfc', FFFD*2), # 2 start bytes
01126             (b'\xfc\x80\x80', FFFD*3), # only 2 continuation bytes
01127             (b'\xfc\x80\x80\x80\x80\x80', FFFD*6), # 6 continuation bytes
01128             # invalid start byte
01129             (b'\xfe', FFFD),
01130             (b'\xfe\x80\x80', FFFD*3),
01131             # other sequences
01132             (b'\xf1\x80\x41\x42\x43', '\ufffd\x41\x42\x43'),
01133             (b'\xf1\x80\xff\x42\x43', '\ufffd\ufffd\x42\x43'),
01134             (b'\xf1\x80\xc2\x81\x43', '\ufffd\x81\x43'),
01135             (b'\x61\xF1\x80\x80\xE1\x80\xC2\x62\x80\x63\x80\xBF\x64',
01136              '\x61\uFFFD\uFFFD\uFFFD\x62\uFFFD\x63\uFFFD\uFFFD\x64'),
01137         ]
01138         for n, (seq, res) in enumerate(sequences):
01139             self.assertRaises(UnicodeDecodeError, seq.decode, 'utf-8', 'strict')
01140             self.assertEqual(seq.decode('utf-8', 'replace'), res)
01141             self.assertEqual((seq+b'b').decode('utf-8', 'replace'), res+'b')
01142             self.assertEqual(seq.decode('utf-8', 'ignore'),
01143                              res.replace('\uFFFD', ''))

Here is the call graph for this function:

Reimplemented from test.string_tests.MixinStrUnicodeUserStringTest.

Definition at line 354 of file test_unicode.py.

00354 
00355     def test_istitle(self):
00356         string_tests.MixinStrUnicodeUserStringTest.test_title(self)
00357         self.checkequalnofix(True, '\u1FFc', 'istitle')
00358         self.checkequalnofix(True, 'Greek \u1FFcitlecases ...', 'istitle')

Here is the call graph for this function:

Reimplemented from test.string_tests.MixinStrUnicodeUserStringTest.

Definition at line 349 of file test_unicode.py.

00349 
00350     def test_isupper(self):
00351         string_tests.MixinStrUnicodeUserStringTest.test_isupper(self)
00352         if not sys.platform.startswith('java'):
00353             self.checkequalnofix(False, '\u1FFc', 'isupper')

Here is the call graph for this function:

Definition at line 151 of file test_unicode.py.

00151 
00152     def test_iterators(self):
00153         # Make sure unicode objects have an __iter__ method
00154         it = "\u1111\u2222\u3333".__iter__()
00155         self.assertEqual(next(it), "\u1111")
00156         self.assertEqual(next(it), "\u2222")
00157         self.assertEqual(next(it), "\u3333")
00158         self.assertRaises(StopIteration, next, it)

Here is the call graph for this function:

Reimplemented from test.string_tests.MixinStrUnicodeUserStringTest.

Definition at line 251 of file test_unicode.py.

00251 
00252     def test_join(self):
00253         string_tests.MixinStrUnicodeUserStringTest.test_join(self)
00254 
00255         class MyWrapper:
00256             def __init__(self, sval): self.sval = sval
00257             def __str__(self): return self.sval
00258 
00259         # mixed arguments
00260         self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
00261         self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd'))
00262         self.checkequalnofix('w x y z', ' ', 'join', string_tests.Sequence('wxyz'))
00263         self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
00264         self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
00265         self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd'))
00266         self.checkequalnofix('w x y z', ' ', 'join', string_tests.Sequence('wxyz'))
00267         self.checkraises(TypeError, ' ', 'join', ['1', '2', MyWrapper('foo')])
00268         self.checkraises(TypeError, ' ', 'join', ['1', '2', '3', bytes()])
00269         self.checkraises(TypeError, ' ', 'join', [1, 2, 3])
00270         self.checkraises(TypeError, ' ', 'join', ['1', '2', 3])

Definition at line 58 of file test_unicode.py.

00058 
00059     def test_literals(self):
00060         self.assertEqual('\xff', '\u00ff')
00061         self.assertEqual('\uffff', '\U0000ffff')
00062         self.assertRaises(SyntaxError, eval, '\'\\Ufffffffe\'')
00063         self.assertRaises(SyntaxError, eval, '\'\\Uffffffff\'')
00064         self.assertRaises(SyntaxError, eval, '\'\\U%08x\'' % 0x110000)
00065         # raw strings should not have unicode escapes
00066         self.assertNotEqual(r"\u0020", " ")

Here is the call graph for this function:

def test.string_tests.CommonTest.test_ljust (   self) [inherited]

Definition at line 753 of file string_tests.py.

00753 
00754     def test_ljust(self):
00755         self.checkequal('abc       ', 'abc', 'ljust', 10)
00756         self.checkequal('abc   ', 'abc', 'ljust', 6)
00757         self.checkequal('abc', 'abc', 'ljust', 3)
00758         self.checkequal('abc', 'abc', 'ljust', 2)
00759         self.checkequal('abc*******', 'abc', 'ljust', 10, '*')
00760         self.checkraises(TypeError, 'abc', 'ljust')

Here is the call graph for this function:

def test.string_tests.CommonTest.test_lower (   self) [inherited]

Reimplemented from test.string_tests.BaseTest.

Definition at line 646 of file string_tests.py.

00646 
00647     def test_lower(self):
00648         self.checkequal('hello', 'HeLLo', 'lower')
00649         self.checkequal('hello', 'hello', 'lower')
00650         self.checkraises(TypeError, 'hello', 'lower', 42)

Here is the call graph for this function:

Definition at line 211 of file test_unicode.py.

00211 
00212     def test_maketrans_translate(self):
00213         # these work with plain translate()
00214         self.checkequalnofix('bbbc', 'abababc', 'translate',
00215                              {ord('a'): None})
00216         self.checkequalnofix('iiic', 'abababc', 'translate',
00217                              {ord('a'): None, ord('b'): ord('i')})
00218         self.checkequalnofix('iiix', 'abababc', 'translate',
00219                              {ord('a'): None, ord('b'): ord('i'), ord('c'): 'x'})
00220         self.checkequalnofix('c', 'abababc', 'translate',
00221                              {ord('a'): None, ord('b'): ''})
00222         self.checkequalnofix('xyyx', 'xzx', 'translate',
00223                              {ord('z'): 'yy'})
00224         # this needs maketrans()
00225         self.checkequalnofix('abababc', 'abababc', 'translate',
00226                              {'b': '<i>'})
00227         tbl = self.type2test.maketrans({'a': None, 'b': '<i>'})
00228         self.checkequalnofix('<i><i><i>c', 'abababc', 'translate', tbl)
00229         # test alternative way of calling maketrans()
00230         tbl = self.type2test.maketrans('abc', 'xyz', 'd')
00231         self.checkequalnofix('xyzzy', 'abdcdcbdddd', 'translate', tbl)
00232 
00233         self.assertRaises(TypeError, self.type2test.maketrans)
00234         self.assertRaises(ValueError, self.type2test.maketrans, 'abc', 'defg')
00235         self.assertRaises(TypeError, self.type2test.maketrans, 2, 'def')
00236         self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 2)
00237         self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 'def', 2)
00238         self.assertRaises(ValueError, self.type2test.maketrans, {'xy': 2})
00239         self.assertRaises(TypeError, self.type2test.maketrans, {(1,): 2})
00240 
00241         self.assertRaises(TypeError, 'hello'.translate)
00242         self.assertRaises(TypeError, 'abababc'.translate, 'abc', 'xyz')

Here is the call graph for this function:

Definition at line 1039 of file string_tests.py.

01039 
01040     def test_mul(self):
01041         self.checkequal('', 'abc', '__mul__', -1)
01042         self.checkequal('', 'abc', '__mul__', 0)
01043         self.checkequal('abc', 'abc', '__mul__', 1)
01044         self.checkequal('abcabcabc', 'abc', '__mul__', 3)
01045         self.checkraises(TypeError, 'abc', '__mul__')
01046         self.checkraises(TypeError, 'abc', '__mul__', '')
01047         # XXX: on a 64-bit system, this doesn't raise an overflow error,
01048         # but either raises a MemoryError, or succeeds (if you have 54TiB)
01049         #self.checkraises(OverflowError, 10000*'abc', '__mul__', 2000000000)

Here is the call graph for this function:

Definition at line 1186 of file string_tests.py.

01186 
01187     def test_none_arguments(self):
01188         # issue 11828
01189         s = 'hello'
01190         self.checkequal(2, s, 'find', 'l', None)
01191         self.checkequal(3, s, 'find', 'l', -2, None)
01192         self.checkequal(2, s, 'find', 'l', None, -2)
01193         self.checkequal(0, s, 'find', 'h', None, None)
01194 
01195         self.checkequal(3, s, 'rfind', 'l', None)
01196         self.checkequal(3, s, 'rfind', 'l', -2, None)
01197         self.checkequal(2, s, 'rfind', 'l', None, -2)
01198         self.checkequal(0, s, 'rfind', 'h', None, None)
01199 
01200         self.checkequal(2, s, 'index', 'l', None)
01201         self.checkequal(3, s, 'index', 'l', -2, None)
01202         self.checkequal(2, s, 'index', 'l', None, -2)
01203         self.checkequal(0, s, 'index', 'h', None, None)
01204 
01205         self.checkequal(3, s, 'rindex', 'l', None)
01206         self.checkequal(3, s, 'rindex', 'l', -2, None)
01207         self.checkequal(2, s, 'rindex', 'l', None, -2)
01208         self.checkequal(0, s, 'rindex', 'h', None, None)
01209 
01210         self.checkequal(2, s, 'count', 'l', None)
01211         self.checkequal(1, s, 'count', 'l', -2, None)
01212         self.checkequal(1, s, 'count', 'l', None, -2)
01213         self.checkequal(0, s, 'count', 'x', None, None)
01214 
01215         self.checkequal(True, s, 'endswith', 'o', None)
01216         self.checkequal(True, s, 'endswith', 'lo', -2, None)
01217         self.checkequal(True, s, 'endswith', 'l', None, -2)
01218         self.checkequal(False, s, 'endswith', 'x', None, None)
01219 
01220         self.checkequal(True, s, 'startswith', 'h', None)
01221         self.checkequal(True, s, 'startswith', 'l', -2, None)
01222         self.checkequal(True, s, 'startswith', 'h', None, -2)
01223         self.checkequal(False, s, 'startswith', 'x', None, None)

Here is the call graph for this function:

Definition at line 1156 of file string_tests.py.

01156 
01157     def test_partition(self):
01158 
01159         self.checkequal(('this is the par', 'ti', 'tion method'),
01160             'this is the partition method', 'partition', 'ti')
01161 
01162         # from raymond's original specification
01163         S = 'http://www.python.org'
01164         self.checkequal(('http', '://', 'www.python.org'), S, 'partition', '://')
01165         self.checkequal(('http://www.python.org', '', ''), S, 'partition', '?')
01166         self.checkequal(('', 'http://', 'www.python.org'), S, 'partition', 'http://')
01167         self.checkequal(('http://www.python.', 'org', ''), S, 'partition', 'org')
01168 
01169         self.checkraises(ValueError, S, 'partition', '')
01170         self.checkraises(TypeError, S, 'partition', None)

Here is the call graph for this function:

Definition at line 1410 of file test_unicode.py.

01410 
01411     def test_printable_repr(self):
01412         self.assertEqual(repr('\U00010000'), "'%c'" % (0x10000,)) # printable
01413         self.assertEqual(repr('\U00014000'), "'\\U00014000'")     # nonprintable

Here is the call graph for this function:

Definition at line 1302 of file test_unicode.py.

01302 
01303     def test_printing(self):
01304         class BitBucket:
01305             def write(self, text):
01306                 pass
01307 
01308         out = BitBucket()
01309         print('abc', file=out)
01310         print('abc', 'def', file=out)
01311         print('abc', 'def', file=out)
01312         print('abc', 'def', file=out)
01313         print('abc\n', file=out)
01314         print('abc\n', end=' ', file=out)
01315         print('abc\n', end=' ', file=out)
01316         print('def\n', file=out)
01317         print('def\n', file=out)

Here is the call graph for this function:

Definition at line 1422 of file test_unicode.py.

01422 
01423     def test_raiseMemError(self):
01424         # Ensure that the freelist contains a consistent object, even
01425         # when a string allocation fails with a MemoryError.
01426         # This used to crash the interpreter,
01427         # or leak references when the number was smaller.
01428         charwidth = 4 if sys.maxunicode >= 0x10000 else 2
01429         # Note: sys.maxsize is half of the actual max allocation because of
01430         # the signedness of Py_ssize_t.
01431         alloc = lambda: "a" * (sys.maxsize // charwidth * 2)
01432         self.assertRaises(MemoryError, alloc)
01433         self.assertRaises(MemoryError, alloc)

Here is the call graph for this function:

Reimplemented from test.string_tests.BaseTest.

Definition at line 271 of file test_unicode.py.

00271 
00272     def test_replace(self):
00273         string_tests.CommonTest.test_replace(self)
00274 
00275         # method call forwarded from str implementation because of unicode argument
00276         self.checkequalnofix('one@two!three!', 'one!two!three!', 'replace', '!', '@', 1)
00277         self.assertRaises(TypeError, 'replace'.replace, "r", 42)

Here is the call graph for this function:

Definition at line 109 of file test_unicode.py.

00109 
00110     def test_repr(self):
00111         if not sys.platform.startswith('java'):
00112             # Test basic sanity of repr()
00113             self.assertEqual(repr('abc'), "'abc'")
00114             self.assertEqual(repr('ab\\c'), "'ab\\\\c'")
00115             self.assertEqual(repr('ab\\'), "'ab\\\\'")
00116             self.assertEqual(repr('\\c'), "'\\\\c'")
00117             self.assertEqual(repr('\\'), "'\\\\'")
00118             self.assertEqual(repr('\n'), "'\\n'")
00119             self.assertEqual(repr('\r'), "'\\r'")
00120             self.assertEqual(repr('\t'), "'\\t'")
00121             self.assertEqual(repr('\b'), "'\\x08'")
00122             self.assertEqual(repr("'\""), """'\\'"'""")
00123             self.assertEqual(repr("'\""), """'\\'"'""")
00124             self.assertEqual(repr("'"), '''"'"''')
00125             self.assertEqual(repr('"'), """'"'""")
00126             latin1repr = (
00127                 "'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r"
00128                 "\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a"
00129                 "\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHI"
00130                 "JKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f"
00131                 "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d"
00132                 "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b"
00133                 "\\x9c\\x9d\\x9e\\x9f\\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9"
00134                 "\xaa\xab\xac\\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7"
00135                 "\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5"
00136                 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
00137                 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1"
00138                 "\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
00139                 "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd"
00140                 "\xfe\xff'")
00141             testrepr = repr(''.join(map(chr, range(256))))
00142             self.assertEqual(testrepr, latin1repr)
00143             # Test repr works on wide unicode escapes without overflow.
00144             self.assertEqual(repr("\U00010000" * 39 + "\uffff" * 4096),
00145                              repr("\U00010000" * 39 + "\uffff" * 4096))
00146 
00147             class WrongRepr:
00148                 def __repr__(self):
00149                     return b'byte-repr'
00150             self.assertRaises(TypeError, repr, WrongRepr())

Here is the call graph for this function:

Reimplemented from test.string_tests.BaseTest.

Definition at line 180 of file test_unicode.py.

00180 
00181     def test_rfind(self):
00182         string_tests.CommonTest.test_rfind(self)
00183         # check mixed argument types
00184         self.checkequalnofix(9,   'abcdefghiabc', 'rfind', 'abc')
00185         self.checkequalnofix(12,  'abcdefghiabc', 'rfind', '')
00186         self.checkequalnofix(12, 'abcdefghiabc', 'rfind',  '')

Here is the call graph for this function:

Reimplemented from test.string_tests.BaseTest.

Definition at line 198 of file test_unicode.py.

00198 
00199     def test_rindex(self):
00200         string_tests.CommonTest.test_rindex(self)
00201         self.checkequalnofix(12, 'abcdefghiabc', 'rindex',  '')
00202         self.checkequalnofix(3,  'abcdefghiabc', 'rindex',  'def')
00203         self.checkequalnofix(9,  'abcdefghiabc', 'rindex',  'abc')
00204         self.checkequalnofix(0,  'abcdefghiabc', 'rindex',  'abc', 0, -1)
00205 
00206         self.assertRaises(ValueError, 'abcdefghiabc'.rindex,  'hib')
00207         self.assertRaises(ValueError, 'defghiabc'.rindex,  'def', 1)
00208         self.assertRaises(ValueError, 'defghiabc'.rindex,  'abc', 0, -1)
00209         self.assertRaises(ValueError, 'abcdefghi'.rindex,  'ghi', 0, 8)
00210         self.assertRaises(ValueError, 'abcdefghi'.rindex,  'ghi', 0, -1)

Here is the call graph for this function:

def test.string_tests.CommonTest.test_rjust (   self) [inherited]

Definition at line 761 of file string_tests.py.

00761 
00762     def test_rjust(self):
00763         self.checkequal('       abc', 'abc', 'rjust', 10)
00764         self.checkequal('   abc', 'abc', 'rjust', 6)
00765         self.checkequal('abc', 'abc', 'rjust', 3)
00766         self.checkequal('abc', 'abc', 'rjust', 2)
00767         self.checkequal('*******abc', 'abc', 'rjust', 10, '*')
00768         self.checkraises(TypeError, 'abc', 'rjust')

Here is the call graph for this function:

Definition at line 1171 of file string_tests.py.

01171 
01172     def test_rpartition(self):
01173 
01174         self.checkequal(('this is the rparti', 'ti', 'on method'),
01175             'this is the rpartition method', 'rpartition', 'ti')
01176 
01177         # from raymond's original specification
01178         S = 'http://www.python.org'
01179         self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://')
01180         self.checkequal(('', '', 'http://www.python.org'), S, 'rpartition', '?')
01181         self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://')
01182         self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org')
01183 
01184         self.checkraises(ValueError, S, 'rpartition', '')
01185         self.checkraises(TypeError, S, 'rpartition', None)

Here is the call graph for this function:

def test.string_tests.BaseTest.test_rsplit (   self) [inherited]

Definition at line 373 of file string_tests.py.

00373 
00374     def test_rsplit(self):
00375         # by a char
00376         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|')
00377         self.checkequal(['a|b|c', 'd'], 'a|b|c|d', 'rsplit', '|', 1)
00378         self.checkequal(['a|b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 2)
00379         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 3)
00380         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 4)
00381         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|',
00382                         sys.maxsize-100)
00383         self.checkequal(['a|b|c|d'], 'a|b|c|d', 'rsplit', '|', 0)
00384         self.checkequal(['a||b||c', '', 'd'], 'a||b||c||d', 'rsplit', '|', 2)
00385         self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|')
00386         self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|')
00387         self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|')
00388 
00389         self.checkequal(['a\x00\x00b', 'c', 'd'], 'a\x00\x00b\x00c\x00d', 'rsplit', '\x00', 2)
00390 
00391         self.checkequal(['a']*20, ('a|'*20)[:-1], 'rsplit', '|')
00392         self.checkequal(['a|a|a|a|a']+['a']*15,
00393                         ('a|'*20)[:-1], 'rsplit', '|', 15)
00394 
00395         # by string
00396         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//')
00397         self.checkequal(['a//b//c', 'd'], 'a//b//c//d', 'rsplit', '//', 1)
00398         self.checkequal(['a//b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 2)
00399         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 3)
00400         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 4)
00401         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//',
00402                         sys.maxsize-5)
00403         self.checkequal(['a//b//c//d'], 'a//b//c//d', 'rsplit', '//', 0)
00404         self.checkequal(['a////b////c', '', 'd'], 'a////b////c////d', 'rsplit', '//', 2)
00405         self.checkequal(['', ' begincase'], 'test begincase', 'rsplit', 'test')
00406         self.checkequal(['endcase ', ''], 'endcase test', 'rsplit', 'test')
00407         self.checkequal(['', ' bothcase ', ''], 'test bothcase test',
00408                         'rsplit', 'test')
00409         self.checkequal(['ab', 'c'], 'abbbc', 'rsplit', 'bb')
00410         self.checkequal(['', ''], 'aaa', 'rsplit', 'aaa')
00411         self.checkequal(['aaa'], 'aaa', 'rsplit', 'aaa', 0)
00412         self.checkequal(['ab', 'ab'], 'abbaab', 'rsplit', 'ba')
00413         self.checkequal(['aaaa'], 'aaaa', 'rsplit', 'aab')
00414         self.checkequal([''], '', 'rsplit', 'aaa')
00415         self.checkequal(['aa'], 'aa', 'rsplit', 'aaa')
00416         self.checkequal(['bbob', 'A'], 'bbobbbobbA', 'rsplit', 'bbobb')
00417         self.checkequal(['', 'B', 'A'], 'bbobbBbbobbA', 'rsplit', 'bbobb')
00418 
00419         self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH')
00420         self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH', 19)
00421         self.checkequal(['aBLAHa'] + ['a']*18, ('aBLAH'*20)[:-4],
00422                         'rsplit', 'BLAH', 18)
00423 
00424         # argument type
00425         self.checkraises(TypeError, 'hello', 'rsplit', 42, 42, 42)
00426 
00427         # null case
00428         self.checkraises(ValueError, 'hello', 'rsplit', '')
00429         self.checkraises(ValueError, 'hello', 'rsplit', '', 0)

Here is the call graph for this function:

Definition at line 1014 of file string_tests.py.

01014 
01015     def test_slice(self):
01016         self.checkequal('abc', 'abc', '__getitem__', slice(0, 1000))
01017         self.checkequal('abc', 'abc', '__getitem__', slice(0, 3))
01018         self.checkequal('ab', 'abc', '__getitem__', slice(0, 2))
01019         self.checkequal('bc', 'abc', '__getitem__', slice(1, 3))
01020         self.checkequal('b', 'abc', '__getitem__', slice(1, 2))
01021         self.checkequal('', 'abc', '__getitem__', slice(2, 2))
01022         self.checkequal('', 'abc', '__getitem__', slice(1000, 1000))
01023         self.checkequal('', 'abc', '__getitem__', slice(2000, 1000))
01024         self.checkequal('', 'abc', '__getitem__', slice(2, 1))
01025 
01026         self.checkraises(TypeError, 'abc', '__getitem__', 'def')

Here is the call graph for this function:

Reimplemented from test.string_tests.BaseTest.

Definition at line 243 of file test_unicode.py.

00243 
00244     def test_split(self):
00245         string_tests.CommonTest.test_split(self)
00246 
00247         # Mixed arguments
00248         self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//')
00249         self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//')
00250         self.checkequalnofix(['endcase ', ''], 'endcase test', 'split', 'test')

Here is the call graph for this function:

Definition at line 887 of file string_tests.py.

00887 
00888     def test_splitlines(self):
00889         self.checkequal(['abc', 'def', '', 'ghi'], "abc\ndef\n\rghi", 'splitlines')
00890         self.checkequal(['abc', 'def', '', 'ghi'], "abc\ndef\n\r\nghi", 'splitlines')
00891         self.checkequal(['abc', 'def', 'ghi'], "abc\ndef\r\nghi", 'splitlines')
00892         self.checkequal(['abc', 'def', 'ghi'], "abc\ndef\r\nghi\n", 'splitlines')
00893         self.checkequal(['abc', 'def', 'ghi', ''], "abc\ndef\r\nghi\n\r", 'splitlines')
00894         self.checkequal(['', 'abc', 'def', 'ghi', ''], "\nabc\ndef\r\nghi\n\r", 'splitlines')
00895         self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'], "\nabc\ndef\r\nghi\n\r", 'splitlines', 1)
00896 
00897         self.checkraises(TypeError, 'abc', 'splitlines', 42, 42)

Here is the call graph for this function:

Definition at line 898 of file string_tests.py.

00898 
00899     def test_startswith(self):
00900         self.checkequal(True, 'hello', 'startswith', 'he')
00901         self.checkequal(True, 'hello', 'startswith', 'hello')
00902         self.checkequal(False, 'hello', 'startswith', 'hello world')
00903         self.checkequal(True, 'hello', 'startswith', '')
00904         self.checkequal(False, 'hello', 'startswith', 'ello')
00905         self.checkequal(True, 'hello', 'startswith', 'ello', 1)
00906         self.checkequal(True, 'hello', 'startswith', 'o', 4)
00907         self.checkequal(False, 'hello', 'startswith', 'o', 5)
00908         self.checkequal(True, 'hello', 'startswith', '', 5)
00909         self.checkequal(False, 'hello', 'startswith', 'lo', 6)
00910         self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3)
00911         self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3, 7)
00912         self.checkequal(False, 'helloworld', 'startswith', 'lowo', 3, 6)
00913 
00914         # test negative indices
00915         self.checkequal(True, 'hello', 'startswith', 'he', 0, -1)
00916         self.checkequal(True, 'hello', 'startswith', 'he', -53, -1)
00917         self.checkequal(False, 'hello', 'startswith', 'hello', 0, -1)
00918         self.checkequal(False, 'hello', 'startswith', 'hello world', -1, -10)
00919         self.checkequal(False, 'hello', 'startswith', 'ello', -5)
00920         self.checkequal(True, 'hello', 'startswith', 'ello', -4)
00921         self.checkequal(False, 'hello', 'startswith', 'o', -2)
00922         self.checkequal(True, 'hello', 'startswith', 'o', -1)
00923         self.checkequal(True, 'hello', 'startswith', '', -3, -3)
00924         self.checkequal(False, 'hello', 'startswith', 'lo', -9)
00925 
00926         self.checkraises(TypeError, 'hello', 'startswith')
00927         self.checkraises(TypeError, 'hello', 'startswith', 42)
00928 
00929         # test tuple arguments
00930         self.checkequal(True, 'hello', 'startswith', ('he', 'ha'))
00931         self.checkequal(False, 'hello', 'startswith', ('lo', 'llo'))
00932         self.checkequal(True, 'hello', 'startswith', ('hellox', 'hello'))
00933         self.checkequal(False, 'hello', 'startswith', ())
00934         self.checkequal(True, 'helloworld', 'startswith', ('hellowo',
00935                                                            'rld', 'lowo'), 3)
00936         self.checkequal(False, 'helloworld', 'startswith', ('hellowo', 'ello',
00937                                                             'rld'), 3)
00938         self.checkequal(True, 'hello', 'startswith', ('lo', 'he'), 0, -1)
00939         self.checkequal(False, 'hello', 'startswith', ('he', 'hel'), 0, 1)
00940         self.checkequal(True, 'hello', 'startswith', ('he', 'hel'), 0, 2)
00941 
00942         self.checkraises(TypeError, 'hello', 'startswith', (42,))

Here is the call graph for this function:

Definition at line 829 of file test_unicode.py.

00829 
00830     def test_startswith_endswith_errors(self):
00831         for meth in ('foo'.startswith, 'foo'.endswith):
00832             with self.assertRaises(TypeError) as cm:
00833                 meth(['f'])
00834             exc = str(cm.exception)
00835             self.assertIn('str', exc)
00836             self.assertIn('tuple', exc)

Here is the call graph for this function:

def test.string_tests.CommonTest.test_strip (   self) [inherited]

Definition at line 731 of file string_tests.py.

00731 
00732     def test_strip(self):
00733         self.checkequal('hello', '   hello   ', 'strip')
00734         self.checkequal('hello   ', '   hello   ', 'lstrip')
00735         self.checkequal('   hello', '   hello   ', 'rstrip')
00736         self.checkequal('hello', 'hello', 'strip')
00737 
00738         # strip/lstrip/rstrip with None arg
00739         self.checkequal('hello', '   hello   ', 'strip', None)
00740         self.checkequal('hello   ', '   hello   ', 'lstrip', None)
00741         self.checkequal('   hello', '   hello   ', 'rstrip', None)
00742         self.checkequal('hello', 'hello', 'strip', None)
00743 
00744         # strip/lstrip/rstrip with str arg
00745         self.checkequal('hello', 'xyzzyhelloxyzzy', 'strip', 'xyz')
00746         self.checkequal('helloxyzzy', 'xyzzyhelloxyzzy', 'lstrip', 'xyz')
00747         self.checkequal('xyzzyhello', 'xyzzyhelloxyzzy', 'rstrip', 'xyz')
00748         self.checkequal('hello', 'hello', 'strip', 'xyz')
00749 
00750         self.checkraises(TypeError, 'hello', 'strip', 42, 42)
00751         self.checkraises(TypeError, 'hello', 'lstrip', 42, 42)
00752         self.checkraises(TypeError, 'hello', 'rstrip', 42, 42)

Here is the call graph for this function:

Definition at line 1003 of file string_tests.py.

01003 
01004     def test_subscript(self):
01005         self.checkequal('a', 'abc', '__getitem__', 0)
01006         self.checkequal('c', 'abc', '__getitem__', -1)
01007         self.checkequal('a', 'abc', '__getitem__', 0)
01008         self.checkequal('abc', 'abc', '__getitem__', slice(0, 3))
01009         self.checkequal('abc', 'abc', '__getitem__', slice(0, 1000))
01010         self.checkequal('a', 'abc', '__getitem__', slice(0, 1))
01011         self.checkequal('', 'abc', '__getitem__', slice(0, 0))
01012 
01013         self.checkraises(TypeError, 'abc', '__getitem__', 'def')

Here is the call graph for this function:

def test.string_tests.CommonTest.test_swapcase (   self) [inherited]

Definition at line 777 of file string_tests.py.

00777 
00778     def test_swapcase(self):
00779         self.checkequal('hEllO CoMPuTErS', 'HeLLo cOmpUteRs', 'swapcase')
00780 
00781         self.checkraises(TypeError, 'hello', 'swapcase', 42)

Here is the call graph for this function:

Definition at line 878 of file string_tests.py.

00878 
00879     def test_title(self):
00880         self.checkequal(' Hello ', ' hello ', 'title')
00881         self.checkequal('Hello ', 'hello ', 'title')
00882         self.checkequal('Hello ', 'Hello ', 'title')
00883         self.checkequal('Format This As Title String', "fOrMaT thIs aS titLe String", 'title')
00884         self.checkequal('Format,This-As*Title;String', "fOrMaT,thIs-aS*titLe;String", 'title', )
00885         self.checkequal('Getint', "getInt", 'title')
00886         self.checkraises(TypeError, 'hello', 'title', 42)

Here is the call graph for this function:

Definition at line 1318 of file test_unicode.py.

01318 
01319     def test_ucs4(self):
01320         x = '\U00100000'
01321         y = x.encode("raw-unicode-escape").decode("raw-unicode-escape")
01322         self.assertEqual(x, y)
01323 
01324         y = br'\U00100000'
01325         x = y.decode("raw-unicode-escape").encode("raw-unicode-escape")
01326         self.assertEqual(x, y)
01327         y = br'\U00010000'
01328         x = y.decode("raw-unicode-escape").encode("raw-unicode-escape")
01329         self.assertEqual(x, y)
01330 
01331         try:
01332             br'\U11111111'.decode("raw-unicode-escape")
01333         except UnicodeDecodeError as e:
01334             self.assertEqual(e.start, 0)
01335             self.assertEqual(e.end, 10)
01336         else:
01337             self.fail("Should have raised UnicodeDecodeError")

Here is the call graph for this function:

Definition at line 1398 of file test_unicode.py.

01398 
01399     def test_unicode_repr(self):
01400         class s1:
01401             def __repr__(self):
01402                 return '\\n'
01403 
01404         class s2:
01405             def __repr__(self):
01406                 return '\\n'
01407 
01408         self.assertEqual(repr(s1()), '\\n')
01409         self.assertEqual(repr(s2()), '\\n')

Here is the call graph for this function:

def test.string_tests.CommonTest.test_upper (   self) [inherited]

Reimplemented from test.string_tests.BaseTest.

Definition at line 651 of file string_tests.py.

00651 
00652     def test_upper(self):
00653         self.checkequal('HELLO', 'HeLLo', 'upper')
00654         self.checkequal('HELLO', 'HELLO', 'upper')
00655         self.checkraises(TypeError, 'hello', 'upper', 42)

Here is the call graph for this function:

Definition at line 1008 of file test_unicode.py.

01008 
01009     def test_utf8_decode_invalid_sequences(self):
01010         # continuation bytes in a sequence of 2, 3, or 4 bytes
01011         continuation_bytes = [bytes([x]) for x in range(0x80, 0xC0)]
01012         # start bytes of a 2-byte sequence equivalent to codepoints < 0x7F
01013         invalid_2B_seq_start_bytes = [bytes([x]) for x in range(0xC0, 0xC2)]
01014         # start bytes of a 4-byte sequence equivalent to codepoints > 0x10FFFF
01015         invalid_4B_seq_start_bytes = [bytes([x]) for x in range(0xF5, 0xF8)]
01016         invalid_start_bytes = (
01017             continuation_bytes + invalid_2B_seq_start_bytes +
01018             invalid_4B_seq_start_bytes + [bytes([x]) for x in range(0xF7, 0x100)]
01019         )
01020 
01021         for byte in invalid_start_bytes:
01022             self.assertRaises(UnicodeDecodeError, byte.decode, 'utf-8')
01023 
01024         for sb in invalid_2B_seq_start_bytes:
01025             for cb in continuation_bytes:
01026                 self.assertRaises(UnicodeDecodeError, (sb+cb).decode, 'utf-8')
01027 
01028         for sb in invalid_4B_seq_start_bytes:
01029             for cb1 in continuation_bytes[:3]:
01030                 for cb3 in continuation_bytes[:3]:
01031                     self.assertRaises(UnicodeDecodeError,
01032                                       (sb+cb1+b'\x80'+cb3).decode, 'utf-8')
01033 
01034         for cb in [bytes([x]) for x in range(0x80, 0xA0)]:
01035             self.assertRaises(UnicodeDecodeError,
01036                               (b'\xE0'+cb+b'\x80').decode, 'utf-8')
01037             self.assertRaises(UnicodeDecodeError,
01038                               (b'\xE0'+cb+b'\xBF').decode, 'utf-8')
01039         # surrogates
01040         for cb in [bytes([x]) for x in range(0xA0, 0xC0)]:
01041             self.assertRaises(UnicodeDecodeError,
01042                               (b'\xED'+cb+b'\x80').decode, 'utf-8')
01043             self.assertRaises(UnicodeDecodeError,
01044                               (b'\xED'+cb+b'\xBF').decode, 'utf-8')
01045         for cb in [bytes([x]) for x in range(0x80, 0x90)]:
01046             self.assertRaises(UnicodeDecodeError,
01047                               (b'\xF0'+cb+b'\x80\x80').decode, 'utf-8')
01048             self.assertRaises(UnicodeDecodeError,
01049                               (b'\xF0'+cb+b'\xBF\xBF').decode, 'utf-8')
01050         for cb in [bytes([x]) for x in range(0x90, 0xC0)]:
01051             self.assertRaises(UnicodeDecodeError,
01052                               (b'\xF4'+cb+b'\x80\x80').decode, 'utf-8')
01053             self.assertRaises(UnicodeDecodeError,
01054                               (b'\xF4'+cb+b'\xBF\xBF').decode, 'utf-8')

Here is the call graph for this function:

Definition at line 991 of file test_unicode.py.

00991 
00992     def test_utf8_decode_valid_sequences(self):
00993         sequences = [
00994             # single byte
00995             (b'\x00', '\x00'), (b'a', 'a'), (b'\x7f', '\x7f'),
00996             # 2 bytes
00997             (b'\xc2\x80', '\x80'), (b'\xdf\xbf', '\u07ff'),
00998             # 3 bytes
00999             (b'\xe0\xa0\x80', '\u0800'), (b'\xed\x9f\xbf', '\ud7ff'),
01000             (b'\xee\x80\x80', '\uE000'), (b'\xef\xbf\xbf', '\uffff'),
01001             # 4 bytes
01002             (b'\xF0\x90\x80\x80', '\U00010000'),
01003             (b'\xf4\x8f\xbf\xbf', '\U0010FFFF')
01004         ]
01005         for seq, res in sequences:
01006             self.assertEqual(seq.decode('utf-8'), res)
01007 

Here is the call graph for this function:

def test.string_tests.CommonTest.test_zfill (   self) [inherited]

Definition at line 782 of file string_tests.py.

00782 
00783     def test_zfill(self):
00784         self.checkequal('123', '123', 'zfill', 2)
00785         self.checkequal('123', '123', 'zfill', 3)
00786         self.checkequal('0123', '123', 'zfill', 4)
00787         self.checkequal('+123', '+123', 'zfill', 3)
00788         self.checkequal('+123', '+123', 'zfill', 4)
00789         self.checkequal('+0123', '+123', 'zfill', 5)
00790         self.checkequal('-123', '-123', 'zfill', 3)
00791         self.checkequal('-123', '-123', 'zfill', 4)
00792         self.checkequal('-0123', '-123', 'zfill', 5)
00793         self.checkequal('000', '', 'zfill', 3)
00794         self.checkequal('34', '34', 'zfill', 1)
00795         self.checkequal('0034', '34', 'zfill', 4)
00796 
00797         self.checkraises(TypeError, '123', 'zfill')

Here is the call graph for this function:


Member Data Documentation

Definition at line 482 of file test_unicode.py.

Definition at line 719 of file test_unicode.py.

Definition at line 255 of file test_unicode.py.

Reimplemented from test.string_tests.BaseTest.

Definition at line 38 of file test_unicode.py.

Definition at line 488 of file test_unicode.py.


The documentation for this class was generated from the following file: