Skip to content

Commit 535983d

Browse files
committed
address review: minimize diff
1 parent e6aff0a commit 535983d

1 file changed

Lines changed: 55 additions & 56 deletions

File tree

Lib/test/test_format.py

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def testcommon(formatstr, args, output=None, limit=None, overflowok=False):
7272
class FormatTest(unittest.TestCase):
7373

7474
def check_exc(self, formatstr, args, exception, excmsg):
75-
with self.assertRaisesRegex(exception, excmsg):
75+
with self.assertRaisesRegex(exception, re.escape(excmsg)):
7676
testformat(formatstr, args)
7777

7878
def check_exc_common(self, formatstr, args, exception, excmsg):
@@ -271,49 +271,49 @@ def test_common_format(self):
271271
test_exc_common("abc %1 d", 1, ValueError,
272272
"stray % at position 4 or unexpected format character ' ' at position 6")
273273
test_exc_common('abc % (x)r', {}, ValueError,
274-
"stray % at position 4 or unexpected format character '\(' at position 6")
274+
"stray % at position 4 or unexpected format character '(' at position 6")
275275
test_exc_common('abc %((x)r', {}, ValueError,
276276
"stray % or incomplete format key at position 4")
277277
test_exc_common('%r %r', 1, TypeError,
278-
"not enough arguments for format string \(got 1\)")
278+
"not enough arguments for format string (got 1)")
279279
test_exc_common('%r %r', (1,), TypeError,
280-
"not enough arguments for format string \(got 1\)")
280+
"not enough arguments for format string (got 1)")
281281
test_exc_common('%r', (), TypeError,
282-
"not enough arguments for format string \(got 0\)")
282+
"not enough arguments for format string (got 0)")
283283
test_exc_common('abc %' + '9'*50 + 'r', 1, ValueError,
284284
"width too big at position 4")
285285
test_exc_common('abc %.' + '9'*50 + 'r', 1, ValueError,
286286
"precision too big at position 4")
287287
test_exc_common('%r %*r', 1, TypeError,
288-
"not enough arguments for format string \(got 1\)")
288+
"not enough arguments for format string (got 1)")
289289
test_exc_common('%r %*r', (1,), TypeError,
290-
"not enough arguments for format string \(got 1\)")
290+
"not enough arguments for format string (got 1)")
291291
test_exc_common('%*r', (1,), TypeError,
292-
"not enough arguments for format string \(got 1\)")
292+
"not enough arguments for format string (got 1)")
293293
test_exc_common('%*r', (), TypeError,
294-
"not enough arguments for format string \(got 0\)")
294+
"not enough arguments for format string (got 0)")
295295
test_exc_common('%r %.*r', 1, TypeError,
296-
"not enough arguments for format string \(got 1\)")
296+
"not enough arguments for format string (got 1)")
297297
test_exc_common('%r %.*r', (1,), TypeError,
298-
"not enough arguments for format string \(got 1\)")
298+
"not enough arguments for format string (got 1)")
299299
test_exc_common('%.*r', (1,), TypeError,
300-
"not enough arguments for format string \(got 1\)")
300+
"not enough arguments for format string (got 1)")
301301
test_exc_common('%.*r', (), TypeError,
302-
"not enough arguments for format string \(got 0\)")
302+
"not enough arguments for format string (got 0)")
303303
test_exc_common('%(x)r', 1, TypeError,
304304
"format requires a mapping, not int")
305305
test_exc_common('%*r', 1, TypeError,
306-
"not enough arguments for format string \(got 1\)")
306+
"not enough arguments for format string (got 1)")
307307
test_exc_common('%*r', 3.14, TypeError,
308-
"not enough arguments for format string \(got 1\)")
308+
"not enough arguments for format string (got 1)")
309309
test_exc_common('%*r', (3.14, 1), TypeError,
310-
"format argument 1: \* requires int, not float")
310+
"format argument 1: * requires int, not float")
311311
test_exc_common('%.*r', 1, TypeError,
312-
"not enough arguments for format string \(got 1\)")
312+
"not enough arguments for format string (got 1)")
313313
test_exc_common('%.*r', 3.14, TypeError,
314-
"not enough arguments for format string \(got 1\)")
314+
"not enough arguments for format string (got 1)")
315315
test_exc_common('%.*r', (3.14, 1), TypeError,
316-
"format argument 1: \* requires int, not float")
316+
"format argument 1: * requires int, not float")
317317
test_exc_common('%*r', (2**1000, 1), OverflowError,
318318
"format argument 1: too big for width")
319319
test_exc_common('%*r', (-2**1000, 1), OverflowError,
@@ -357,43 +357,43 @@ def test_str_format(self):
357357
test_exc('abc %b', 1, ValueError,
358358
"unsupported format %b at position 4")
359359
test_exc("abc %\nd", 1, ValueError,
360-
"stray % at position 4 or unexpected format character U\+000A at position 5")
360+
"stray % at position 4 or unexpected format character U+000A at position 5")
361361
test_exc("abc %\x1fd", 1, ValueError,
362-
"stray % at position 4 or unexpected format character U\+001F at position 5")
362+
"stray % at position 4 or unexpected format character U+001F at position 5")
363363
test_exc("abc %\x7fd", 1, ValueError,
364-
"stray % at position 4 or unexpected format character U\+007F at position 5")
364+
"stray % at position 4 or unexpected format character U+007F at position 5")
365365
test_exc("abc %\x80d", 1, ValueError,
366-
"stray % at position 4 or unexpected format character U\+0080 at position 5")
366+
"stray % at position 4 or unexpected format character U+0080 at position 5")
367367
test_exc('abc %äd', 1, ValueError,
368-
"stray % at position 4 or unexpected format character 'ä' \(U\+00E4\) at position 5")
368+
"stray % at position 4 or unexpected format character 'ä' (U+00E4) at position 5")
369369
test_exc('abc %€d', 1, ValueError,
370-
"stray % at position 4 or unexpected format character '€' \(U\+20AC\) at position 5")
370+
"stray % at position 4 or unexpected format character '€' (U+20AC) at position 5")
371371
test_exc('no format', '1', TypeError,
372-
"not all arguments converted during string formatting \(required 0, got 1\)")
372+
"not all arguments converted during string formatting (required 0, got 1)")
373373
test_exc('%r', (1, 2), TypeError,
374-
"not all arguments converted during string formatting \(required 1, got 2\)")
374+
"not all arguments converted during string formatting (required 1, got 2)")
375375
test_exc('%(x)r %r', {'x': 1}, ValueError,
376376
"format requires a parenthesised mapping key at position 6")
377377
test_exc('%(x)*r', {'x': 1}, ValueError,
378-
"\* cannot be used with a parenthesised mapping key at position 0")
378+
"* cannot be used with a parenthesised mapping key at position 0")
379379
test_exc('%(x).*r', {'x': 1}, ValueError,
380-
"\* cannot be used with a parenthesised mapping key at position 0")
380+
"* cannot be used with a parenthesised mapping key at position 0")
381381
test_exc('%(x)d', {'x': '1'}, TypeError,
382382
"format argument 'x': %d requires a real number, not str")
383383
test_exc('%(x)x', {'x': '1'}, TypeError,
384384
"format argument 'x': %x requires an integer, not str")
385385
test_exc('%(x)g', {'x': '1'}, TypeError,
386386
"format argument 'x': %g requires a real number, not str")
387387
test_exc('%c', -1, OverflowError,
388-
"format argument: %c argument not in range\(0x110000\)")
388+
"format argument: %c argument not in range(0x110000)")
389389
test_exc('%c', (-1,), OverflowError,
390-
"format argument 1: %c argument not in range\(0x110000\)")
390+
"format argument 1: %c argument not in range(0x110000)")
391391
test_exc('%(x)c', {'x': -1}, OverflowError,
392-
"format argument 'x': %c argument not in range\(0x110000\)")
392+
"format argument 'x': %c argument not in range(0x110000)")
393393
test_exc('%c', sys.maxunicode+1, OverflowError,
394-
"format argument: %c argument not in range\(0x110000\)")
394+
"format argument: %c argument not in range(0x110000)")
395395
test_exc('%c', 2**128, OverflowError,
396-
"format argument: %c argument not in range\(0x110000\)")
396+
"format argument: %c argument not in range(0x110000)")
397397
test_exc('%c', 3.14, TypeError,
398398
"format argument: %c requires an integer or a unicode character, not float")
399399
test_exc('%c', (3.14,), TypeError,
@@ -457,7 +457,6 @@ def __bytes__(self):
457457
# Test exception for unknown format characters, etc.
458458
if verbose:
459459
print('Testing exceptions')
460-
461460
test_exc = self.check_exc
462461
test_exc(b"abc %\nd", 1, ValueError,
463462
"stray % at position 4 or unexpected format character with code 0x0a at position 5")
@@ -470,55 +469,55 @@ def __bytes__(self):
470469
test_exc(b"abc %\x80d", 1, ValueError,
471470
"stray % at position 4 or unexpected format character with code 0x80 at position 5")
472471
test_exc(b'no format', 7, TypeError,
473-
"not all arguments converted during bytes formatting \(required 0, got 1\)")
472+
"not all arguments converted during bytes formatting (required 0, got 1)")
474473
test_exc(b'no format', b'1', TypeError,
475-
"not all arguments converted during bytes formatting \(required 0, got 1\)")
474+
"not all arguments converted during bytes formatting (required 0, got 1)")
476475
test_exc(b'no format', bytearray(b'1'), TypeError,
477-
"not all arguments converted during bytes formatting \(required 0, got 1\)")
476+
"not all arguments converted during bytes formatting (required 0, got 1)")
478477
test_exc(b'%r', (1, 2), TypeError,
479-
"not all arguments converted during bytes formatting \(required 1, got 2\)")
478+
"not all arguments converted during bytes formatting (required 1, got 2)")
480479
test_exc(b'%(x)r %r', {b'x': 1}, ValueError,
481480
"format requires a parenthesised mapping key at position 6")
482481
test_exc(b'%(x)*r', {b'x': 1}, ValueError,
483-
"\* cannot be used with a parenthesised mapping key at position 0")
482+
"* cannot be used with a parenthesised mapping key at position 0")
484483
test_exc(b'%(x).*r', {b'x': 1}, ValueError,
485-
"\* cannot be used with a parenthesised mapping key at position 0")
484+
"* cannot be used with a parenthesised mapping key at position 0")
486485
test_exc(b'%(x)d', {b'x': '1'}, TypeError,
487486
"format argument b'x': %d requires a real number, not str")
488487
test_exc(b'%(x)x', {b'x': '1'}, TypeError,
489488
"format argument b'x': %x requires an integer, not str")
490489
test_exc(b'%(x)g', {b'x': '1'}, TypeError,
491490
"format argument b'x': %g requires a real number, not str")
492491
test_exc(b"%c", -1, OverflowError,
493-
"format argument: %c argument not in range\(256\)")
492+
"format argument: %c argument not in range(256)")
494493
test_exc(b"%c", (-1,), OverflowError,
495-
"format argument 1: %c argument not in range\(256\)")
494+
"format argument 1: %c argument not in range(256)")
496495
test_exc(b"%(x)c", {b'x': -1}, OverflowError,
497-
"format argument b'x': %c argument not in range\(256\)")
496+
"format argument b'x': %c argument not in range(256)")
498497
test_exc(b"%c", 256, OverflowError,
499-
"format argument: %c argument not in range\(256\)")
498+
"format argument: %c argument not in range(256)")
500499
test_exc(b"%c", 2**128, OverflowError,
501-
"format argument: %c argument not in range\(256\)")
500+
"format argument: %c argument not in range(256)")
502501
test_exc(b"%c", b"Za", TypeError,
503-
"format argument: %c requires an integer in range\(256\) or a single byte, not a bytes object of length 2")
502+
"format argument: %c requires an integer in range(256) or a single byte, not a bytes object of length 2")
504503
test_exc(b"%c", (b"Za",), TypeError,
505-
"format argument 1: %c requires an integer in range\(256\) or a single byte, not a bytes object of length 2")
504+
"format argument 1: %c requires an integer in range(256) or a single byte, not a bytes object of length 2")
506505
test_exc(b"%(x)c", {b'x': b"Za"}, TypeError,
507-
"format argument b'x': %c requires an integer in range\(256\) or a single byte, not a bytes object of length 2")
506+
"format argument b'x': %c requires an integer in range(256) or a single byte, not a bytes object of length 2")
508507
test_exc(b"%c", bytearray(b"Za"), TypeError,
509-
"format argument: %c requires an integer in range\(256\) or a single byte, not a bytearray object of length 2")
508+
"format argument: %c requires an integer in range(256) or a single byte, not a bytearray object of length 2")
510509
test_exc(b"%c", (bytearray(b"Za"),), TypeError,
511-
"format argument 1: %c requires an integer in range\(256\) or a single byte, not a bytearray object of length 2")
510+
"format argument 1: %c requires an integer in range(256) or a single byte, not a bytearray object of length 2")
512511
test_exc(b"%(x)c", {b'x': bytearray(b"Za")}, TypeError,
513-
"format argument b'x': %c requires an integer in range\(256\) or a single byte, not a bytearray object of length 2")
512+
"format argument b'x': %c requires an integer in range(256) or a single byte, not a bytearray object of length 2")
514513
test_exc(b"%c", "Y", TypeError,
515-
"format argument: %c requires an integer in range\(256\) or a single byte, not str")
514+
"format argument: %c requires an integer in range(256) or a single byte, not str")
516515
test_exc(b"%c", 3.14, TypeError,
517-
"format argument: %c requires an integer in range\(256\) or a single byte, not float")
516+
"format argument: %c requires an integer in range(256) or a single byte, not float")
518517
test_exc(b"%c", (3.14,), TypeError,
519-
"format argument 1: %c requires an integer in range\(256\) or a single byte, not float")
518+
"format argument 1: %c requires an integer in range(256) or a single byte, not float")
520519
test_exc(b"%(x)c", {b'x': 3.14}, TypeError,
521-
"format argument b'x': %c requires an integer in range\(256\) or a single byte, not float")
520+
"format argument b'x': %c requires an integer in range(256) or a single byte, not float")
522521
test_exc(b"%b", "Xc", TypeError,
523522
"format argument: %b requires a bytes-like object, "
524523
"or an object that implements __bytes__, not str")

0 commit comments

Comments
 (0)