Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 1 | from test.support import verbose, TestFailed |
Victor Stinner | 41a863c | 2012-02-24 00:37:51 +0100 | [diff] [blame] | 2 | import locale |
Eric S. Raymond | d8c628b | 2001-02-09 11:46:37 +0000 | [diff] [blame] | 3 | import sys |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 4 | import test.support as support |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 5 | import unittest |
| 6 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 7 | maxsize = support.MAX_Py_ssize_t |
Marc-André Lemburg | d70141a | 2000-06-30 10:26:29 +0000 | [diff] [blame] | 8 | |
| 9 | # test string formatting operator (I am not sure if this is being tested |
| 10 | # elsewhere but, surely, some of the given cases are *not* tested because |
| 11 | # they crash python) |
| 12 | # test on unicode strings as well |
| 13 | |
Mark Dickinson | b7be570 | 2010-02-23 13:20:58 +0000 | [diff] [blame] | 14 | def testformat(formatstr, args, output=None, limit=None, overflowok=False): |
Tim Peters | 38fd5b6 | 2000-09-21 05:43:11 +0000 | [diff] [blame] | 15 | if verbose: |
| 16 | if output: |
Walter Dörwald | 38e43c2 | 2007-06-09 16:13:23 +0000 | [diff] [blame] | 17 | print("%r %% %r =? %r ..." %\ |
| 18 | (formatstr, args, output), end=' ') |
Tim Peters | 38fd5b6 | 2000-09-21 05:43:11 +0000 | [diff] [blame] | 19 | else: |
Walter Dörwald | 38e43c2 | 2007-06-09 16:13:23 +0000 | [diff] [blame] | 20 | print("%r %% %r works? ..." % (formatstr, args), end=' ') |
Tim Peters | 38fd5b6 | 2000-09-21 05:43:11 +0000 | [diff] [blame] | 21 | try: |
| 22 | result = formatstr % args |
| 23 | except OverflowError: |
| 24 | if not overflowok: |
| 25 | raise |
| 26 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 27 | print('overflow (this is fine)') |
Tim Peters | 38fd5b6 | 2000-09-21 05:43:11 +0000 | [diff] [blame] | 28 | else: |
Mark Dickinson | 5354a1f | 2010-02-07 13:15:37 +0000 | [diff] [blame] | 29 | if output and limit is None and result != output: |
Guido van Rossum | b5a755e | 2007-07-18 18:15:48 +0000 | [diff] [blame] | 30 | if verbose: |
| 31 | print('no') |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 32 | raise AssertionError("%r %% %r == %r != %r" % |
| 33 | (formatstr, args, result, output)) |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 34 | # when 'limit' is specified, it determines how many characters |
| 35 | # must match exactly; lengths must always match. |
| 36 | # ex: limit=5, '12345678' matches '12345___' |
| 37 | # (mainly for floating point format tests for which an exact match |
| 38 | # can't be guaranteed due to rounding and representation errors) |
| 39 | elif output and limit is not None and ( |
| 40 | len(result)!=len(output) or result[:limit]!=output[:limit]): |
| 41 | if verbose: |
| 42 | print('no') |
| 43 | print("%s %% %s == %s != %s" % \ |
| 44 | (repr(formatstr), repr(args), repr(result), repr(output))) |
Tim Peters | 38fd5b6 | 2000-09-21 05:43:11 +0000 | [diff] [blame] | 45 | else: |
| 46 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 47 | print('yes') |
Marc-André Lemburg | d70141a | 2000-06-30 10:26:29 +0000 | [diff] [blame] | 48 | |
Tim Peters | 38fd5b6 | 2000-09-21 05:43:11 +0000 | [diff] [blame] | 49 | |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 50 | class FormatTest(unittest.TestCase): |
| 51 | def test_format(self): |
| 52 | testformat("%.1d", (1,), "1") |
Mark Dickinson | b7be570 | 2010-02-23 13:20:58 +0000 | [diff] [blame] | 53 | testformat("%.*d", (sys.maxsize,1), overflowok=True) # expect overflow |
| 54 | testformat("%.100d", (1,), '00000000000000000000000000000000000000' |
| 55 | '000000000000000000000000000000000000000000000000000000' |
| 56 | '00000001', overflowok=True) |
| 57 | testformat("%#.117x", (1,), '0x00000000000000000000000000000000000' |
| 58 | '000000000000000000000000000000000000000000000000000000' |
| 59 | '0000000000000000000000000001', |
| 60 | overflowok=True) |
| 61 | testformat("%#.118x", (1,), '0x00000000000000000000000000000000000' |
| 62 | '000000000000000000000000000000000000000000000000000000' |
| 63 | '00000000000000000000000000001', |
| 64 | overflowok=True) |
Marc-André Lemburg | d70141a | 2000-06-30 10:26:29 +0000 | [diff] [blame] | 65 | |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 66 | testformat("%f", (1.0,), "1.000000") |
| 67 | # these are trying to test the limits of the internal magic-number-length |
| 68 | # formatting buffer, if that number changes then these tests are less |
| 69 | # effective |
| 70 | testformat("%#.*g", (109, -1.e+49/3.)) |
| 71 | testformat("%#.*g", (110, -1.e+49/3.)) |
| 72 | testformat("%#.*g", (110, -1.e+100/3.)) |
| 73 | # test some ridiculously large precision, expect overflow |
| 74 | testformat('%12.*f', (123456, 1.0)) |
Mark Dickinson | 5354a1f | 2010-02-07 13:15:37 +0000 | [diff] [blame] | 75 | |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 76 | # check for internal overflow validation on length of precision |
Mark Dickinson | 5354a1f | 2010-02-07 13:15:37 +0000 | [diff] [blame] | 77 | # these tests should no longer cause overflow in Python |
| 78 | # 2.7/3.1 and later. |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 79 | testformat("%#.*g", (110, -1.e+100/3.)) |
| 80 | testformat("%#.*G", (110, -1.e+100/3.)) |
| 81 | testformat("%#.*f", (110, -1.e+100/3.)) |
| 82 | testformat("%#.*F", (110, -1.e+100/3.)) |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 83 | # Formatting of integers. Overflow is not ok |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 84 | testformat("%x", 10, "a") |
| 85 | testformat("%x", 100000000000, "174876e800") |
| 86 | testformat("%o", 10, "12") |
| 87 | testformat("%o", 100000000000, "1351035564000") |
| 88 | testformat("%d", 10, "10") |
| 89 | testformat("%d", 100000000000, "100000000000") |
| 90 | big = 123456789012345678901234567890 |
| 91 | testformat("%d", big, "123456789012345678901234567890") |
| 92 | testformat("%d", -big, "-123456789012345678901234567890") |
| 93 | testformat("%5d", -big, "-123456789012345678901234567890") |
| 94 | testformat("%31d", -big, "-123456789012345678901234567890") |
| 95 | testformat("%32d", -big, " -123456789012345678901234567890") |
| 96 | testformat("%-32d", -big, "-123456789012345678901234567890 ") |
| 97 | testformat("%032d", -big, "-0123456789012345678901234567890") |
| 98 | testformat("%-032d", -big, "-123456789012345678901234567890 ") |
| 99 | testformat("%034d", -big, "-000123456789012345678901234567890") |
| 100 | testformat("%034d", big, "0000123456789012345678901234567890") |
| 101 | testformat("%0+34d", big, "+000123456789012345678901234567890") |
| 102 | testformat("%+34d", big, " +123456789012345678901234567890") |
| 103 | testformat("%34d", big, " 123456789012345678901234567890") |
| 104 | testformat("%.2d", big, "123456789012345678901234567890") |
| 105 | testformat("%.30d", big, "123456789012345678901234567890") |
| 106 | testformat("%.31d", big, "0123456789012345678901234567890") |
| 107 | testformat("%32.31d", big, " 0123456789012345678901234567890") |
| 108 | testformat("%d", float(big), "123456________________________", 6) |
| 109 | big = 0x1234567890abcdef12345 # 21 hex digits |
| 110 | testformat("%x", big, "1234567890abcdef12345") |
| 111 | testformat("%x", -big, "-1234567890abcdef12345") |
| 112 | testformat("%5x", -big, "-1234567890abcdef12345") |
| 113 | testformat("%22x", -big, "-1234567890abcdef12345") |
| 114 | testformat("%23x", -big, " -1234567890abcdef12345") |
| 115 | testformat("%-23x", -big, "-1234567890abcdef12345 ") |
| 116 | testformat("%023x", -big, "-01234567890abcdef12345") |
| 117 | testformat("%-023x", -big, "-1234567890abcdef12345 ") |
| 118 | testformat("%025x", -big, "-0001234567890abcdef12345") |
| 119 | testformat("%025x", big, "00001234567890abcdef12345") |
| 120 | testformat("%0+25x", big, "+0001234567890abcdef12345") |
| 121 | testformat("%+25x", big, " +1234567890abcdef12345") |
| 122 | testformat("%25x", big, " 1234567890abcdef12345") |
| 123 | testformat("%.2x", big, "1234567890abcdef12345") |
| 124 | testformat("%.21x", big, "1234567890abcdef12345") |
| 125 | testformat("%.22x", big, "01234567890abcdef12345") |
| 126 | testformat("%23.22x", big, " 01234567890abcdef12345") |
| 127 | testformat("%-23.22x", big, "01234567890abcdef12345 ") |
| 128 | testformat("%X", big, "1234567890ABCDEF12345") |
| 129 | testformat("%#X", big, "0X1234567890ABCDEF12345") |
| 130 | testformat("%#x", big, "0x1234567890abcdef12345") |
| 131 | testformat("%#x", -big, "-0x1234567890abcdef12345") |
| 132 | testformat("%#.23x", -big, "-0x001234567890abcdef12345") |
| 133 | testformat("%#+.23x", big, "+0x001234567890abcdef12345") |
| 134 | testformat("%# .23x", big, " 0x001234567890abcdef12345") |
| 135 | testformat("%#+.23X", big, "+0X001234567890ABCDEF12345") |
| 136 | testformat("%#-+.23X", big, "+0X001234567890ABCDEF12345") |
| 137 | testformat("%#-+26.23X", big, "+0X001234567890ABCDEF12345") |
| 138 | testformat("%#-+27.23X", big, "+0X001234567890ABCDEF12345 ") |
| 139 | testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345") |
| 140 | # next one gets two leading zeroes from precision, and another from the |
| 141 | # 0 flag and the width |
| 142 | testformat("%#+027.23X", big, "+0X0001234567890ABCDEF12345") |
| 143 | # same, except no 0 flag |
| 144 | testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345") |
| 145 | testformat("%x", float(big), "123456_______________", 6) |
| 146 | big = 0o12345670123456701234567012345670 # 32 octal digits |
| 147 | testformat("%o", big, "12345670123456701234567012345670") |
| 148 | testformat("%o", -big, "-12345670123456701234567012345670") |
| 149 | testformat("%5o", -big, "-12345670123456701234567012345670") |
| 150 | testformat("%33o", -big, "-12345670123456701234567012345670") |
| 151 | testformat("%34o", -big, " -12345670123456701234567012345670") |
| 152 | testformat("%-34o", -big, "-12345670123456701234567012345670 ") |
| 153 | testformat("%034o", -big, "-012345670123456701234567012345670") |
| 154 | testformat("%-034o", -big, "-12345670123456701234567012345670 ") |
| 155 | testformat("%036o", -big, "-00012345670123456701234567012345670") |
| 156 | testformat("%036o", big, "000012345670123456701234567012345670") |
| 157 | testformat("%0+36o", big, "+00012345670123456701234567012345670") |
| 158 | testformat("%+36o", big, " +12345670123456701234567012345670") |
| 159 | testformat("%36o", big, " 12345670123456701234567012345670") |
| 160 | testformat("%.2o", big, "12345670123456701234567012345670") |
| 161 | testformat("%.32o", big, "12345670123456701234567012345670") |
| 162 | testformat("%.33o", big, "012345670123456701234567012345670") |
| 163 | testformat("%34.33o", big, " 012345670123456701234567012345670") |
| 164 | testformat("%-34.33o", big, "012345670123456701234567012345670 ") |
| 165 | testformat("%o", big, "12345670123456701234567012345670") |
| 166 | testformat("%#o", big, "0o12345670123456701234567012345670") |
| 167 | testformat("%#o", -big, "-0o12345670123456701234567012345670") |
| 168 | testformat("%#.34o", -big, "-0o0012345670123456701234567012345670") |
| 169 | testformat("%#+.34o", big, "+0o0012345670123456701234567012345670") |
| 170 | testformat("%# .34o", big, " 0o0012345670123456701234567012345670") |
| 171 | testformat("%#+.34o", big, "+0o0012345670123456701234567012345670") |
| 172 | testformat("%#-+.34o", big, "+0o0012345670123456701234567012345670") |
| 173 | testformat("%#-+37.34o", big, "+0o0012345670123456701234567012345670") |
| 174 | testformat("%#+37.34o", big, "+0o0012345670123456701234567012345670") |
| 175 | # next one gets one leading zero from precision |
| 176 | testformat("%.33o", big, "012345670123456701234567012345670") |
| 177 | # base marker shouldn't change that, since "0" is redundant |
| 178 | testformat("%#.33o", big, "0o012345670123456701234567012345670") |
| 179 | # but reduce precision, and base marker should add a zero |
| 180 | testformat("%#.32o", big, "0o12345670123456701234567012345670") |
| 181 | # one leading zero from precision, and another from "0" flag & width |
| 182 | testformat("%034.33o", big, "0012345670123456701234567012345670") |
| 183 | # base marker shouldn't change that |
| 184 | testformat("%0#34.33o", big, "0o012345670123456701234567012345670") |
| 185 | testformat("%o", float(big), "123456__________________________", 6) |
| 186 | # Some small ints, in both Python int and flavors). |
| 187 | testformat("%d", 42, "42") |
| 188 | testformat("%d", -42, "-42") |
| 189 | testformat("%d", 42, "42") |
| 190 | testformat("%d", -42, "-42") |
| 191 | testformat("%d", 42.0, "42") |
| 192 | testformat("%#x", 1, "0x1") |
| 193 | testformat("%#x", 1, "0x1") |
| 194 | testformat("%#X", 1, "0X1") |
| 195 | testformat("%#X", 1, "0X1") |
| 196 | testformat("%#x", 1.0, "0x1") |
| 197 | testformat("%#o", 1, "0o1") |
| 198 | testformat("%#o", 1, "0o1") |
| 199 | testformat("%#o", 0, "0o0") |
| 200 | testformat("%#o", 0, "0o0") |
| 201 | testformat("%o", 0, "0") |
| 202 | testformat("%o", 0, "0") |
| 203 | testformat("%d", 0, "0") |
| 204 | testformat("%d", 0, "0") |
| 205 | testformat("%#x", 0, "0x0") |
| 206 | testformat("%#x", 0, "0x0") |
| 207 | testformat("%#X", 0, "0X0") |
| 208 | testformat("%#X", 0, "0X0") |
| 209 | testformat("%x", 0x42, "42") |
| 210 | testformat("%x", -0x42, "-42") |
| 211 | testformat("%x", 0x42, "42") |
| 212 | testformat("%x", -0x42, "-42") |
| 213 | testformat("%x", float(0x42), "42") |
| 214 | testformat("%o", 0o42, "42") |
| 215 | testformat("%o", -0o42, "-42") |
| 216 | testformat("%o", 0o42, "42") |
| 217 | testformat("%o", -0o42, "-42") |
| 218 | testformat("%o", float(0o42), "42") |
Amaury Forgeot d'Arc | a083f1e | 2008-09-10 23:51:42 +0000 | [diff] [blame] | 219 | testformat("%r", "\u0378", "'\\u0378'") # non printable |
| 220 | testformat("%a", "\u0378", "'\\u0378'") # non printable |
Amaury Forgeot d'Arc | a819caa | 2008-07-04 17:57:09 +0000 | [diff] [blame] | 221 | testformat("%r", "\u0374", "'\u0374'") # printable |
| 222 | testformat("%a", "\u0374", "'\\u0374'") # printable |
Eric Smith | 0923d1d | 2009-04-16 20:16:10 +0000 | [diff] [blame] | 223 | |
| 224 | # alternate float formatting |
| 225 | testformat('%g', 1.1, '1.1') |
| 226 | testformat('%#g', 1.1, '1.10000') |
| 227 | |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 228 | # Test exception for unknown format characters |
| 229 | if verbose: |
| 230 | print('Testing exceptions') |
| 231 | def test_exc(formatstr, args, exception, excmsg): |
| 232 | try: |
| 233 | testformat(formatstr, args) |
| 234 | except exception as exc: |
| 235 | if str(exc) == excmsg: |
| 236 | if verbose: |
| 237 | print("yes") |
| 238 | else: |
| 239 | if verbose: print('no') |
| 240 | print('Unexpected ', exception, ':', repr(str(exc))) |
| 241 | except: |
| 242 | if verbose: print('no') |
| 243 | print('Unexpected exception') |
| 244 | raise |
| 245 | else: |
| 246 | raise TestFailed('did not get expected exception: %s' % excmsg) |
Georg Brandl | 559e5d7 | 2008-06-11 18:37:52 +0000 | [diff] [blame] | 247 | test_exc('abc %b', 1, ValueError, |
| 248 | "unsupported format character 'b' (0x62) at index 5") |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 249 | #test_exc(unicode('abc %\u3000','raw-unicode-escape'), 1, ValueError, |
| 250 | # "unsupported format character '?' (0x3000) at index 5") |
| 251 | test_exc('%d', '1', TypeError, "%d format: a number is required, not str") |
| 252 | test_exc('%g', '1', TypeError, "a float is required") |
| 253 | test_exc('no format', '1', TypeError, |
| 254 | "not all arguments converted during string formatting") |
| 255 | test_exc('no format', '1', TypeError, |
| 256 | "not all arguments converted during string formatting") |
Marc-André Lemburg | d70141a | 2000-06-30 10:26:29 +0000 | [diff] [blame] | 257 | |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 258 | if maxsize == 2**31-1: |
| 259 | # crashes 2.2.1 and earlier: |
| 260 | try: |
| 261 | "%*d"%(maxsize, -127) |
| 262 | except MemoryError: |
| 263 | pass |
| 264 | else: |
| 265 | raise TestFailed('"%*d"%(maxsize, -127) should fail') |
Guido van Rossum | b5a755e | 2007-07-18 18:15:48 +0000 | [diff] [blame] | 266 | |
Victor Stinner | a4ac600 | 2012-01-21 15:50:49 +0100 | [diff] [blame] | 267 | def test_non_ascii(self): |
Victor Stinner | 184252a | 2012-06-16 02:57:41 +0200 | [diff] [blame] | 268 | testformat("\u20ac=%f", (1.0,), "\u20ac=1.000000") |
| 269 | |
Victor Stinner | a4ac600 | 2012-01-21 15:50:49 +0100 | [diff] [blame] | 270 | self.assertEqual(format("abc", "\u2007<5"), "abc\u2007\u2007") |
| 271 | self.assertEqual(format(123, "\u2007<5"), "123\u2007\u2007") |
| 272 | self.assertEqual(format(12.3, "\u2007<6"), "12.3\u2007\u2007") |
| 273 | self.assertEqual(format(0j, "\u2007<4"), "0j\u2007\u2007") |
| 274 | self.assertEqual(format(1+2j, "\u2007<8"), "(1+2j)\u2007\u2007") |
| 275 | |
| 276 | self.assertEqual(format("abc", "\u2007>5"), "\u2007\u2007abc") |
| 277 | self.assertEqual(format(123, "\u2007>5"), "\u2007\u2007123") |
| 278 | self.assertEqual(format(12.3, "\u2007>6"), "\u2007\u200712.3") |
| 279 | self.assertEqual(format(1+2j, "\u2007>8"), "\u2007\u2007(1+2j)") |
| 280 | self.assertEqual(format(0j, "\u2007>4"), "\u2007\u20070j") |
| 281 | |
| 282 | self.assertEqual(format("abc", "\u2007^5"), "\u2007abc\u2007") |
| 283 | self.assertEqual(format(123, "\u2007^5"), "\u2007123\u2007") |
| 284 | self.assertEqual(format(12.3, "\u2007^6"), "\u200712.3\u2007") |
| 285 | self.assertEqual(format(1+2j, "\u2007^8"), "\u2007(1+2j)\u2007") |
| 286 | self.assertEqual(format(0j, "\u2007^4"), "\u20070j\u2007") |
| 287 | |
Victor Stinner | 41a863c | 2012-02-24 00:37:51 +0100 | [diff] [blame] | 288 | def test_locale(self): |
| 289 | try: |
Stefan Krah | 0509d94 | 2012-02-27 10:18:51 +0100 | [diff] [blame] | 290 | oldloc = locale.setlocale(locale.LC_ALL) |
| 291 | locale.setlocale(locale.LC_ALL, '') |
Victor Stinner | 41a863c | 2012-02-24 00:37:51 +0100 | [diff] [blame] | 292 | except locale.Error as err: |
| 293 | self.skipTest("Cannot set locale: {}".format(err)) |
| 294 | try: |
Victor Stinner | 90f50d4 | 2012-02-24 01:44:47 +0100 | [diff] [blame] | 295 | localeconv = locale.localeconv() |
| 296 | sep = localeconv['thousands_sep'] |
| 297 | point = localeconv['decimal_point'] |
| 298 | |
Victor Stinner | 41a863c | 2012-02-24 00:37:51 +0100 | [diff] [blame] | 299 | text = format(123456789, "n") |
| 300 | self.assertIn(sep, text) |
| 301 | self.assertEqual(text.replace(sep, ''), '123456789') |
Victor Stinner | 90f50d4 | 2012-02-24 01:44:47 +0100 | [diff] [blame] | 302 | |
| 303 | text = format(1234.5, "n") |
| 304 | self.assertIn(sep, text) |
| 305 | self.assertIn(point, text) |
| 306 | self.assertEqual(text.replace(sep, ''), '1234' + point + '5') |
Victor Stinner | 41a863c | 2012-02-24 00:37:51 +0100 | [diff] [blame] | 307 | finally: |
| 308 | locale.setlocale(locale.LC_ALL, oldloc) |
| 309 | |
Victor Stinner | 621ef3d | 2012-10-02 00:33:47 +0200 | [diff] [blame] | 310 | @support.cpython_only |
| 311 | def test_optimisations(self): |
| 312 | text = "abcde" # 5 characters |
| 313 | |
| 314 | self.assertIs("%s" % text, text) |
| 315 | self.assertIs("%.5s" % text, text) |
| 316 | self.assertIs("%.10s" % text, text) |
| 317 | self.assertIs("%1s" % text, text) |
| 318 | self.assertIs("%5s" % text, text) |
| 319 | |
| 320 | self.assertIs("{0}".format(text), text) |
| 321 | self.assertIs("{0:s}".format(text), text) |
| 322 | self.assertIs("{0:.5s}".format(text), text) |
| 323 | self.assertIs("{0:.10s}".format(text), text) |
| 324 | self.assertIs("{0:1s}".format(text), text) |
| 325 | self.assertIs("{0:5s}".format(text), text) |
Victor Stinner | 41a863c | 2012-02-24 00:37:51 +0100 | [diff] [blame] | 326 | |
Victor Stinner | a4ac600 | 2012-01-21 15:50:49 +0100 | [diff] [blame] | 327 | |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 328 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 329 | support.run_unittest(FormatTest) |
Tim Peters | 38fd5b6 | 2000-09-21 05:43:11 +0000 | [diff] [blame] | 330 | |
Tim Peters | 38fd5b6 | 2000-09-21 05:43:11 +0000 | [diff] [blame] | 331 | |
Christian Heimes | f6cd967 | 2008-03-26 13:45:42 +0000 | [diff] [blame] | 332 | if __name__ == "__main__": |
| 333 | unittest.main() |