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

Side by Side Diff: Lib/test/test_unicode.py

Issue 9856: Change object.__format__(s) where s is non-empty to a TypeError
Patch Set: Created 7 years, 8 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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_builtin.py ('k') | Objects/typeobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 struct 10 import struct
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 self.assertEqual('{0!a}'.format(F('\u0374')), 'F(\\u0374)') 782 self.assertEqual('{0!a}'.format(F('\u0374')), 'F(\\u0374)')
783 783
784 # test fallback to object.__format__ 784 # test fallback to object.__format__
785 self.assertEqual('{0}'.format({}), '{}') 785 self.assertEqual('{0}'.format({}), '{}')
786 self.assertEqual('{0}'.format([]), '[]') 786 self.assertEqual('{0}'.format([]), '[]')
787 self.assertEqual('{0}'.format([1]), '[1]') 787 self.assertEqual('{0}'.format([1]), '[1]')
788 788
789 self.assertEqual('{0:d}'.format(G('data')), 'G(data)') 789 self.assertEqual('{0:d}'.format(G('data')), 'G(data)')
790 self.assertEqual('{0!s}'.format(G('data')), 'string is data') 790 self.assertEqual('{0!s}'.format(G('data')), 'string is data')
791 791
792 msg = 'object.__format__ with a non-empty format string is deprecated' 792 self.assertRaises(TypeError, '{0:^10}'.format, E('data'))
793 with support.check_warnings((msg, DeprecationWarning)): 793 self.assertRaises(TypeError, '{0:^10s}'.format, E('data'))
794 self.assertEqual('{0:^10}'.format(E('data')), ' E(data) ') 794 self.assertRaises(TypeError, '{0:>15s}'.format, G('data'))
795 self.assertEqual('{0:^10s}'.format(E('data')), ' E(data) ')
796 self.assertEqual('{0:>15s}'.format(G('data')), ' string is data')
797 795
798 self.assertEqual("{0:date: %Y-%m-%d}".format(I(year=2007, 796 self.assertEqual("{0:date: %Y-%m-%d}".format(I(year=2007,
799 month=8, 797 month=8,
800 day=27)), 798 day=27)),
801 "date: 2007-08-27") 799 "date: 2007-08-27")
802 800
803 # test deriving from a builtin type and overriding __format__ 801 # test deriving from a builtin type and overriding __format__
804 self.assertEqual("{0}".format(J(10)), "20") 802 self.assertEqual("{0}".format(J(10)), "20")
805 803
806 804
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 (False, 'key2'), 1887 (False, 'key2'),
1890 ]]) 1888 ]])
1891 self.assertRaises(TypeError, _string.formatter_field_name_split, 1) 1889 self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
1892 1890
1893 1891
1894 def test_main(): 1892 def test_main():
1895 support.run_unittest(__name__) 1893 support.run_unittest(__name__)
1896 1894
1897 if __name__ == "__main__": 1895 if __name__ == "__main__":
1898 test_main() 1896 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_builtin.py ('k') | Objects/typeobject.c » ('j') | no next file with comments »

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