From 4fbf766b3eac4146b86175682cec88d266fd8470 Mon Sep 17 00:00:00 2001 From: Orenoid <2367058391@qq.com> Date: Tue, 24 Sep 2024 02:38:19 +0800 Subject: [PATCH] test: add tests in `test_requests` (#2677) * test: add tests in test_requests * test: add test for Request.close method * fix: typo * test: ignore conditional branch in coverage report and remove unnecessary test * test: pragma no branch --------- Co-authored-by: Marcelo Trylesinski --- starlette/requests.py | 8 ++++---- tests/test_requests.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/starlette/requests.py b/starlette/requests.py index 23f8ac70a..26c13d1ca 100644 --- a/starlette/requests.py +++ b/starlette/requests.py @@ -93,7 +93,7 @@ def app(self) -> typing.Any: @property def url(self) -> URL: - if not hasattr(self, "_url"): + if not hasattr(self, "_url"): # pragma: no branch self._url = URL(scope=self.scope) return self._url @@ -122,7 +122,7 @@ def headers(self) -> Headers: @property def query_params(self) -> QueryParams: - if not hasattr(self, "_query_params"): + if not hasattr(self, "_query_params"): # pragma: no branch self._query_params = QueryParams(self.scope["query_string"]) return self._query_params @@ -237,7 +237,7 @@ async def body(self) -> bytes: return self._body async def json(self) -> typing.Any: - if not hasattr(self, "_json"): + if not hasattr(self, "_json"): # pragma: no branch body = await self.body() self._json = json.loads(body) return self._json @@ -276,7 +276,7 @@ def form( return AwaitableOrContextManagerWrapper(self._get_form(max_files=max_files, max_fields=max_fields)) async def close(self) -> None: - if self._form is not None: + if self._form is not None: # pragma: no branch await self._form.close() async def is_disconnected(self) -> bool: diff --git a/tests/test_requests.py b/tests/test_requests.py index 02f29ee35..2f173713e 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -425,7 +425,7 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None: # Browsers don't send extra whitespace or semicolons in Cookie headers, # but cookie_parser() should parse whitespace the same way # document.cookie parses whitespace. - # (" = b ; ; = ; c = ; ", {"": "b", "c": ""}), + (" = b ; ; = ; c = ; ", {"": "b", "c": ""}), ], ) def test_cookies_invalid(