Skip to content

Commit 2d802d1

Browse files
authored
build: Add linting to the PR process (#1168)
1 parent 4fcd6a1 commit 2d802d1

File tree

5 files changed

+41
-33
lines changed

5 files changed

+41
-33
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,5 @@ jobs:
9595
cache-dependency-path: "code/frontend/package-lock.json"
9696
- name: Run frontend unit tests
9797
run: make unittest-frontend
98+
- name: Lint
99+
run: make lint

code/create_app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from os import path
1010
import sys
1111
import requests
12-
from openai import AzureOpenAI, Stream, RateLimitError, APIStatusError
12+
from openai import AzureOpenAI, Stream, APIStatusError
1313
from openai.types.chat import ChatCompletionChunk
1414
from flask import Flask, Response, request, Request, jsonify
1515
from dotenv import load_dotenv
@@ -24,6 +24,7 @@
2424
ERROR_GENERIC_MESSAGE = "An error occurred. Please try again. If the problem persists, please contact the site administrator."
2525
logger = logging.getLogger(__name__)
2626

27+
2728
def stream_with_data(response: Stream[ChatCompletionChunk]):
2829
"""This function streams the response from Azure OpenAI with data."""
2930
response_obj = {

code/tests/search_utilities/test_azure_search_handler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,13 @@ def test_semantic_search_with_advanced_image_processing(
364364
top=handler.env_helper.AZURE_SEARCH_TOP_K,
365365
)
366366

367+
367368
@pytest.fixture
368369
def search_handler():
369-
env_helper=Mock()
370+
env_helper = Mock()
370371
return AzureSearchHandler(env_helper)
371372

373+
372374
def test_search_with_facets_no_search_client(search_handler):
373375

374376
search_handler.search_client = None
@@ -387,12 +389,11 @@ def test_search_with_facets_valid(search_handler):
387389
assert result == "search_results"
388390

389391

390-
391392
def test_get_unique_files_no_results(search_handler):
392393
results = None
393394
facet_key = "facet_key"
394395
result = search_handler.get_unique_files(results, facet_key)
395-
assert(result, [])
396+
assert result == []
396397

397398

398399
def test_get_unique_files_with_results(search_handler):
@@ -405,7 +406,7 @@ def test_get_unique_files_with_results(search_handler):
405406
}
406407
facet_key = "facet_key"
407408
result = search_handler.get_unique_files(mock_results, facet_key)
408-
assert(result, ["file1", "file2"])
409+
assert result == ["file1", "file2"]
409410

410411

411412
def test_delete_from_index(handler, mock_search_client):

code/tests/test_app.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from unittest.mock import AsyncMock, MagicMock, Mock, patch, ANY
66

7-
from httpx import Response
87
from openai import RateLimitError, BadRequestError, InternalServerError
98
import pytest
109
from flask.testing import FlaskClient
@@ -335,17 +334,19 @@ def test_conversation_custom_returns_error_response_on_rate_limit_error(
335334
response_mock = Mock()
336335
response_mock.status_code = 429
337336
response_mock.json.return_value = {
338-
'error': {
339-
'code': "429",
340-
'message': 'Requests to the Embeddings_Create Operation under Azure OpenAI API version 2024-02-01 '
341-
'have exceeded call rate limit of your current OpenAI S0 pricing tier. Please retry after '
342-
'2 seconds. Please go here: https://aka.ms/oai/quotaincrease if you would like to further '
343-
'increase the default rate limit.'
337+
"error": {
338+
"code": "429",
339+
"message": "Requests to the Embeddings_Create Operation under Azure OpenAI API version 2024-02-01 "
340+
"have exceeded call rate limit of your current OpenAI S0 pricing tier. Please retry after "
341+
"2 seconds. Please go here: https://aka.ms/oai/quotaincrease if you would like to further "
342+
"increase the default rate limit.",
344343
}
345344
}
346345
body_mock = {"error": "Rate limit exceeded"}
347346

348-
rate_limit_error = RateLimitError("Rate limit exceeded", response=response_mock, body=body_mock)
347+
rate_limit_error = RateLimitError(
348+
"Rate limit exceeded", response=response_mock, body=body_mock
349+
)
349350
get_orchestrator_config_mock.side_effect = rate_limit_error
350351

351352
# when
@@ -359,18 +360,20 @@ def test_conversation_custom_returns_error_response_on_rate_limit_error(
359360
assert response.status_code == 429
360361
assert response.json == {
361362
"error": "We're currently experiencing a high number of requests for the service you're trying to access. "
362-
"Please wait a moment and try again."
363+
"Please wait a moment and try again."
363364
}
364365

365366
@patch("create_app.get_orchestrator_config")
366367
def test_conversation_custom_returns_500_when_internalservererror_occurs(
367-
self, get_orchestrator_config_mock, env_helper_mock, client
368+
self, get_orchestrator_config_mock, env_helper_mock, client
368369
):
369370
"""Test that an error response is returned when an exception occurs."""
370371
# given
371372
response_mock = MagicMock()
372373
response_mock.status_code = 500
373-
get_orchestrator_config_mock.side_effect = InternalServerError("Test exception", response=response_mock, body="")
374+
get_orchestrator_config_mock.side_effect = InternalServerError(
375+
"Test exception", response=response_mock, body=""
376+
)
374377

375378
# when
376379
response = client.post(
@@ -383,7 +386,7 @@ def test_conversation_custom_returns_500_when_internalservererror_occurs(
383386
assert response.status_code == 500
384387
assert response.json == {
385388
"error": "An error occurred. Please try again. If the problem persists, please contact the site "
386-
"administrator."
389+
"administrator."
387390
}
388391

389392
@patch("create_app.get_message_orchestrator")
@@ -756,13 +759,15 @@ def test_conversation_azure_byod_returns_500_when_exception_occurs(
756759

757760
@patch("create_app.conversation_with_data")
758761
def test_conversation_azure_byod_returns_500_when_internalservererror_occurs(
759-
self, conversation_with_data_mock, env_helper_mock, client
762+
self, conversation_with_data_mock, env_helper_mock, client
760763
):
761764
"""Test that an error response is returned when an exception occurs."""
762765
# given
763766
response_mock = MagicMock()
764767
response_mock.status_code = 500
765-
conversation_with_data_mock.side_effect = InternalServerError("Test exception", response=response_mock, body="")
768+
conversation_with_data_mock.side_effect = InternalServerError(
769+
"Test exception", response=response_mock, body=""
770+
)
766771
env_helper_mock.CONVERSATION_FLOW = ConversationFlow.BYOD.value
767772

768773
# when
@@ -776,29 +781,30 @@ def test_conversation_azure_byod_returns_500_when_internalservererror_occurs(
776781
assert response.status_code == 500
777782
assert response.json == {
778783
"error": "An error occurred. Please try again. If the problem persists, please contact the site "
779-
"administrator."
784+
"administrator."
780785
}
781786

782787
@patch("create_app.conversation_with_data")
783788
def test_conversation_azure_byod_returns_429_on_rate_limit_error(
784-
self, conversation_with_data_mock, env_helper_mock, client
789+
self, conversation_with_data_mock, env_helper_mock, client
785790
):
786791
"""Test that a 429 response is returned on RateLimitError for BYOD conversation."""
787792
# given
788793
response_mock = MagicMock()
789794
response_mock.status_code = 400
790795
response_mock.json.return_value = {
791-
'error': {
792-
'requestid': 'f30740e1-c6e1-48ab-ab1e-35469ed41ba4',
793-
'code': "400",
794-
'message': 'An error occurred when calling Azure OpenAI: Rate limit reached for AOAI embedding '
795-
'resource: Server responded with status 429. Error message: {"error":{"code":"429",'
796-
'"message": "Rate limit is exceeded. Try again in 44 seconds."}}'
796+
"error": {
797+
"requestid": "f30740e1-c6e1-48ab-ab1e-35469ed41ba4",
798+
"code": "400",
799+
"message": "An error occurred when calling Azure OpenAI: Rate limit reached for AOAI embedding "
800+
'resource: Server responded with status 429. Error message: {"error":{"code":"429",'
801+
'"message": "Rate limit is exceeded. Try again in 44 seconds."}}',
797802
}
798803
}
799804

800-
conversation_with_data_mock.side_effect = BadRequestError(message="Error code: 400", response=response_mock,
801-
body="")
805+
conversation_with_data_mock.side_effect = BadRequestError(
806+
message="Error code: 400", response=response_mock, body=""
807+
)
802808
env_helper_mock.CONVERSATION_FLOW = ConversationFlow.BYOD.value
803809

804810
# when
@@ -812,7 +818,7 @@ def test_conversation_azure_byod_returns_429_on_rate_limit_error(
812818
assert response.status_code == 429
813819
assert response.json == {
814820
"error": "We're currently experiencing a high number of requests for the service you're trying to access. "
815-
"Please wait a moment and try again."
821+
"Please wait a moment and try again."
816822
}
817823

818824
@patch("create_app.AzureOpenAI")

code/tests/utilities/helpers/test_azure_computer_vision_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import pytest
66
from pytest_httpserver import HTTPServer
77
from trustme import CA
8-
import werkzeug
9-
import time
108
from requests import ReadTimeout
119

1210
from backend.batch.utilities.helpers.azure_computer_vision_client import (
@@ -178,7 +176,7 @@ def test_returns_text_vectors(
178176

179177
@mock.patch("backend.batch.utilities.helpers.azure_computer_vision_client.requests")
180178
def test_vectorize_image_calls_computer_vision_timeout(
181-
mock_requests: MagicMock, azure_computer_vision_client: AzureComputerVisionClient
179+
mock_requests: MagicMock, azure_computer_vision_client: AzureComputerVisionClient
182180
):
183181
mock_requests.post.side_effect = ReadTimeout("An error occurred")
184182
# when

0 commit comments

Comments
 (0)