Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(35)

Delta Between Two Patch Sets: Lib/test/test_unicode.py

Issue 25958: Implicit ABCs have no means of "anti-registration"
Left Patch Set: Created 4 years, 1 month ago
Right Patch Set: Created 3 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_iter.py ('k') | Objects/enumobject.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """ Test script for the Unicode implementation. 1 """ Test script for the Unicode implementation.
2 2
3 Written by Marc-Andre Lemburg (mal@lemburg.com). 3 Written by Marc-Andre Lemburg (mal@lemburg.com).
4 4
5 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. 5 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
6 6
7 """#" 7 """#"
8 import _string 8 import _string
9 import codecs 9 import codecs
10 import itertools 10 import itertools
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 self.assertEqual("[a]".translate(str.maketrans('a', 'X')), 334 self.assertEqual("[a]".translate(str.maketrans('a', 'X')),
335 "[X]") 335 "[X]")
336 self.assertEqual("[a]".translate(str.maketrans({'a': 'X'})), 336 self.assertEqual("[a]".translate(str.maketrans({'a': 'X'})),
337 "[X]") 337 "[X]")
338 self.assertEqual("[a]".translate(str.maketrans({'a': None})), 338 self.assertEqual("[a]".translate(str.maketrans({'a': None})),
339 "[]") 339 "[]")
340 self.assertEqual("[a]".translate(str.maketrans({'a': 'XXX'})), 340 self.assertEqual("[a]".translate(str.maketrans({'a': 'XXX'})),
341 "[XXX]") 341 "[XXX]")
342 self.assertEqual("[a]".translate(str.maketrans({'a': '\xe9'})), 342 self.assertEqual("[a]".translate(str.maketrans({'a': '\xe9'})),
343 "[\xe9]") 343 "[\xe9]")
344 self.assertEqual('axb'.translate(str.maketrans({'a': None, 'b': '123'})) ,
345 "x123")
346 self.assertEqual('axb'.translate(str.maketrans({'a': None, 'b': '\xe9'}) ),
347 "x\xe9")
348
349 # test non-ASCII (don't take the fast-path)
344 self.assertEqual("[a]".translate(str.maketrans({'a': '<\xe9>'})), 350 self.assertEqual("[a]".translate(str.maketrans({'a': '<\xe9>'})),
345 "[<\xe9>]") 351 "[<\xe9>]")
346 self.assertEqual("[\xe9]".translate(str.maketrans({'\xe9': 'a'})), 352 self.assertEqual("[\xe9]".translate(str.maketrans({'\xe9': 'a'})),
347 "[a]") 353 "[a]")
348 self.assertEqual("[\xe9]".translate(str.maketrans({'\xe9': None})), 354 self.assertEqual("[\xe9]".translate(str.maketrans({'\xe9': None})),
349 "[]") 355 "[]")
356 self.assertEqual("[\xe9]".translate(str.maketrans({'\xe9': '123'})),
357 "[123]")
358 self.assertEqual("[a\xe9]".translate(str.maketrans({'a': '<\u20ac>'})),
359 "[<\u20ac>\xe9]")
350 360
351 # invalid Unicode characters 361 # invalid Unicode characters
352 invalid_char = 0x10ffff+1 362 invalid_char = 0x10ffff+1
353 for before in "a\xe9\u20ac\U0010ffff": 363 for before in "a\xe9\u20ac\U0010ffff":
354 mapping = str.maketrans({before: invalid_char}) 364 mapping = str.maketrans({before: invalid_char})
355 text = "[%s]" % before 365 text = "[%s]" % before
356 self.assertRaises(ValueError, text.translate, mapping) 366 self.assertRaises(ValueError, text.translate, mapping)
357 367
358 # errors 368 # errors
359 self.assertRaises(TypeError, self.type2test.maketrans) 369 self.assertRaises(TypeError, self.type2test.maketrans)
360 self.assertRaises(ValueError, self.type2test.maketrans, 'abc', 'defg') 370 self.assertRaises(ValueError, self.type2test.maketrans, 'abc', 'defg')
361 self.assertRaises(TypeError, self.type2test.maketrans, 2, 'def') 371 self.assertRaises(TypeError, self.type2test.maketrans, 2, 'def')
362 self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 2) 372 self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 2)
363 self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 'def', 2) 373 self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 'def', 2)
364 self.assertRaises(ValueError, self.type2test.maketrans, {'xy': 2}) 374 self.assertRaises(ValueError, self.type2test.maketrans, {'xy': 2})
365 self.assertRaises(TypeError, self.type2test.maketrans, {(1,): 2}) 375 self.assertRaises(TypeError, self.type2test.maketrans, {(1,): 2})
366 376
367 self.assertRaises(TypeError, 'hello'.translate) 377 self.assertRaises(TypeError, 'hello'.translate)
368 self.assertRaises(TypeError, 'abababc'.translate, 'abc', 'xyz') 378 self.assertRaises(TypeError, 'abababc'.translate, 'abc', 'xyz')
369 379
370 def test_split(self): 380 def test_split(self):
371 string_tests.CommonTest.test_split(self) 381 string_tests.CommonTest.test_split(self)
372 382
373 # Mixed arguments
374 self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//')
375 self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//')
376 self.checkequalnofix(['endcase ', ''], 'endcase test', 'split', 'test')
377 # test mixed kinds 383 # test mixed kinds
378 for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'): 384 for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'):
379 left *= 9 385 left *= 9
380 right *= 9 386 right *= 9
381 for delim in ('c', '\u0102', '\U00010302'): 387 for delim in ('c', '\u0102', '\U00010302'):
382 self.checkequal([left + right], 388 self.checkequal([left + right],
383 left + right, 'split', delim) 389 left + right, 'split', delim)
384 self.checkequal([left, right], 390 self.checkequal([left, right],
385 left + delim + right, 'split', delim) 391 left + delim + right, 'split', delim)
386 self.checkequal([left + right], 392 self.checkequal([left + right],
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 s2 = '\udb00\udfff' 554 s2 = '\udb00\udfff'
549 test_lecmp(s, s2) 555 test_lecmp(s, s2)
550 556
551 test_fixup('\ue000') 557 test_fixup('\ue000')
552 test_fixup('\uff61') 558 test_fixup('\uff61')
553 559
554 # Surrogates on both sides, no fixup required 560 # Surrogates on both sides, no fixup required
555 self.assertTrue('\ud800\udc02' < '\ud84d\udc56') 561 self.assertTrue('\ud800\udc02' < '\ud84d\udc56')
556 562
557 def test_islower(self): 563 def test_islower(self):
558 string_tests.MixinStrUnicodeUserStringTest.test_islower(self) 564 super().test_islower()
559 self.checkequalnofix(False, '\u1FFc', 'islower') 565 self.checkequalnofix(False, '\u1FFc', 'islower')
560 self.assertFalse('\u2167'.islower()) 566 self.assertFalse('\u2167'.islower())
561 self.assertTrue('\u2177'.islower()) 567 self.assertTrue('\u2177'.islower())
562 # non-BMP, uppercase 568 # non-BMP, uppercase
563 self.assertFalse('\U00010401'.islower()) 569 self.assertFalse('\U00010401'.islower())
564 self.assertFalse('\U00010427'.islower()) 570 self.assertFalse('\U00010427'.islower())
565 # non-BMP, lowercase 571 # non-BMP, lowercase
566 self.assertTrue('\U00010429'.islower()) 572 self.assertTrue('\U00010429'.islower())
567 self.assertTrue('\U0001044E'.islower()) 573 self.assertTrue('\U0001044E'.islower())
568 # non-BMP, non-cased 574 # non-BMP, non-cased
569 self.assertFalse('\U0001F40D'.islower()) 575 self.assertFalse('\U0001F40D'.islower())
570 self.assertFalse('\U0001F46F'.islower()) 576 self.assertFalse('\U0001F46F'.islower())
571 577
572 def test_isupper(self): 578 def test_isupper(self):
573 string_tests.MixinStrUnicodeUserStringTest.test_isupper(self) 579 super().test_isupper()
574 if not sys.platform.startswith('java'): 580 if not sys.platform.startswith('java'):
575 self.checkequalnofix(False, '\u1FFc', 'isupper') 581 self.checkequalnofix(False, '\u1FFc', 'isupper')
576 self.assertTrue('\u2167'.isupper()) 582 self.assertTrue('\u2167'.isupper())
577 self.assertFalse('\u2177'.isupper()) 583 self.assertFalse('\u2177'.isupper())
578 # non-BMP, uppercase 584 # non-BMP, uppercase
579 self.assertTrue('\U00010401'.isupper()) 585 self.assertTrue('\U00010401'.isupper())
580 self.assertTrue('\U00010427'.isupper()) 586 self.assertTrue('\U00010427'.isupper())
581 # non-BMP, lowercase 587 # non-BMP, lowercase
582 self.assertFalse('\U00010429'.isupper()) 588 self.assertFalse('\U00010429'.isupper())
583 self.assertFalse('\U0001044E'.isupper()) 589 self.assertFalse('\U0001044E'.isupper())
584 # non-BMP, non-cased 590 # non-BMP, non-cased
585 self.assertFalse('\U0001F40D'.isupper()) 591 self.assertFalse('\U0001F40D'.isupper())
586 self.assertFalse('\U0001F46F'.isupper()) 592 self.assertFalse('\U0001F46F'.isupper())
587 593
588 def test_istitle(self): 594 def test_istitle(self):
589 string_tests.MixinStrUnicodeUserStringTest.test_istitle(self) 595 super().test_istitle()
590 self.checkequalnofix(True, '\u1FFc', 'istitle') 596 self.checkequalnofix(True, '\u1FFc', 'istitle')
591 self.checkequalnofix(True, 'Greek \u1FFcitlecases ...', 'istitle') 597 self.checkequalnofix(True, 'Greek \u1FFcitlecases ...', 'istitle')
592 598
593 # non-BMP, uppercase + lowercase 599 # non-BMP, uppercase + lowercase
594 self.assertTrue('\U00010401\U00010429'.istitle()) 600 self.assertTrue('\U00010401\U00010429'.istitle())
595 self.assertTrue('\U00010427\U0001044E'.istitle()) 601 self.assertTrue('\U00010427\U0001044E'.istitle())
596 # apparently there are no titlecased (Lt) non-BMP chars in Unicode 6 602 # apparently there are no titlecased (Lt) non-BMP chars in Unicode 6
597 for ch in ['\U00010429', '\U0001044E', '\U0001F40D', '\U0001F46F']: 603 for ch in ['\U00010429', '\U0001044E', '\U0001F40D', '\U0001F46F']:
598 self.assertFalse(ch.istitle(), '{!a} is not title'.format(ch)) 604 self.assertFalse(ch.istitle(), '{!a} is not title'.format(ch))
599 605
600 def test_isspace(self): 606 def test_isspace(self):
601 string_tests.MixinStrUnicodeUserStringTest.test_isspace(self) 607 super().test_isspace()
602 self.checkequalnofix(True, '\u2000', 'isspace') 608 self.checkequalnofix(True, '\u2000', 'isspace')
603 self.checkequalnofix(True, '\u200a', 'isspace') 609 self.checkequalnofix(True, '\u200a', 'isspace')
604 self.checkequalnofix(False, '\u2014', 'isspace') 610 self.checkequalnofix(False, '\u2014', 'isspace')
605 # apparently there are no non-BMP spaces chars in Unicode 6 611 # apparently there are no non-BMP spaces chars in Unicode 6
606 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', 612 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
607 '\U0001F40D', '\U0001F46F']: 613 '\U0001F40D', '\U0001F46F']:
608 self.assertFalse(ch.isspace(), '{!a} is not space.'.format(ch)) 614 self.assertFalse(ch.isspace(), '{!a} is not space.'.format(ch))
609 615
610 def test_isalnum(self): 616 def test_isalnum(self):
611 string_tests.MixinStrUnicodeUserStringTest.test_isalnum(self) 617 super().test_isalnum()
612 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', 618 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
613 '\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']: 619 '\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']:
614 self.assertTrue(ch.isalnum(), '{!a} is alnum.'.format(ch)) 620 self.assertTrue(ch.isalnum(), '{!a} is alnum.'.format(ch))
615 621
616 def test_isalpha(self): 622 def test_isalpha(self):
617 string_tests.MixinStrUnicodeUserStringTest.test_isalpha(self) 623 super().test_isalpha()
618 self.checkequalnofix(True, '\u1FFc', 'isalpha') 624 self.checkequalnofix(True, '\u1FFc', 'isalpha')
619 # non-BMP, cased 625 # non-BMP, cased
620 self.assertTrue('\U00010401'.isalpha()) 626 self.assertTrue('\U00010401'.isalpha())
621 self.assertTrue('\U00010427'.isalpha()) 627 self.assertTrue('\U00010427'.isalpha())
622 self.assertTrue('\U00010429'.isalpha()) 628 self.assertTrue('\U00010429'.isalpha())
623 self.assertTrue('\U0001044E'.isalpha()) 629 self.assertTrue('\U0001044E'.isalpha())
624 # non-BMP, non-cased 630 # non-BMP, non-cased
625 self.assertFalse('\U0001F40D'.isalpha()) 631 self.assertFalse('\U0001F40D'.isalpha())
626 self.assertFalse('\U0001F46F'.isalpha()) 632 self.assertFalse('\U0001F46F'.isalpha())
627 633
628 def test_isdecimal(self): 634 def test_isdecimal(self):
629 self.checkequalnofix(False, '', 'isdecimal') 635 self.checkequalnofix(False, '', 'isdecimal')
630 self.checkequalnofix(False, 'a', 'isdecimal') 636 self.checkequalnofix(False, 'a', 'isdecimal')
631 self.checkequalnofix(True, '0', 'isdecimal') 637 self.checkequalnofix(True, '0', 'isdecimal')
632 self.checkequalnofix(False, '\u2460', 'isdecimal') # CIRCLED DIGIT ONE 638 self.checkequalnofix(False, '\u2460', 'isdecimal') # CIRCLED DIGIT ONE
633 self.checkequalnofix(False, '\xbc', 'isdecimal') # VULGAR FRACTION ONE Q UARTER 639 self.checkequalnofix(False, '\xbc', 'isdecimal') # VULGAR FRACTION ONE Q UARTER
634 self.checkequalnofix(True, '\u0660', 'isdecimal') # ARABIC-INDIC DIGIT Z ERO 640 self.checkequalnofix(True, '\u0660', 'isdecimal') # ARABIC-INDIC DIGIT Z ERO
635 self.checkequalnofix(True, '0123456789', 'isdecimal') 641 self.checkequalnofix(True, '0123456789', 'isdecimal')
636 self.checkequalnofix(False, '0123456789a', 'isdecimal') 642 self.checkequalnofix(False, '0123456789a', 'isdecimal')
637 643
638 self.checkraises(TypeError, 'abc', 'isdecimal', 42) 644 self.checkraises(TypeError, 'abc', 'isdecimal', 42)
639 645
640 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', 646 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
641 '\U0001F40D', '\U0001F46F', '\U00011065', '\U0001F107']: 647 '\U0001F40D', '\U0001F46F', '\U00011065', '\U0001F107']:
642 self.assertFalse(ch.isdecimal(), '{!a} is not decimal.'.format(ch)) 648 self.assertFalse(ch.isdecimal(), '{!a} is not decimal.'.format(ch))
643 for ch in ['\U0001D7F6', '\U00011066', '\U000104A0']: 649 for ch in ['\U0001D7F6', '\U00011066', '\U000104A0']:
644 self.assertTrue(ch.isdecimal(), '{!a} is decimal.'.format(ch)) 650 self.assertTrue(ch.isdecimal(), '{!a} is decimal.'.format(ch))
645 651
646 def test_isdigit(self): 652 def test_isdigit(self):
647 string_tests.MixinStrUnicodeUserStringTest.test_isdigit(self) 653 super().test_isdigit()
648 self.checkequalnofix(True, '\u2460', 'isdigit') 654 self.checkequalnofix(True, '\u2460', 'isdigit')
649 self.checkequalnofix(False, '\xbc', 'isdigit') 655 self.checkequalnofix(False, '\xbc', 'isdigit')
650 self.checkequalnofix(True, '\u0660', 'isdigit') 656 self.checkequalnofix(True, '\u0660', 'isdigit')
651 657
652 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', 658 for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
653 '\U0001F40D', '\U0001F46F', '\U00011065']: 659 '\U0001F40D', '\U0001F46F', '\U00011065']:
654 self.assertFalse(ch.isdigit(), '{!a} is not a digit.'.format(ch)) 660 self.assertFalse(ch.isdigit(), '{!a} is not a digit.'.format(ch))
655 for ch in ['\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']: 661 for ch in ['\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']:
656 self.assertTrue(ch.isdigit(), '{!a} is a digit.'.format(ch)) 662 self.assertTrue(ch.isdigit(), '{!a} is a digit.'.format(ch))
657 663
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 '\U00010427\U0001044F') 796 '\U00010427\U0001044F')
791 self.assertEqual('X\U00010427x\U0001044F'.capitalize(), 797 self.assertEqual('X\U00010427x\U0001044F'.capitalize(),
792 'X\U0001044Fx\U0001044F') 798 'X\U0001044Fx\U0001044F')
793 self.assertEqual('h\u0130'.capitalize(), 'H\u0069\u0307') 799 self.assertEqual('h\u0130'.capitalize(), 'H\u0069\u0307')
794 exp = '\u0399\u0308\u0300\u0069\u0307' 800 exp = '\u0399\u0308\u0300\u0069\u0307'
795 self.assertEqual('\u1fd2\u0130'.capitalize(), exp) 801 self.assertEqual('\u1fd2\u0130'.capitalize(), exp)
796 self.assertEqual('finnish'.capitalize(), 'FInnish') 802 self.assertEqual('finnish'.capitalize(), 'FInnish')
797 self.assertEqual('A\u0345\u03a3'.capitalize(), 'A\u0345\u03c2') 803 self.assertEqual('A\u0345\u03a3'.capitalize(), 'A\u0345\u03c2')
798 804
799 def test_title(self): 805 def test_title(self):
800 string_tests.MixinStrUnicodeUserStringTest.test_title(self) 806 super().test_title()
801 self.assertEqual('\U0001044F'.title(), '\U00010427') 807 self.assertEqual('\U0001044F'.title(), '\U00010427')
802 self.assertEqual('\U0001044F\U0001044F'.title(), 808 self.assertEqual('\U0001044F\U0001044F'.title(),
803 '\U00010427\U0001044F') 809 '\U00010427\U0001044F')
804 self.assertEqual('\U0001044F\U0001044F \U0001044F\U0001044F'.title(), 810 self.assertEqual('\U0001044F\U0001044F \U0001044F\U0001044F'.title(),
805 '\U00010427\U0001044F \U00010427\U0001044F') 811 '\U00010427\U0001044F \U00010427\U0001044F')
806 self.assertEqual('\U00010427\U0001044F \U00010427\U0001044F'.title(), 812 self.assertEqual('\U00010427\U0001044F \U00010427\U0001044F'.title(),
807 '\U00010427\U0001044F \U00010427\U0001044F') 813 '\U00010427\U0001044F \U00010427\U0001044F')
808 self.assertEqual('\U0001044F\U00010427 \U0001044F\U00010427'.title(), 814 self.assertEqual('\U0001044F\U00010427 \U0001044F\U00010427'.title(),
809 '\U00010427\U0001044F \U00010427\U0001044F') 815 '\U00010427\U0001044F \U00010427\U0001044F')
810 self.assertEqual('X\U00010427x\U0001044F X\U00010427x\U0001044F'.title() , 816 self.assertEqual('X\U00010427x\U0001044F X\U00010427x\U0001044F'.title() ,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 class J(int): 985 class J(int):
980 def __format__(self, format_spec): 986 def __format__(self, format_spec):
981 return int.__format__(self * 2, format_spec) 987 return int.__format__(self * 2, format_spec)
982 988
983 class M: 989 class M:
984 def __init__(self, x): 990 def __init__(self, x):
985 self.x = x 991 self.x = x
986 def __repr__(self): 992 def __repr__(self):
987 return 'M(' + self.x + ')' 993 return 'M(' + self.x + ')'
988 __str__ = None 994 __str__ = None
989 995
990 class N: 996 class N:
991 def __init__(self, x): 997 def __init__(self, x):
992 self.x = x 998 self.x = x
993 def __repr__(self): 999 def __repr__(self):
994 return 'N(' + self.x + ')' 1000 return 'N(' + self.x + ')'
995 __format__ = None 1001 __format__ = None
996 1002
997 self.assertEqual(''.format(), '') 1003 self.assertEqual(''.format(), '')
998 self.assertEqual('abc'.format(), 'abc') 1004 self.assertEqual('abc'.format(), 'abc')
999 self.assertEqual('{0}'.format('abc'), 'abc') 1005 self.assertEqual('{0}'.format('abc'), 'abc')
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 self.assertEqual(seq.decode('utf-8', 'replace'), res) 1790 self.assertEqual(seq.decode('utf-8', 'replace'), res)
1785 self.assertEqual((seq+b'b').decode('utf-8', 'replace'), res+'b') 1791 self.assertEqual((seq+b'b').decode('utf-8', 'replace'), res+'b')
1786 self.assertEqual(seq.decode('utf-8', 'ignore'), 1792 self.assertEqual(seq.decode('utf-8', 'ignore'),
1787 res.replace('\uFFFD', '')) 1793 res.replace('\uFFFD', ''))
1788 1794
1789 def to_bytestring(self, seq): 1795 def to_bytestring(self, seq):
1790 return bytes(int(c, 16) for c in seq.split()) 1796 return bytes(int(c, 16) for c in seq.split())
1791 1797
1792 def assertCorrectUTF8Decoding(self, seq, res, err): 1798 def assertCorrectUTF8Decoding(self, seq, res, err):
1793 """ 1799 """
1794 Check that an invalid UTF-8 sequence raises an UnicodeDecodeError when 1800 Check that an invalid UTF-8 sequence raises a UnicodeDecodeError when
1795 'strict' is used, returns res when 'replace' is used, and that doesn't 1801 'strict' is used, returns res when 'replace' is used, and that doesn't
1796 return anything when 'ignore' is used. 1802 return anything when 'ignore' is used.
1797 """ 1803 """
1798 with self.assertRaises(UnicodeDecodeError) as cm: 1804 with self.assertRaises(UnicodeDecodeError) as cm:
1799 seq.decode('utf-8') 1805 seq.decode('utf-8')
1800 exc = cm.exception 1806 exc = cm.exception
1801 1807
1802 self.assertIn(err, str(exc)) 1808 self.assertIn(err, str(exc))
1803 self.assertEqual(seq.decode('utf-8', 'replace'), res) 1809 self.assertEqual(seq.decode('utf-8', 'replace'), res)
1804 self.assertEqual((b'aaaa' + seq + b'bbbb').decode('utf-8', 'replace'), 1810 self.assertEqual((b'aaaa' + seq + b'bbbb').decode('utf-8', 'replace'),
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
2735 # Due to CPython specific optimization the 's' string can be 2741 # Due to CPython specific optimization the 's' string can be
2736 # resized in-place. 2742 # resized in-place.
2737 s += chr(k) 2743 s += chr(k)
2738 # Parsing with the "s#" format code calls indirectly 2744 # Parsing with the "s#" format code calls indirectly
2739 # PyUnicode_AsUTF8AndSize() which creates the UTF-8 2745 # PyUnicode_AsUTF8AndSize() which creates the UTF-8
2740 # encoded string cached in the Unicode object. 2746 # encoded string cached in the Unicode object.
2741 self.assertEqual(getargs_s_hash(s), chr(k).encode() * (i + 1)) 2747 self.assertEqual(getargs_s_hash(s), chr(k).encode() * (i + 1))
2742 # Check that the second call returns the same result 2748 # Check that the second call returns the same result
2743 self.assertEqual(getargs_s_hash(s), chr(k).encode() * (i + 1)) 2749 self.assertEqual(getargs_s_hash(s), chr(k).encode() * (i + 1))
2744 2750
2751 def test_free_after_iterating(self):
2752 support.check_free_after_iterating(self, iter, str)
2753 support.check_free_after_iterating(self, reversed, str)
2754
2745 2755
2746 class StringModuleTest(unittest.TestCase): 2756 class StringModuleTest(unittest.TestCase):
2747 def test_formatter_parser(self): 2757 def test_formatter_parser(self):
2748 def parse(format): 2758 def parse(format):
2749 return list(_string.formatter_parser(format)) 2759 return list(_string.formatter_parser(format))
2750 2760
2751 formatter = parse("prefix {2!s}xxx{0:^+10.3f}{obj.attr!s} {z[0]!s:10}") 2761 formatter = parse("prefix {2!s}xxx{0:^+10.3f}{obj.attr!s} {z[0]!s:10}")
2752 self.assertEqual(formatter, [ 2762 self.assertEqual(formatter, [
2753 ('prefix ', '2', '', 's'), 2763 ('prefix ', '2', '', 's'),
2754 ('xxx', '0', '^+10.3f', None), 2764 ('xxx', '0', '^+10.3f', None),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2789 "obj", 2799 "obj",
2790 [(True, 'arg'), 2800 [(True, 'arg'),
2791 (False, 'key1'), 2801 (False, 'key1'),
2792 (False, 'key2'), 2802 (False, 'key2'),
2793 ]]) 2803 ]])
2794 self.assertRaises(TypeError, _string.formatter_field_name_split, 1) 2804 self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
2795 2805
2796 2806
2797 if __name__ == "__main__": 2807 if __name__ == "__main__":
2798 unittest.main() 2808 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+