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

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

Issue 9856: Change object.__format__(s) where s is non-empty to a TypeError
Patch Set: Created 8 years 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 | « no previous file | Lib/test/test_unicode.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Python test set -- built-in functions 1 # Python test set -- built-in functions
2 2
3 import platform 3 import platform
4 import unittest 4 import unittest
5 import sys 5 import sys
6 import warnings 6 import warnings
7 import collections 7 import collections
8 import io 8 import io
9 import os 9 import os
10 import ast 10 import ast
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 self.assertTrue(x.startswith('<object object at')) 1367 self.assertTrue(x.startswith('<object object at'))
1368 1368
1369 # first argument to object.__format__ must be string 1369 # first argument to object.__format__ must be string
1370 self.assertRaises(TypeError, object().__format__, 3) 1370 self.assertRaises(TypeError, object().__format__, 3)
1371 self.assertRaises(TypeError, object().__format__, object()) 1371 self.assertRaises(TypeError, object().__format__, object())
1372 self.assertRaises(TypeError, object().__format__, None) 1372 self.assertRaises(TypeError, object().__format__, None)
1373 1373
1374 # -------------------------------------------------------------------- 1374 # --------------------------------------------------------------------
1375 # Issue #7994: object.__format__ with a non-empty format string is 1375 # Issue #7994: object.__format__ with a non-empty format string is
1376 # deprecated 1376 # deprecated
1377 def test_deprecated_format_string(obj, fmt_str, should_raise_warning): 1377 def test_deprecated_format_string(obj, fmt_str, should_raise):
1378 with warnings.catch_warnings(record=True) as w: 1378 if should_raise:
1379 warnings.simplefilter("always", DeprecationWarning) 1379 self.assertRaises(TypeError, format, obj, fmt_str)
1380 else:
1380 format(obj, fmt_str) 1381 format(obj, fmt_str)
1381 if should_raise_warning:
1382 self.assertEqual(len(w), 1)
1383 self.assertIsInstance(w[0].message, DeprecationWarning)
1384 self.assertIn('object.__format__ with a non-empty format '
1385 'string', str(w[0].message))
1386 else:
1387 self.assertEqual(len(w), 0)
1388 1382
1389 fmt_strs = ['', 's'] 1383 fmt_strs = ['', 's']
1390 1384
1391 class A: 1385 class A:
1392 def __format__(self, fmt_str): 1386 def __format__(self, fmt_str):
1393 return format('', fmt_str) 1387 return format('', fmt_str)
1394 1388
1395 for fmt_str in fmt_strs: 1389 for fmt_str in fmt_strs:
1396 test_deprecated_format_string(A(), fmt_str, False) 1390 test_deprecated_format_string(A(), fmt_str, False)
1397 1391
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 counts = [None] * 5 1468 counts = [None] * 5
1475 for i in range(len(counts)): 1469 for i in range(len(counts)):
1476 run_unittest(*test_classes) 1470 run_unittest(*test_classes)
1477 gc.collect() 1471 gc.collect()
1478 counts[i] = sys.gettotalrefcount() 1472 counts[i] = sys.gettotalrefcount()
1479 print(counts) 1473 print(counts)
1480 1474
1481 1475
1482 if __name__ == "__main__": 1476 if __name__ == "__main__":
1483 test_main(verbose=True) 1477 test_main(verbose=True)
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_unicode.py » ('j') | no next file with comments »

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