Skip to content

Commit

Permalink
Merge pull request #16 from Rouast-Labs/dev
Browse files Browse the repository at this point in the history
Improve error codes; Fix testing on windows
  • Loading branch information
prouast authored Jan 4, 2025
2 parents b57d098 + c101813 commit a644315
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
Expand Down
6 changes: 3 additions & 3 deletions tests/test_vitallens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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")
Expand All @@ -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
6 changes: 5 additions & 1 deletion vitallens/methods/vitallens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a644315

Please sign in to comment.