Skip to content

Comments

tests: branches coverage in responses.py, staticfiles.py, templating.py, middleware/wsgi.py and endpoints.py#2804

Merged
Kludex merged 4 commits intoKludex:masterfrom
lealre:test-coverage-branch-true
Dec 25, 2024
Merged

tests: branches coverage in responses.py, staticfiles.py, templating.py, middleware/wsgi.py and endpoints.py#2804
Kludex merged 4 commits intoKludex:masterfrom
lealre:test-coverage-branch-true

Conversation

@lealre
Copy link
Contributor

@lealre lealre commented Dec 16, 2024

Summary

Related to issue #2452.

responses.py - 117→124

Test with samesite = None added.

staticfiles.py - 207→212

Test with etag not matching the headers["if-none-match"].

templating.py - 46→56

It seems that TestClient adds {'http.response.debug': {}} to the scope on every HTTP request (line 310), making the statement always True.
Added pragma: no branch and needs confirmation.

middleware/wsgi.py - 124→exit

self.response_started is initialized as False in WSGIResponder and is only used in WSGIMiddleware (line 79). Removing the if statement does not affect the tests.
Added pragma: no branch and needs confirmation.

endpoints.py - 77→72

It seems there are only two possible options inside the while loop.
Added pragma: no branch and needs confirmation.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

…ting.py`, `middleware/wsgi.py` and `endpoints.py`
request = self.context.get("request", {})
extensions = request.get("extensions", {})
if "http.response.debug" in extensions:
if "http.response.debug" in extensions: # pragma: no branch
Copy link
Owner

Choose a reason for hiding this comment

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

This can be tested without the TestClient.

We have some tests that don't use the TestClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right, I didn't think about it.

Added a test to the case based on other similar tests

Copy link
Owner

Choose a reason for hiding this comment

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

I put this back. I think this is enough for the "http.response.debug".

request = self.context.get("request", {})
extensions = request.get("extensions", {})
if "http.response.debug" in extensions:
if "http.response.debug" in extensions: # pragma: no branch
Copy link
Owner

Choose a reason for hiding this comment

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

I put this back. I think this is enough for the "http.response.debug".

@Kludex Kludex enabled auto-merge (squash) December 25, 2024 08:54
@Kludex Kludex merged commit 70a04ee into Kludex:master Dec 25, 2024
6 checks passed
@lealre lealre deleted the test-coverage-branch-true branch December 25, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants