Skip to content

Commit 4d97a1c

Browse files
committed
fix: Update Gemini CLI tests to mock shutil.which for proper path detection
- Add shutil.which mocking to all lookup_normattiva_url tests - Update test_lookup_normattiva_url_cli_not_found to mock shutil.which returning None - Ensure tests pass in CI environment where Gemini CLI may not be installed
1 parent 36e6e70 commit 4d97a1c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

tests/test_convert.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ def test_lookup_normattiva_url_with_mock_success(self):
318318
mock_result.stdout = '{"response": "https://www.normattiva.it/uri-res/N2Ls?urn:nir:stato:legge:2018-12-30;205"}'
319319
mock_result.stderr = ""
320320

321-
with mock.patch('subprocess.run', return_value=mock_result):
321+
with mock.patch('subprocess.run', return_value=mock_result), \
322+
mock.patch('shutil.which', return_value='/usr/bin/gemini'):
322323
result = lookup_normattiva_url("legge stanca")
323324
self.assertEqual(result, "https://www.normattiva.it/uri-res/N2Ls?urn:nir:stato:legge:2018-12-30;205")
324325

@@ -331,7 +332,8 @@ def test_lookup_normattiva_url_no_url_found(self):
331332
mock_result.stdout = '{"response": "Non ho trovato corrispondenze per questa ricerca"}'
332333
mock_result.stderr = ""
333334

334-
with mock.patch('subprocess.run', return_value=mock_result):
335+
with mock.patch('subprocess.run', return_value=mock_result), \
336+
mock.patch('shutil.which', return_value='/usr/bin/gemini'):
335337
result = lookup_normattiva_url("legge inesistente")
336338
self.assertIsNone(result)
337339

@@ -344,15 +346,16 @@ def test_lookup_normattiva_url_gemini_error(self):
344346
mock_result.stdout = ""
345347
mock_result.stderr = "Error from Gemini"
346348

347-
with mock.patch('subprocess.run', return_value=mock_result):
349+
with mock.patch('subprocess.run', return_value=mock_result), \
350+
mock.patch('shutil.which', return_value='/usr/bin/gemini'):
348351
result = lookup_normattiva_url("test query")
349352
self.assertIsNone(result)
350353

351354
def test_lookup_normattiva_url_cli_not_found(self):
352355
"""Test when Gemini CLI is not installed"""
353356
import unittest.mock as mock
354357

355-
with mock.patch('subprocess.run', side_effect=FileNotFoundError):
358+
with mock.patch('shutil.which', return_value=None):
356359
result = lookup_normattiva_url("test query")
357360
self.assertIsNone(result)
358361

0 commit comments

Comments
 (0)