From 334b1924778e2e76ad71d30c9ae12bfaa1e75168 Mon Sep 17 00:00:00 2001 From: Philipp Rouast Date: Sat, 4 Jan 2025 19:48:19 +1100 Subject: [PATCH 1/4] Changed handling of state; Improved error messages --- tests/test_vitallens.py | 6 +++--- vitallens/methods/vitallens.py | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_vitallens.py b/tests/test_vitallens.py index 2b5531a..f1ceb85 100644 --- a/tests/test_vitallens.py +++ b/tests/test_vitallens.py @@ -90,7 +90,7 @@ def create_mock_api_response( "ppg_waveform": {"data": np.random.rand(video.shape[0]).tolist(), "unit": "unitless", "confidence": np.ones(video.shape[0]).tolist(), "note": "Note"}, "respiratory_waveform": {"data": np.random.rand(video.shape[0]).tolist(), "unit": "unitless", "confidence": np.ones(video.shape[0]).tolist(), "note": "Note"}}, "face": {"confidence": np.random.rand(video.shape[0]).tolist(), "note": "Note"}, - "state": {"data": np.zeros((2, 128), dtype=np.float32).tolist(), "note": "Note"}, + "state": {"data": np.zeros((256,), dtype=np.float32).tolist(), "note": "Note"}, "message": "Message"}) @pytest.mark.parametrize("file", [True, False]) @@ -167,7 +167,7 @@ def test_VitalLens_API_valid_response(request, process_signals, n_frames): live = np.asarray(response_body["face"]["confidence"]) assert live.shape == (n_frames,) state = np.asarray(response_body["state"]["data"]) - assert state.shape == (2, 128) + assert state.shape == (256,) def test_VitalLens_API_wrong_api_key(request): config = load_config("vitallens.yaml") @@ -194,4 +194,4 @@ def test_VitalLens_API_no_parseable_video(request): headers = {"x-api-key": api_key} payload = {"video": "not_parseable"} response = requests.post(API_URL, headers=headers, json=payload) - assert response.status_code == 400 + assert response.status_code == 422 diff --git a/vitallens/methods/vitallens.py b/vitallens/methods/vitallens.py index 41a4d27..805f1c9 100644 --- a/vitallens/methods/vitallens.py +++ b/vitallens/methods/vitallens.py @@ -255,7 +255,11 @@ def process_api_batch( elif response.status_code == 429: raise VitalLensAPIQuotaExceededError() elif response.status_code == 400: - raise VitalLensAPIError("Error occurred in the API. Message: {}".format(response_body['message'])) + raise VitalLensAPIError("Parameters missing: {}".format(response_body['message'])) + elif response.status_code == 422: + raise VitalLensAPIError("Issue with provided parameters: {}".format(response_body['message'])) + elif response.status_code == 500: + raise VitalLensAPIError("Error occurred in the API: {}".format(response_body['message'])) else: raise Exception("Error {}: {}".format(response.status_code, response_body['message'])) # Parse response From 02fbe3069e27d2e09eae54a09b4fcdd7e84b9681 Mon Sep 17 00:00:00 2001 From: Philipp Rouast Date: Sat, 4 Jan 2025 20:03:19 +1100 Subject: [PATCH 2/4] Attempt to fix issue with test setup on windows --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8905c13..c404f1b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,7 +66,7 @@ jobs: python -m pip install ".[test]" - name: Set development API_URL for non-main branches if: github.ref != 'refs/heads/main' - run: echo "API_URL=https://api.rouast.com/vitallens-dev" >> $GITHUB_ENV + run: echo API_URL=https://api.rouast.com/vitallens-dev >> %GITHUB_ENV% - name: Lint with flake8 run: | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics From a9272d2137cfab3b912f88e351daffa9cc909572 Mon Sep 17 00:00:00 2001 From: Philipp Rouast Date: Sat, 4 Jan 2025 20:13:14 +1100 Subject: [PATCH 3/4] Attempt again to fix issue with test setup on windows --- .github/workflows/main.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c404f1b..291a64c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,12 +66,19 @@ jobs: python -m pip install ".[test]" - name: Set development API_URL for non-main branches if: github.ref != 'refs/heads/main' - run: echo API_URL=https://api.rouast.com/vitallens-dev >> %GITHUB_ENV% + run: echo "Setting development API_URL" + env: + API_URL: "https://api.rouast.com/vitallens-dev" + - name: Confirm API_URL is set + run: echo "API_URL=${API_URL}" + env: + API_URL: ${{ env.API_URL }} - name: Lint with flake8 run: | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - name: Test with pytest env: + API_URL: ${{ env.API_URL }} VITALLENS_DEV_API_KEY: ${{ secrets.VITALLENS_DEV_API_KEY }} run: | pytest From c101813102b5d4ea2439d78f7bad93b778b8515a Mon Sep 17 00:00:00 2001 From: Philipp Rouast Date: Sun, 5 Jan 2025 08:13:45 +1100 Subject: [PATCH 4/4] Attempt again to fix issue with test setup on windows --- .github/workflows/main.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 291a64c..58819c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,19 +66,12 @@ jobs: python -m pip install ".[test]" - name: Set development API_URL for non-main branches if: github.ref != 'refs/heads/main' - run: echo "Setting development API_URL" - env: - API_URL: "https://api.rouast.com/vitallens-dev" - - name: Confirm API_URL is set - run: echo "API_URL=${API_URL}" - env: - API_URL: ${{ env.API_URL }} + run: echo "API_URL=https://api.rouast.com/vitallens-dev" | Out-File -FilePath $env:GITHUB_ENV -Append - name: Lint with flake8 run: | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - name: Test with pytest env: - API_URL: ${{ env.API_URL }} VITALLENS_DEV_API_KEY: ${{ secrets.VITALLENS_DEV_API_KEY }} run: | pytest