Skip to content

Add branch-coverage tests for client lifecycle, ASGI, multipart, and encoding - #3891

Open
sohams5002 wants to merge 7 commits into
encode:masterfrom
sohams5002:test-more-branch-coverage
Open

sohams5002 wants to merge 7 commits into
encode:masterfrom
sohams5002:test-more-branch-coverage

Conversation

@sohams5002

Copy link
Copy Markdown

A follow-up to #3885 with nine more small tests closing uncovered branches found with coverage run --branch:

  • test_build_request_with_timeout_extension: build_request leaves an explicit timeout extension untouched (_client.py 371->378).
  • test_close_when_already_closed / test_aclose_when_already_closed: close()/aclose() are no-ops on an already-closed client (_client.py 1267->exit, 1982->exit).
  • test_mounted_none_transport (sync and async): None mounts fall back to the default transport and are skipped when entering, exiting, and closing the client (_client.py 1272->1271, 1289->1288, 1303->1302, 1987->1986, 2004->2003, 2018->2017).
  • test_asgi_exc_no_raise_after_response_start: with raise_app_exceptions=False, an app that raises after sending the response start keeps the status and headers it already sent (_transports/asgi.py 176->178, 178->181).
  • test_asgi_ignores_debug_messages: the ASGI transport ignores http.response.debug messages (_transports/asgi.py 158->exit).
  • test_multipart_encode_filelike_without_seek: a file-like object with no seek() method at all uploads with chunked transfer encoding (_multipart.py 208->214).
  • test_encoding_with_default_encoding_callable_and_unread_stream: for an unread streaming response, a callable default_encoding cannot be applied and the fallback is "utf-8" (_models.py 669->671).

With these, _client.py, _models.py, _multipart.py, and _transports/asgi.py reach 100% branch coverage. The remaining gaps in _transports/default.py (111->105 and the two close()/aclose() hasattr guards) look unreachable through the public API, so I left them alone.

Full test suite passes locally (1430 passed, 1 skipped) and ruff check / ruff format --check are clean.

Add tests for AsyncClient closure and None transport handling
Add test for multipart encoding with file-like object
Add test for encoding with default encoding callable on unread stream.
Replaced autodetect function with a lambda for default encoding.

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant