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

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

Issue 25958: Implicit ABCs have no means of "anti-registration"
Patch Set: Created 4 years, 3 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
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 itertools 10 import itertools
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 return object.__format__(self, format_spec) 973 return object.__format__(self, format_spec)
974 974
975 class I(datetime.date): 975 class I(datetime.date):
976 def __format__(self, format_spec): 976 def __format__(self, format_spec):
977 return self.strftime(format_spec) 977 return self.strftime(format_spec)
978 978
979 class J(int): 979 class J(int):
980 def __format__(self, format_spec): 980 def __format__(self, format_spec):
981 return int.__format__(self * 2, format_spec) 981 return int.__format__(self * 2, format_spec)
982 982
983 class M:
984 def __init__(self, x):
985 self.x = x
986 def __repr__(self):
987 return 'M(' + self.x + ')'
988 __str__ = None
989
990 class N:
991 def __init__(self, x):
992 self.x = x
993 def __repr__(self):
994 return 'N(' + self.x + ')'
995 __format__ = None
983 996
984 self.assertEqual(''.format(), '') 997 self.assertEqual(''.format(), '')
985 self.assertEqual('abc'.format(), 'abc') 998 self.assertEqual('abc'.format(), 'abc')
986 self.assertEqual('{0}'.format('abc'), 'abc') 999 self.assertEqual('{0}'.format('abc'), 'abc')
987 self.assertEqual('{0:}'.format('abc'), 'abc') 1000 self.assertEqual('{0:}'.format('abc'), 'abc')
988 # self.assertEqual('{ 0 }'.format('abc'), 'abc') 1001 # self.assertEqual('{ 0 }'.format('abc'), 'abc')
989 self.assertEqual('X{0}'.format('abc'), 'Xabc') 1002 self.assertEqual('X{0}'.format('abc'), 'Xabc')
990 self.assertEqual('{0}X'.format('abc'), 'abcX') 1003 self.assertEqual('{0}X'.format('abc'), 'abcX')
991 self.assertEqual('X{0}Y'.format('abc'), 'XabcY') 1004 self.assertEqual('X{0}Y'.format('abc'), 'XabcY')
992 self.assertEqual('{1}'.format(1, 'abc'), 'abc') 1005 self.assertEqual('{1}'.format(1, 'abc'), 'abc')
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 self.assertEqual("{[{}]}".format({"{}" : "a"}), "a") 1199 self.assertEqual("{[{}]}".format({"{}" : "a"}), "a")
1187 self.assertEqual("{[{]}".format({"{" : "a"}), "a") 1200 self.assertEqual("{[{]}".format({"{" : "a"}), "a")
1188 self.assertEqual("{[}]}".format({"}" : "a"}), "a") 1201 self.assertEqual("{[}]}".format({"}" : "a"}), "a")
1189 self.assertEqual("{[[]}".format({"[" : "a"}), "a") 1202 self.assertEqual("{[[]}".format({"[" : "a"}), "a")
1190 self.assertEqual("{[!]}".format({"!" : "a"}), "a") 1203 self.assertEqual("{[!]}".format({"!" : "a"}), "a")
1191 self.assertRaises(ValueError, "{a{}b}".format, 42) 1204 self.assertRaises(ValueError, "{a{}b}".format, 42)
1192 self.assertRaises(ValueError, "{a{b}".format, 42) 1205 self.assertRaises(ValueError, "{a{b}".format, 42)
1193 self.assertRaises(ValueError, "{[}".format, 42) 1206 self.assertRaises(ValueError, "{[}".format, 42)
1194 1207
1195 self.assertEqual("0x{:0{:d}X}".format(0x0,16), "0x0000000000000000") 1208 self.assertEqual("0x{:0{:d}X}".format(0x0,16), "0x0000000000000000")
1209
1210 # Blocking fallback
1211 m = M('data')
1212 self.assertEqual("{!r}".format(m), 'M(data)')
1213 self.assertRaises(TypeError, "{!s}".format, m)
1214 self.assertRaises(TypeError, "{}".format, m)
1215 n = N('data')
1216 self.assertEqual("{!r}".format(n), 'N(data)')
1217 self.assertEqual("{!s}".format(n), 'N(data)')
1218 self.assertRaises(TypeError, "{}".format, n)
1196 1219
1197 def test_format_map(self): 1220 def test_format_map(self):
1198 self.assertEqual(''.format_map({}), '') 1221 self.assertEqual(''.format_map({}), '')
1199 self.assertEqual('a'.format_map({}), 'a') 1222 self.assertEqual('a'.format_map({}), 'a')
1200 self.assertEqual('ab'.format_map({}), 'ab') 1223 self.assertEqual('ab'.format_map({}), 'ab')
1201 self.assertEqual('a{{'.format_map({}), 'a{') 1224 self.assertEqual('a{{'.format_map({}), 'a{')
1202 self.assertEqual('a}}'.format_map({}), 'a}') 1225 self.assertEqual('a}}'.format_map({}), 'a}')
1203 self.assertEqual('{{b'.format_map({}), '{b') 1226 self.assertEqual('{{b'.format_map({}), '{b')
1204 self.assertEqual('}}b'.format_map({}), '}b') 1227 self.assertEqual('}}b'.format_map({}), '}b')
1205 self.assertEqual('a{{b'.format_map({}), 'a{b') 1228 self.assertEqual('a{{b'.format_map({}), 'a{b')
(...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after
2766 "obj", 2789 "obj",
2767 [(True, 'arg'), 2790 [(True, 'arg'),
2768 (False, 'key1'), 2791 (False, 'key1'),
2769 (False, 'key2'), 2792 (False, 'key2'),
2770 ]]) 2793 ]])
2771 self.assertRaises(TypeError, _string.formatter_field_name_split, 1) 2794 self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
2772 2795
2773 2796
2774 if __name__ == "__main__": 2797 if __name__ == "__main__":
2775 unittest.main() 2798 unittest.main()
OLDNEW
« Lib/test/test_bytes.py ('K') | « Lib/test/test_iter.py ('k') | Objects/enumobject.c » ('j') | no next file with comments »

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