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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 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 | « Lib/test/test_xmlrpc_net.py ('k') | Lib/test/test_zipfile.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 import xmlrpc.client as xmlrpclib 6 import xmlrpc.client as xmlrpclib
7 import xmlrpc.server 7 import xmlrpc.server
8 import http.client 8 import http.client
9 import socket 9 import socket
10 import os 10 import os
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 # use the broken message class 925 # use the broken message class
926 xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageCl ass 926 xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageCl ass
927 927
928 try: 928 try:
929 p = xmlrpclib.ServerProxy(URL) 929 p = xmlrpclib.ServerProxy(URL)
930 p.pow(6,8) 930 p.pow(6,8)
931 except (xmlrpclib.ProtocolError, OSError) as e: 931 except (xmlrpclib.ProtocolError, OSError) as e:
932 # ignore failures due to non-blocking socket 'unavailable' errors 932 # ignore failures due to non-blocking socket 'unavailable' errors
933 if not is_unavailable_exception(e) and hasattr(e, "headers"): 933 if not is_unavailable_exception(e) and hasattr(e, "headers"):
934 # The two server-side error headers shouldn't be sent back in th is case 934 # The two server-side error headers shouldn't be sent back in th is case
935 self.assertTrue(e.headers.get("X-exception") is None) 935 self.assertIsNone(e.headers.get("X-exception"))
936 self.assertTrue(e.headers.get("X-traceback") is None) 936 self.assertIsNone(e.headers.get("X-traceback"))
937 else: 937 else:
938 self.fail('ProtocolError not raised') 938 self.fail('ProtocolError not raised')
939 939
940 def test_fail_with_info(self): 940 def test_fail_with_info(self):
941 # use the broken message class 941 # use the broken message class
942 xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageCl ass 942 xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageCl ass
943 943
944 # Check that errors in the server send back exception/traceback 944 # Check that errors in the server send back exception/traceback
945 # info when flag is set 945 # info when flag is set
946 xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True 946 xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True
947 947
948 try: 948 try:
949 p = xmlrpclib.ServerProxy(URL) 949 p = xmlrpclib.ServerProxy(URL)
950 p.pow(6,8) 950 p.pow(6,8)
951 except (xmlrpclib.ProtocolError, OSError) as e: 951 except (xmlrpclib.ProtocolError, OSError) as e:
952 # ignore failures due to non-blocking socket 'unavailable' errors 952 # ignore failures due to non-blocking socket 'unavailable' errors
953 if not is_unavailable_exception(e) and hasattr(e, "headers"): 953 if not is_unavailable_exception(e) and hasattr(e, "headers"):
954 # We should get error info in the response 954 # We should get error info in the response
955 expected_err = "invalid literal for int() with base 10: 'I am br oken'" 955 expected_err = "invalid literal for int() with base 10: 'I am br oken'"
956 self.assertEqual(e.headers.get("X-exception"), expected_err) 956 self.assertEqual(e.headers.get("X-exception"), expected_err)
957 self.assertTrue(e.headers.get("X-traceback") is not None) 957 self.assertIsNotNone(e.headers.get("X-traceback"))
958 else: 958 else:
959 self.fail('ProtocolError not raised') 959 self.fail('ProtocolError not raised')
960 960
961 961
962 @contextlib.contextmanager 962 @contextlib.contextmanager
963 def captured_stdout(encoding='utf-8'): 963 def captured_stdout(encoding='utf-8'):
964 """A variation on support.captured_stdout() which gives a text stream 964 """A variation on support.captured_stdout() which gives a text stream
965 having a `buffer` attribute. 965 having a `buffer` attribute.
966 """ 966 """
967 import io 967 import io
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 pass #gzip not supported in this build 1089 pass #gzip not supported in this build
1090 xmlrpc_tests.append(MultiPathServerTestCase) 1090 xmlrpc_tests.append(MultiPathServerTestCase)
1091 xmlrpc_tests.append(ServerProxyTestCase) 1091 xmlrpc_tests.append(ServerProxyTestCase)
1092 xmlrpc_tests.append(FailingServerTestCase) 1092 xmlrpc_tests.append(FailingServerTestCase)
1093 xmlrpc_tests.append(CGIHandlerTestCase) 1093 xmlrpc_tests.append(CGIHandlerTestCase)
1094 1094
1095 support.run_unittest(*xmlrpc_tests) 1095 support.run_unittest(*xmlrpc_tests)
1096 1096
1097 if __name__ == "__main__": 1097 if __name__ == "__main__":
1098 test_main() 1098 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_xmlrpc_net.py ('k') | Lib/test/test_zipfile.py » ('j') | no next file with comments »

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