Add tests for xmlrpc.client.SafeTransport#154016
Conversation
The SafeTransport class has a FIXME comment indicating it is mostly untested. This adds tests for: - SafeTransport initialization with various parameters - make_connection with mocked HTTPSConnection - Connection caching behavior - Connection with tuple host (host, x509) format - NotImplementedError when HTTPSConnection is unavailable
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
The following commit authors need to sign the Contributor License Agreement: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b380b2ce8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def test_init_with_context(self): | ||
| import ssl | ||
| ctx = ssl.create_default_context() |
There was a problem hiding this comment.
Skip SafeTransport tests when SSL is unavailable
On Python builds configured without _ssl, http.client does not define HTTPSConnection, and these new tests still run: the unguarded import ssl raises ImportError, the @mock.patch('http.client.HTTPSConnection') decorators fail because the attribute is missing, and test_make_connection_no_https fails before it can exercise the NotImplementedError path. test_xmlrpc previously handled SSL as optional in test_ssl_presence, so the whole SafeTransportTestCase should be skipped or written with create=True/non-ssl sentinels when HTTPS support is absent.
Useful? React with 👍 / 👎.
Summary
The
SafeTransportclass inLib/xmlrpc/client.pyhas a FIXME comment at line 1340 indicating it is "mostly untested". This PR adds tests to cover the core functionality of this class.Changes
Added
SafeTransportTestCaseclass toLib/test/test_xmlrpc.pywith 10 test methods:HTTPSConnectionmake_connectionwith the same host returns the cached connection(host, x509)tuple format used for SSL certificate infoNotImplementedErrorwhenHTTPSConnectionis unavailableAll 104 tests in
test_xmlrpc.pypass (including 10 new tests).