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

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, 5 months ago
Right Patch Set: Created 3 years, 9 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:
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
(no file at all)
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 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 return object.__format__(self, format_spec) 979 return object.__format__(self, format_spec)
980 980
981 class I(datetime.date): 981 class I(datetime.date):
982 def __format__(self, format_spec): 982 def __format__(self, format_spec):
983 return self.strftime(format_spec) 983 return self.strftime(format_spec)
984 984
985 class J(int): 985 class J(int):
986 def __format__(self, format_spec): 986 def __format__(self, format_spec):
987 return int.__format__(self * 2, format_spec) 987 return int.__format__(self * 2, format_spec)
988 988
989 class M:
990 def __init__(self, x):
991 self.x = x
992 def __repr__(self):
993 return 'M(' + self.x + ')'
994 __str__ = None
995
996 class N:
997 def __init__(self, x):
998 self.x = x
999 def __repr__(self):
1000 return 'N(' + self.x + ')'
1001 __format__ = None
989 1002
990 self.assertEqual(''.format(), '') 1003 self.assertEqual(''.format(), '')
991 self.assertEqual('abc'.format(), 'abc') 1004 self.assertEqual('abc'.format(), 'abc')
992 self.assertEqual('{0}'.format('abc'), 'abc') 1005 self.assertEqual('{0}'.format('abc'), 'abc')
993 self.assertEqual('{0:}'.format('abc'), 'abc') 1006 self.assertEqual('{0:}'.format('abc'), 'abc')
994 # self.assertEqual('{ 0 }'.format('abc'), 'abc') 1007 # self.assertEqual('{ 0 }'.format('abc'), 'abc')
995 self.assertEqual('X{0}'.format('abc'), 'Xabc') 1008 self.assertEqual('X{0}'.format('abc'), 'Xabc')
996 self.assertEqual('{0}X'.format('abc'), 'abcX') 1009 self.assertEqual('{0}X'.format('abc'), 'abcX')
997 self.assertEqual('X{0}Y'.format('abc'), 'XabcY') 1010 self.assertEqual('X{0}Y'.format('abc'), 'XabcY')
998 self.assertEqual('{1}'.format(1, 'abc'), 'abc') 1011 self.assertEqual('{1}'.format(1, 'abc'), 'abc')
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 self.assertEqual("{[{}]}".format({"{}" : "a"}), "a") 1205 self.assertEqual("{[{}]}".format({"{}" : "a"}), "a")
1193 self.assertEqual("{[{]}".format({"{" : "a"}), "a") 1206 self.assertEqual("{[{]}".format({"{" : "a"}), "a")
1194 self.assertEqual("{[}]}".format({"}" : "a"}), "a") 1207 self.assertEqual("{[}]}".format({"}" : "a"}), "a")
1195 self.assertEqual("{[[]}".format({"[" : "a"}), "a") 1208 self.assertEqual("{[[]}".format({"[" : "a"}), "a")
1196 self.assertEqual("{[!]}".format({"!" : "a"}), "a") 1209 self.assertEqual("{[!]}".format({"!" : "a"}), "a")
1197 self.assertRaises(ValueError, "{a{}b}".format, 42) 1210 self.assertRaises(ValueError, "{a{}b}".format, 42)
1198 self.assertRaises(ValueError, "{a{b}".format, 42) 1211 self.assertRaises(ValueError, "{a{b}".format, 42)
1199 self.assertRaises(ValueError, "{[}".format, 42) 1212 self.assertRaises(ValueError, "{[}".format, 42)
1200 1213
1201 self.assertEqual("0x{:0{:d}X}".format(0x0,16), "0x0000000000000000") 1214 self.assertEqual("0x{:0{:d}X}".format(0x0,16), "0x0000000000000000")
1215
1216 # Blocking fallback
1217 m = M('data')
1218 self.assertEqual("{!r}".format(m), 'M(data)')
1219 self.assertRaises(TypeError, "{!s}".format, m)
1220 self.assertRaises(TypeError, "{}".format, m)
1221 n = N('data')
1222 self.assertEqual("{!r}".format(n), 'N(data)')
1223 self.assertEqual("{!s}".format(n), 'N(data)')
1224 self.assertRaises(TypeError, "{}".format, n)
1202 1225
1203 def test_format_map(self): 1226 def test_format_map(self):
1204 self.assertEqual(''.format_map({}), '') 1227 self.assertEqual(''.format_map({}), '')
1205 self.assertEqual('a'.format_map({}), 'a') 1228 self.assertEqual('a'.format_map({}), 'a')
1206 self.assertEqual('ab'.format_map({}), 'ab') 1229 self.assertEqual('ab'.format_map({}), 'ab')
1207 self.assertEqual('a{{'.format_map({}), 'a{') 1230 self.assertEqual('a{{'.format_map({}), 'a{')
1208 self.assertEqual('a}}'.format_map({}), 'a}') 1231 self.assertEqual('a}}'.format_map({}), 'a}')
1209 self.assertEqual('{{b'.format_map({}), '{b') 1232 self.assertEqual('{{b'.format_map({}), '{b')
1210 self.assertEqual('}}b'.format_map({}), '}b') 1233 self.assertEqual('}}b'.format_map({}), '}b')
1211 self.assertEqual('a{{b'.format_map({}), 'a{b') 1234 self.assertEqual('a{{b'.format_map({}), 'a{b')
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 "obj", 2799 "obj",
2777 [(True, 'arg'), 2800 [(True, 'arg'),
2778 (False, 'key1'), 2801 (False, 'key1'),
2779 (False, 'key2'), 2802 (False, 'key2'),
2780 ]]) 2803 ]])
2781 self.assertRaises(TypeError, _string.formatter_field_name_split, 1) 2804 self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
2782 2805
2783 2806
2784 if __name__ == "__main__": 2807 if __name__ == "__main__":
2785 unittest.main() 2808 unittest.main()
LEFTRIGHT

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