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

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

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 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
« no previous file with comments | « Lib/test/test_urlparse.py ('k') | Lib/test/test_zipimport.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 from contextlib import contextmanager 1 from contextlib import contextmanager
2 import linecache 2 import linecache
3 import os 3 import os
4 from io import StringIO 4 from io import StringIO
5 import sys 5 import sys
6 import unittest 6 import unittest
7 import subprocess 7 import subprocess
8 from test import support 8 from test import support
9 from test.script_helper import assert_python_ok 9 from test.script_helper import assert_python_ok
10 10
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 self.module.filterwarnings("always", category=UserWarning) 505 self.module.filterwarnings("always", category=UserWarning)
506 del self.module.showwarning 506 del self.module.showwarning
507 with support.captured_output('stderr') as stream: 507 with support.captured_output('stderr') as stream:
508 self.module.warn(text) 508 self.module.warn(text)
509 result = stream.getvalue() 509 result = stream.getvalue()
510 self.assertIn(text, result) 510 self.assertIn(text, result)
511 511
512 def test_showwarning_not_callable(self): 512 def test_showwarning_not_callable(self):
513 with original_warnings.catch_warnings(module=self.module): 513 with original_warnings.catch_warnings(module=self.module):
514 self.module.filterwarnings("always", category=UserWarning) 514 self.module.filterwarnings("always", category=UserWarning)
515 self.module.showwarning = print 515 old_showwarning = self.module.showwarning
516 with support.captured_output('stdout'):
517 self.module.warn('Warning!')
518 self.module.showwarning = 23 516 self.module.showwarning = 23
519 self.assertRaises(TypeError, self.module.warn, "Warning!") 517 try:
518 self.assertRaises(TypeError, self.module.warn, "Warning!")
519 finally:
520 self.module.showwarning = old_showwarning
520 521
521 def test_show_warning_output(self): 522 def test_show_warning_output(self):
522 # With showarning() missing, make sure that output is okay. 523 # With showarning() missing, make sure that output is okay.
523 text = 'test show_warning' 524 text = 'test show_warning'
524 with original_warnings.catch_warnings(module=self.module): 525 with original_warnings.catch_warnings(module=self.module):
525 self.module.filterwarnings("always", category=UserWarning) 526 self.module.filterwarnings("always", category=UserWarning)
526 del self.module.showwarning 527 del self.module.showwarning
527 with support.captured_output('stderr') as stream: 528 with support.captured_output('stderr') as stream:
528 warning_tests.inner(text) 529 warning_tests.inner(text)
529 result = stream.getvalue() 530 result = stream.getvalue()
530 self.assertEqual(result.count('\n'), 2, 531 self.assertEqual(result.count('\n'), 2,
531 "Too many newlines in %r" % result) 532 "Too many newlines in %r" % result)
532 first_line, second_line = result.split('\n', 1) 533 first_line, second_line = result.split('\n', 1)
533 expected_file = os.path.splitext(warning_tests.__file__)[0] + '.py' 534 expected_file = os.path.splitext(warning_tests.__file__)[0] + '.py'
534 first_line_parts = first_line.rsplit(':', 3) 535 first_line_parts = first_line.rsplit(':', 3)
535 path, line, warning_class, message = first_line_parts 536 path, line, warning_class, message = first_line_parts
536 line = int(line) 537 line = int(line)
537 self.assertEqual(expected_file, path) 538 self.assertEqual(expected_file, path)
538 self.assertEqual(warning_class, ' ' + UserWarning.__name__) 539 self.assertEqual(warning_class, ' ' + UserWarning.__name__)
539 self.assertEqual(message, ' ' + text) 540 self.assertEqual(message, ' ' + text)
540 expected_line = ' ' + linecache.getline(path, line).strip() + '\n' 541 expected_line = ' ' + linecache.getline(path, line).strip() + '\n'
541 assert expected_line 542 assert expected_line
542 self.assertEqual(second_line, expected_line) 543 self.assertEqual(second_line, expected_line)
543
544 def test_filename_none(self):
545 # issue #12467: race condition if a warning is emitted at shutdown
546 globals_dict = globals()
547 oldfile = globals_dict['__file__']
548 try:
549 catch = original_warnings.catch_warnings(record=True,
550 module=self.module)
551 with catch as w:
552 self.module.filterwarnings("always", category=UserWarning)
553 globals_dict['__file__'] = None
554 original_warnings.warn('test', UserWarning)
555 self.assertTrue(len(w))
556 finally:
557 globals_dict['__file__'] = oldfile
558 544
559 545
560 class WarningsDisplayTests(unittest.TestCase): 546 class WarningsDisplayTests(unittest.TestCase):
561 547
562 """Test the displaying of warnings and the ability to overload functions 548 """Test the displaying of warnings and the ability to overload functions
563 related to displaying warnings.""" 549 related to displaying warnings."""
564 550
565 def test_formatwarning(self): 551 def test_formatwarning(self):
566 message = "msg" 552 message = "msg"
567 category = Warning 553 category = Warning
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 _WarningsTests, 784 _WarningsTests,
799 CWarningsDisplayTests, PyWarningsDisplayTests, 785 CWarningsDisplayTests, PyWarningsDisplayTests,
800 CCatchWarningTests, PyCatchWarningTests, 786 CCatchWarningTests, PyCatchWarningTests,
801 CEnvironmentVariableTests, PyEnvironmentVariableTests, 787 CEnvironmentVariableTests, PyEnvironmentVariableTests,
802 BootstrapTest, 788 BootstrapTest,
803 ) 789 )
804 790
805 791
806 if __name__ == "__main__": 792 if __name__ == "__main__":
807 test_main() 793 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_urlparse.py ('k') | Lib/test/test_zipimport.py » ('j') | no next file with comments »

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