Skip to content

Commit 451553e

Browse files
Sid MohanSid Mohan
Sid Mohan
authored and
Sid Mohan
committed
precommit
1 parent 7b4a175 commit 451553e

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

tests/test_client.py

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,103 @@
1+
from unittest.mock import MagicMock, patch
2+
13
import pytest
24
from typer.testing import CliRunner
3-
from unittest.mock import patch, MagicMock
5+
46
from datafog.client import app
57

68
runner = CliRunner()
79

10+
811
@pytest.fixture
912
def mock_datafog():
10-
with patch('datafog.client.DataFog') as mock:
13+
with patch("datafog.client.DataFog") as mock:
1114
yield mock
1215

16+
1317
def test_scan_image_no_urls():
1418
result = runner.invoke(app, ["scan-image"])
1519
assert result.exit_code == 1
1620
assert "No image URLs or file paths provided" in result.stdout
1721

22+
1823
@pytest.mark.asyncio
1924
async def test_scan_image_success(mock_datafog):
2025
mock_instance = mock_datafog.return_value
2126
mock_instance.run_ocr_pipeline.return_value = ["Mocked result"]
22-
23-
with patch('datafog.client.asyncio.run', new=lambda x: x):
27+
28+
with patch("datafog.client.asyncio.run", new=lambda x: x):
2429
result = runner.invoke(app, ["scan-image", "http://example.com/image.jpg"])
25-
30+
2631
assert result.exit_code == 0
2732
assert "OCR Pipeline Results: ['Mocked result']" in result.stdout
28-
mock_instance.run_ocr_pipeline.assert_called_once_with(image_urls=["http://example.com/image.jpg"])
33+
mock_instance.run_ocr_pipeline.assert_called_once_with(
34+
image_urls=["http://example.com/image.jpg"]
35+
)
36+
2937

3038
def test_scan_text_no_texts():
3139
result = runner.invoke(app, ["scan-text"])
3240
assert result.exit_code == 1
3341
assert "No texts provided" in result.stdout
3442

43+
3544
@pytest.mark.asyncio
3645
async def test_scan_text_success(mock_datafog):
3746
mock_instance = mock_datafog.return_value
3847
mock_instance.run_text_pipeline.return_value = ["Mocked result"]
39-
40-
with patch('datafog.client.asyncio.run', new=lambda x: x):
48+
49+
with patch("datafog.client.asyncio.run", new=lambda x: x):
4150
result = runner.invoke(app, ["scan-text", "Sample text"])
42-
51+
4352
assert result.exit_code == 0
4453
assert "Text Pipeline Results: ['Mocked result']" in result.stdout
4554
mock_instance.run_text_pipeline.assert_called_once_with(str_list=["Sample text"])
4655

56+
4757
def test_health():
4858
result = runner.invoke(app, ["health"])
4959
assert result.exit_code == 0
5060
assert "DataFog is running" in result.stdout
5161

52-
@patch('datafog.client.get_config')
62+
63+
@patch("datafog.client.get_config")
5364
def test_show_config(mock_get_config):
5465
mock_get_config.return_value = {"key": "value"}
5566
result = runner.invoke(app, ["show-config"])
5667
assert result.exit_code == 0
5768
assert "{'key': 'value'}" in result.stdout
5869

59-
@patch('datafog.client.SpacyAnnotator.download_model')
70+
71+
@patch("datafog.client.SpacyAnnotator.download_model")
6072
def test_download_model(mock_download_model):
6173
result = runner.invoke(app, ["download-model", "en_core_web_sm"])
6274
assert result.exit_code == 0
6375
assert "Model en_core_web_sm downloaded" in result.stdout
6476
mock_download_model.assert_called_once_with("en_core_web_sm")
6577

66-
@patch('datafog.client.SpacyAnnotator')
78+
79+
@patch("datafog.client.SpacyAnnotator")
6780
def test_show_spacy_model_directory(mock_spacy_annotator):
6881
mock_instance = mock_spacy_annotator.return_value
6982
mock_instance.show_model_path.return_value = "/path/to/model"
7083
result = runner.invoke(app, ["show-spacy-model-directory", "en_core_web_sm"])
7184
assert result.exit_code == 0
7285
assert "/path/to/model" in result.stdout
7386

74-
@patch('datafog.client.SpacyAnnotator')
87+
88+
@patch("datafog.client.SpacyAnnotator")
7589
def test_list_spacy_models(mock_spacy_annotator):
7690
mock_instance = mock_spacy_annotator.return_value
7791
mock_instance.list_models.return_value = ["model1", "model2"]
7892
result = runner.invoke(app, ["list-spacy-models"])
7993
assert result.exit_code == 0
8094
assert "['model1', 'model2']" in result.stdout
8195

82-
@patch('datafog.client.SpacyAnnotator')
96+
97+
@patch("datafog.client.SpacyAnnotator")
8398
def test_list_entities(mock_spacy_annotator):
8499
mock_instance = mock_spacy_annotator.return_value
85100
mock_instance.list_entities.return_value = ["PERSON", "ORG"]
86101
result = runner.invoke(app, ["list-entities"])
87102
assert result.exit_code == 0
88-
assert "['PERSON', 'ORG']" in result.stdout
103+
assert "['PERSON', 'ORG']" in result.stdout

0 commit comments

Comments
 (0)