Skip to content

Add tests for xmlrpc.client.SafeTransport#154016

Open
magic-peach wants to merge 1 commit into
python:mainfrom
magic-peach:add-safetransport-tests
Open

Add tests for xmlrpc.client.SafeTransport#154016
magic-peach wants to merge 1 commit into
python:mainfrom
magic-peach:add-safetransport-tests

Conversation

@magic-peach

Copy link
Copy Markdown

Summary

The SafeTransport class in Lib/xmlrpc/client.py has 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 SafeTransportTestCase class to Lib/test/test_xmlrpc.py with 10 test methods:

  • Initialization tests: Verify SafeTransport stores context, datetime, builtin_types, and headers correctly
  • make_connection tests: Test connection creation with mocked HTTPSConnection
  • Connection caching: Verify that calling make_connection with the same host returns the cached connection
  • Different hosts: Verify new connections are created for different hosts
  • Tuple host format: Test (host, x509) tuple format used for SSL certificate info
  • Missing HTTPS support: Test NotImplementedError when HTTPSConnection is unavailable

All 104 tests in test_xmlrpc.py pass (including 10 new tests).

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
@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Jul 18, 2026
@bedevere-app

bedevere-app Bot commented Jul 18, 2026

Copy link
Copy Markdown

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 skip news label instead.

@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread Lib/test/test_xmlrpc.py
Comment on lines +1550 to +1552
def test_init_with_context(self):
import ssl
ctx = ssl.create_default_context()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant