summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xmlrpc.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2014-03-21 15:24:40 (GMT)
committerBrett Cannon <brett@python.org>2014-03-21 15:24:40 (GMT)
commit33a40003745302eff5e6031d24d26642763fb6d8 (patch)
tree75787adf85b136178f9053a54a2ed46f3f98c247 /Lib/test/test_xmlrpc.py
parent051f37d2e739981eac45051f6f2b873d2ef4699f (diff)
downloadcpython-33a40003745302eff5e6031d24d26642763fb6d8.zip
cpython-33a40003745302eff5e6031d24d26642763fb6d8.tar.gz
cpython-33a40003745302eff5e6031d24d26642763fb6d8.tar.bz2
Issue #20627: xmlrpc.client.ServerProxy is now a context manager.
Patch by Claudiu Popa.
Diffstat (limited to 'Lib/test/test_xmlrpc.py')
-rw-r--r--Lib/test/test_xmlrpc.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 99b3eda..120c54f 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -713,6 +713,23 @@ class SimpleServerTestCase(BaseServerTestCase):
conn.request('POST', '/RPC2 HTTP/1.0\r\nContent-Length: 100\r\n\r\nbye')
conn.close()
+ def test_context_manager(self):
+ with xmlrpclib.ServerProxy(URL) as server:
+ server.add(2, 3)
+ self.assertNotEqual(server('transport')._connection,
+ (None, None))
+ self.assertEqual(server('transport')._connection,
+ (None, None))
+
+ def test_context_manager_method_error(self):
+ try:
+ with xmlrpclib.ServerProxy(URL) as server:
+ server.add(2, "a")
+ except xmlrpclib.Fault:
+ pass
+ self.assertEqual(server('transport')._connection,
+ (None, None))
+
class MultiPathServerTestCase(BaseServerTestCase):
threadFunc = staticmethod(http_multi_server)
@@ -898,6 +915,7 @@ class ServerProxyTestCase(unittest.TestCase):
p = xmlrpclib.ServerProxy(self.url, transport=t)
self.assertEqual(p('transport'), t)
+
# This is a contrived way to make a failure occur on the server side
# in order to test the _send_traceback_header flag on the server
class FailingMessageClass(http.client.HTTPMessage):