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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 7 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_xdrlib.py ('k') | Lib/test/test_zlib.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 import base64 1 import base64
2 import datetime 2 import datetime
3 import sys 3 import sys
4 import time 4 import time
5 import unittest 5 import unittest
6 from unittest import mock 6 from unittest import mock
7 import xmlrpc.client as xmlrpclib 7 import xmlrpc.client as xmlrpclib
8 import xmlrpc.server 8 import xmlrpc.server
9 import http.client 9 import http.client
10 import socket 10 import socket
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 # use the broken message class 951 # use the broken message class
952 xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageCl ass 952 xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageCl ass
953 953
954 try: 954 try:
955 p = xmlrpclib.ServerProxy(URL) 955 p = xmlrpclib.ServerProxy(URL)
956 p.pow(6,8) 956 p.pow(6,8)
957 except (xmlrpclib.ProtocolError, OSError) as e: 957 except (xmlrpclib.ProtocolError, OSError) as e:
958 # ignore failures due to non-blocking socket 'unavailable' errors 958 # ignore failures due to non-blocking socket 'unavailable' errors
959 if not is_unavailable_exception(e) and hasattr(e, "headers"): 959 if not is_unavailable_exception(e) and hasattr(e, "headers"):
960 # The two server-side error headers shouldn't be sent back in th is case 960 # The two server-side error headers shouldn't be sent back in th is case
961 self.assertTrue(e.headers.get("X-exception") is None) 961 self.assertIsNone(e.headers.get("X-exception"))
962 self.assertTrue(e.headers.get("X-traceback") is None) 962 self.assertIsNone(e.headers.get("X-traceback"))
963 else: 963 else:
964 self.fail('ProtocolError not raised') 964 self.fail('ProtocolError not raised')
965 965
966 def test_fail_with_info(self): 966 def test_fail_with_info(self):
967 # use the broken message class 967 # use the broken message class
968 xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageCl ass 968 xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageCl ass
969 969
970 # Check that errors in the server send back exception/traceback 970 # Check that errors in the server send back exception/traceback
971 # info when flag is set 971 # info when flag is set
972 xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True 972 xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True
973 973
974 try: 974 try:
975 p = xmlrpclib.ServerProxy(URL) 975 p = xmlrpclib.ServerProxy(URL)
976 p.pow(6,8) 976 p.pow(6,8)
977 except (xmlrpclib.ProtocolError, OSError) as e: 977 except (xmlrpclib.ProtocolError, OSError) as e:
978 # ignore failures due to non-blocking socket 'unavailable' errors 978 # ignore failures due to non-blocking socket 'unavailable' errors
979 if not is_unavailable_exception(e) and hasattr(e, "headers"): 979 if not is_unavailable_exception(e) and hasattr(e, "headers"):
980 # We should get error info in the response 980 # We should get error info in the response
981 expected_err = "invalid literal for int() with base 10: 'I am br oken'" 981 expected_err = "invalid literal for int() with base 10: 'I am br oken'"
982 self.assertEqual(e.headers.get("X-exception"), expected_err) 982 self.assertEqual(e.headers.get("X-exception"), expected_err)
983 self.assertTrue(e.headers.get("X-traceback") is not None) 983 self.assertIsNotNone(e.headers.get("X-traceback"))
984 else: 984 else:
985 self.fail('ProtocolError not raised') 985 self.fail('ProtocolError not raised')
986 986
987 987
988 @contextlib.contextmanager 988 @contextlib.contextmanager
989 def captured_stdout(encoding='utf-8'): 989 def captured_stdout(encoding='utf-8'):
990 """A variation on support.captured_stdout() which gives a text stream 990 """A variation on support.captured_stdout() which gives a text stream
991 having a `buffer` attribute. 991 having a `buffer` attribute.
992 """ 992 """
993 import io 993 import io
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 support.run_unittest(XMLRPCTestCase, HelperTestCase, DateTimeTestCase, 1105 support.run_unittest(XMLRPCTestCase, HelperTestCase, DateTimeTestCase,
1106 BinaryTestCase, FaultTestCase, UseBuiltinTypesTestCase, 1106 BinaryTestCase, FaultTestCase, UseBuiltinTypesTestCase,
1107 SimpleServerTestCase, KeepaliveServerTestCase1, 1107 SimpleServerTestCase, KeepaliveServerTestCase1,
1108 KeepaliveServerTestCase2, GzipServerTestCase, 1108 KeepaliveServerTestCase2, GzipServerTestCase,
1109 MultiPathServerTestCase, ServerProxyTestCase, FailingServerTestCase, 1109 MultiPathServerTestCase, ServerProxyTestCase, FailingServerTestCase,
1110 CGIHandlerTestCase) 1110 CGIHandlerTestCase)
1111 1111
1112 1112
1113 if __name__ == "__main__": 1113 if __name__ == "__main__":
1114 test_main() 1114 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_xdrlib.py ('k') | Lib/test/test_zlib.py » ('j') | no next file with comments »

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