Skip to content

Commit 9c11ee6

Browse files
committed
Increase test coverage
1 parent 10124eb commit 9c11ee6

File tree

11 files changed

+417
-54
lines changed

11 files changed

+417
-54
lines changed

.github/workflows/python-test.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ jobs:
6262
- name: Check formatting with black
6363
run: black . --check --verbose
6464
- name: Run Python tests
65-
if: runner.os != 'Windows'
66-
run: pytest -s -vv --cov --cov-report=xml --cov-fail-under=89
65+
run: pytest -s -vv --cov --cov-report=xml --cov-fail-under=90
6766
- name: Check diff coverage
68-
if: runner.os != 'Windows' && github.event_name == 'pull_request'
6967
run: |
7068
git fetch origin main:refs/remotes/origin/main
7169
diff-cover coverage.xml --compare-branch=origin/main --fail-under=90

tests/conftest.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
MockAzureCredential,
4343
MockAzureCredentialExpired,
4444
MockBlobClient,
45+
MockDirectoryClient,
4546
MockResponse,
4647
MockTransport,
4748
mock_retrieval_response,
@@ -237,6 +238,8 @@ async def mock_acreate(*args, **kwargs):
237238
answer = "capital of France"
238239
elif last_question == "Generate search query for: Are interest rates high?":
239240
answer = "interest rates"
241+
elif last_question == "Generate search query for: Flowers in westbrae nursery logo?":
242+
answer = "westbrae nursery logo"
240243
elif isinstance(last_question, list) and any([part.get("image_url") for part in last_question]):
241244
answer = "From the provided sources, the impact of interest rates and GDP growth on financial markets can be observed through the line graph. [Financial Market Analysis Report 2023-7.png]"
242245
else:
@@ -362,6 +365,8 @@ async def mock_exists(*args, **kwargs):
362365
"AZURE_SERVER_APP_SECRET": "SECRET",
363366
"AZURE_CLIENT_APP_ID": "CLIENT_APP",
364367
"AZURE_TENANT_ID": "TENANT_ID",
368+
"USE_MULTIMODAL": "true",
369+
"AZURE_VISION_ENDPOINT": "https://testvision.cognitiveservices.azure.com/",
365370
},
366371
]
367372

@@ -666,6 +671,7 @@ async def auth_client(
666671
mock_validate_token_success,
667672
mock_list_groups_success,
668673
mock_acs_search_filter,
674+
mock_azurehttp_calls,
669675
request,
670676
):
671677
monkeypatch.setenv("AZURE_STORAGE_ACCOUNT", "test-storage-account")
@@ -757,7 +763,6 @@ async def vision_client(
757763
test_app.app.config.update({"TESTING": True})
758764
mock_openai_chatcompletion(test_app.app.config[app.CONFIG_OPENAI_CLIENT])
759765
mock_openai_embedding(test_app.app.config[app.CONFIG_OPENAI_CLIENT])
760-
# need to mock app.CONFIG_GLOBAL_BLOB_MANAGER to
761766
mock_blob_service_client = BlobServiceClient(
762767
f"https://{os.environ['AZURE_STORAGE_ACCOUNT']}.blob.core.windows.net",
763768
credential=MockAzureCredential(),
@@ -1083,6 +1088,15 @@ def mock_readinto(self, stream: IO[bytes]):
10831088
monkeypatch.setattr(azure.storage.filedatalake.aio.StorageStreamDownloader, "readinto", mock_readinto)
10841089

10851090

1091+
@pytest.fixture
1092+
def mock_user_directory_client(monkeypatch):
1093+
monkeypatch.setattr(
1094+
azure.storage.filedatalake.aio.FileSystemClient,
1095+
"get_directory_client",
1096+
lambda *args, **kwargs: MockDirectoryClient(),
1097+
)
1098+
1099+
10861100
@pytest.fixture
10871101
def chat_approach():
10881102
return ChatReadRetrieveReadApproach(

tests/mocks.py

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,78 @@ def __init__(self, text, highlights=None, additional_properties=None):
136136

137137
class MockAsyncSearchResultsIterator:
138138
def __init__(self, search_text, vector_queries: Optional[list[VectorQuery]]):
139-
if search_text == "interest rates" or (
139+
if search_text == "westbrae nursery logo" and (
140+
vector_queries and any([vector.fields == "images/embedding" for vector in vector_queries])
141+
):
142+
self.data = [
143+
[
144+
{
145+
"id": "file-westbrae_jun28_pdf-77657374627261655F6A756E32382E7064667B276F696473273A205B2766653437353262612D623565652D343531632D623065312D393332316664663365353962275D7D-page-0",
146+
"content": '<figure><figcaption>1.1 <br>The image displays the Gmail logo. It consists of a stylized letter "M" with four colors: red, blue, green, and yellow. To the right of the "M" is the word "Gmail" written in gray text. The design is modern and clean. The colors used are characteristic of Google\'s branding.</figcaption></figure>\n\n\nPamela Fox <[email protected]>\n\nReceipt / Tax invoice (#2-108442)\n\nWestbrae Nursery <[email protected]>\nReply-To: [email protected]\nTo: [email protected]\n\nSat, Jun 28, 2025 at 1:21 PM\n\n\n<figure><figcaption>1.2 <br>The image shows the logo of Westbrae Nursery. The logo features three daffodil flowers on the left side. The text "Westbrae" is positioned to the right of the flowers. Below "Westbrae" is the word "Nursery." The design is simple and rendered in black and white.</figcaption></figure>\n\n\nAn Employee-Owned Co-op\n1272 Gilman St, Berkeley, CA 94706\n510-526-5517\n\nMain Outlet\n\nReceipt / Tax Invoice #2-108442 28 Jun 2025 1:21pm\n\n\n<figure><table><tr><td>1 Gopher Baskets</td><td>@ $7.',
147+
"category": None,
148+
"sourcepage": "westbrae_jun28.pdf#page=1",
149+
"sourcefile": "westbrae_jun28.pdf",
150+
"oids": ["OID_X"],
151+
"groups": [],
152+
"captions": [],
153+
"score": 0.05000000447034836,
154+
"reranker_score": 3.2427687644958496,
155+
"search_agent_query": None,
156+
"images": [
157+
{
158+
"url": "https://userst5gj4l5eootrlo.dfs.core.windows.net/user-content/OID_X/images/westbrae_jun28.pdf/page_0/figure1_1.png",
159+
"description": '<figure><figcaption>1.1 <br>The image displays the Gmail logo. It consists of a stylized letter "M" with four colors: red, blue, green, and yellow. To the right of the "M" is the word "Gmail" written in gray text. The design is modern and clean. The colors used are characteristic of Google\'s branding.</figcaption></figure>',
160+
"boundingbox": [32.99, 43.65, 126.14, 67.72],
161+
},
162+
{
163+
"url": "https://userst5gj4l5eootrlo.dfs.core.windows.net/user-content/OID_X/images/westbrae_jun28.pdf/page_0/figure1_2.png",
164+
"description": '<figure><figcaption>1.2 <br>The image shows the logo of Westbrae Nursery. The logo features three daffodil flowers on the left side. The text "Westbrae" is positioned to the right of the flowers. Below "Westbrae" is the word "Nursery." The design is simple and rendered in black and white.</figcaption></figure>',
165+
"boundingbox": [40.76, 163.42, 347.1, 354.15],
166+
},
167+
],
168+
},
169+
{
170+
"id": "file-westbrae_jun28_pdf-77657374627261655F6A756E32382E7064667B276F696473273A205B2766653437353262612D623565652D343531632D623065312D393332316664663365353962275D7D-page-1",
171+
"content": "</figcaption></figure>\n\n\nAn Employee-Owned Co-op\n1272 Gilman St, Berkeley, CA 94706\n510-526-5517\n\nMain Outlet\n\nReceipt / Tax Invoice #2-108442 28 Jun 2025 1:21pm\n\n\n<figure><table><tr><td>1 Gopher Baskets</td><td>@ $7.99</td><td>$7.99</td></tr><tr><td>1 qt</td><td></td><td></td></tr><tr><td rowSpan=2>1 Gopher Baskets 1 gal</td><td>@ $14.99</td><td>$14.99</td></tr><tr><td></td><td></td></tr><tr><td>1 Edible 4.99</td><td>@ $4.99</td><td>$4.99</td></tr><tr><td>4 Color 11.99</td><td>@ $11.99</td><td>$47.96</td></tr><tr><td>1 Edible $6.99</td><td>@ $6.99</td><td>$6.99</td></tr><tr><td>Subtotal</td><td></td><td>$82.",
172+
"category": None,
173+
"sourcepage": "westbrae_jun28.pdf#page=1",
174+
"sourcefile": "westbrae_jun28.pdf",
175+
"oids": ["OID_X"],
176+
"groups": [],
177+
"captions": [],
178+
"score": 0.04696394503116608,
179+
"reranker_score": 1.8582123517990112,
180+
"search_agent_query": None,
181+
"images": [
182+
{
183+
"url": "https://userst5gj4l5eootrlo.dfs.core.windows.net/user-content/OID_X/images/westbrae_jun28.pdf/page_0/figure1_1.png",
184+
"description": '<figure><figcaption>1.1 <br>The image displays the Gmail logo. It consists of a stylized letter "M" with four colors: red, blue, green, and yellow. To the right of the "M" is the word "Gmail" written in gray text. The design is modern and clean. The colors used are characteristic of Google\'s branding.</figcaption></figure>',
185+
"boundingbox": [32.99, 43.65, 126.14, 67.72],
186+
},
187+
{
188+
"url": "https://userst5gj4l5eootrlo.dfs.core.windows.net/user-content/OID_X/images/westbrae_jun28.pdf/page_0/figure1_2.png",
189+
"description": '<figure><figcaption>1.2 <br>The image shows the logo of Westbrae Nursery. The logo features three daffodil flowers on the left side. The text "Westbrae" is positioned to the right of the flowers. Below "Westbrae" is the word "Nursery." The design is simple and rendered in black and white.</figcaption></figure>',
190+
"boundingbox": [40.76, 163.42, 347.1, 354.15],
191+
},
192+
],
193+
},
194+
{
195+
"id": "file-westbrae_jun28_pdf-77657374627261655F6A756E32382E7064667B276F696473273A205B2766653437353262612D623565652D343531632D623065312D393332316664663365353962275D7D-page-4",
196+
"content": "\n\nIf you have any questions about how to take care of the plants you purchase\nor if they start to show symptoms of ill health, please, give us a call (510-526-\n5517)\n\nreceipt.pdf\n50K",
197+
"category": None,
198+
"sourcepage": "westbrae_jun28.pdf#page=2",
199+
"sourcefile": "westbrae_jun28.pdf",
200+
"oids": ["OID_X"],
201+
"groups": [],
202+
"captions": [],
203+
"score": 0.016393441706895828,
204+
"reranker_score": 1.7518715858459473,
205+
"search_agent_query": None,
206+
"images": [],
207+
},
208+
]
209+
]
210+
elif search_text == "interest rates" or (
140211
vector_queries and any([vector.fields == "images/embedding" for vector in vector_queries])
141212
):
142213
self.data = [
@@ -363,6 +434,30 @@ def get(self):
363434
return self.__result
364435

365436

437+
# Mock DirectoryClient used in blobmanager.py:AdlsBlobManager
438+
class MockDirectoryClient:
439+
async def get_directory_properties(self):
440+
# Return dummy properties to indicate directory exists
441+
return {"name": "test-directory"}
442+
443+
async def get_access_control(self):
444+
# Return a dictionary with the owner matching the auth_client's user_oid
445+
return {"owner": "OID_X"} # This should match the user_oid in auth_client
446+
447+
def get_file_client(self, filename):
448+
# Return a file client for the given filename
449+
return MockFileClient(filename)
450+
451+
452+
# Mock FileClient used in blobmanager.py:AdlsBlobManager
453+
class MockFileClient:
454+
def __init__(self, path_name):
455+
self.path_name = path_name
456+
457+
async def download_file(self):
458+
return MockBlob()
459+
460+
366461
def mock_speak_text_success(self, text):
367462
return MockSynthesisResult(MockAudio("mock_audio_data"))
368463

tests/snapshots/test_app/test_ask_rtr_text_filter/auth_client0/result.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"description": "What is the capital of France?",
1515
"props": {
1616
"filter": "category ne 'excluded' and (oids/any(g:search.in(g, 'OID_X')) or groups/any(g:search.in(g, 'GROUP_Y, GROUP_Z')))",
17-
"search_image_embeddings": false,
17+
"search_image_embeddings": true,
1818
"search_text_embeddings": true,
1919
"top": 3,
2020
"use_query_rewriting": false,

0 commit comments

Comments
 (0)