From f1f4c77fea99518a2b1f78e6832342962a794530 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 13:56:39 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?= =?UTF-8?q?=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_param_allow_inf_nan.py | 59 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/test_param_allow_inf_nan.py b/test_param_allow_inf_nan.py index 4488eeaea..7941b8dc0 100644 --- a/test_param_allow_inf_nan.py +++ b/test_param_allow_inf_nan.py @@ -6,53 +6,56 @@ from fastapi.testclient import TestClient app = FastAPI() + @app.get("/") def get( - x: Optional[float] = Query(default=0, allow_inf_nan=False), - y: Optional[float] = Query(default=0, allow_inf_nan=True), - z: Optional[float] = Query(default=0)) -> str: # type: ignore - return 'OK' + x: Optional[float] = Query(default=0, allow_inf_nan=False), + y: Optional[float] = Query(default=0, allow_inf_nan=True), + z: Optional[float] = Query(default=0), +) -> str: # type: ignore + return "OK" client = TestClient(app) def test_allow_inf_nan_false(): - response = client.get('/?x=inf') - assert response.status_code == 422, response.text - - response = client.get('/?x=-inf') - assert response.status_code == 422, response.text - - response = client.get('/?x=nan') + response = client.get("/?x=inf") assert response.status_code == 422, response.text - response = client.get('/?x=0') + response = client.get("/?x=-inf") + assert response.status_code == 422, response.text + + response = client.get("/?x=nan") + assert response.status_code == 422, response.text + + response = client.get("/?x=0") assert response.status_code == 200, response.text + def test_allow_inf_nan_true(): - response = client.get('/?y=inf') - assert response.status_code == 200, response.text - - response = client.get('/?y=-inf') - assert response.status_code == 200, response.text - - response = client.get('/?y=nan') + response = client.get("/?y=inf") assert response.status_code == 200, response.text - response = client.get('/?y=0') + response = client.get("/?y=-inf") assert response.status_code == 200, response.text + response = client.get("/?y=nan") + assert response.status_code == 200, response.text + + response = client.get("/?y=0") + assert response.status_code == 200, response.text + + def test_allow_inf_nan_not_specified(): - response = client.get('/?z=inf') - assert response.status_code == 200, response.text - - response = client.get('/?z=-inf') - assert response.status_code == 200, response.text - - response = client.get('/?z=nan') + response = client.get("/?z=inf") assert response.status_code == 200, response.text - response = client.get('/?z=0') + response = client.get("/?z=-inf") assert response.status_code == 200, response.text + response = client.get("/?z=nan") + assert response.status_code == 200, response.text + + response = client.get("/?z=0") + assert response.status_code == 200, response.text