Skip to content

Commit 936c6f0

Browse files
committed
test: fix tests for pull
1 parent b0305ef commit 936c6f0

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

tests/unit_tests/dataframe/test_pull.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import os
22
from io import BytesIO
3-
from unittest.mock import Mock, mock_open, patch
3+
from unittest.mock import Mock, PropertyMock, mock_open, patch
44
from zipfile import ZipFile
55

66
import pandas as pd
77
import pytest
88

9+
from pandasai.config import ConfigManager
910
from pandasai.data_loader.semantic_layer_schema import (
1011
Column,
1112
SemanticLayerSchema,
1213
Source,
1314
)
1415
from pandasai.dataframe.base import DataFrame
1516
from pandasai.exceptions import DatasetNotFound, PandaAIApiKeyError
17+
from pandasai.helpers.path import find_project_root
1618

1719

1820
@pytest.fixture
@@ -47,7 +49,7 @@ def mock_schema():
4749

4850
def test_pull_success(mock_env, sample_df, mock_zip_content, mock_schema, tmp_path):
4951
with patch("pandasai.dataframe.base.get_pandaai_session") as mock_session, patch(
50-
"pandasai.dataframe.base.find_project_root"
52+
"pandasai.helpers.path.find_project_root"
5153
) as mock_root, patch(
5254
"pandasai.DatasetLoader.create_loader_from_path"
5355
) as mock_loader, patch("builtins.open", mock_open()) as mock_file:
@@ -103,7 +105,7 @@ def test_pull_api_error(mock_env, sample_df, mock_schema):
103105

104106
def test_pull_file_exists(mock_env, sample_df, mock_zip_content, mock_schema, tmp_path):
105107
with patch("pandasai.dataframe.base.get_pandaai_session") as mock_session, patch(
106-
"pandasai.dataframe.base.find_project_root"
108+
"pandasai.helpers.path.find_project_root"
107109
) as mock_root, patch(
108110
"pandasai.DatasetLoader.create_loader_from_path"
109111
) as mock_loader, patch("builtins.open", mock_open()) as mock_file, patch(
@@ -117,20 +119,24 @@ def test_pull_file_exists(mock_env, sample_df, mock_zip_content, mock_schema, tm
117119
mock_root.return_value = str(tmp_path)
118120
mock_exists.return_value = True
119121

120-
mock_loader_instance = Mock()
121-
mock_loader_instance.load.return_value = DataFrame(
122-
sample_df, schema=mock_schema
123-
)
124-
mock_loader.return_value = mock_loader_instance
125-
126-
# Create DataFrame instance and call pull
127-
df = DataFrame(sample_df, path="test/path", schema=mock_schema)
128-
df.pull()
122+
# Setup FileManager mock
123+
mock_file_manager = Mock()
124+
mock_file_manager.exists.return_value = True
125+
mock_file_manager.base_path = os.path.join(str(tmp_path), "datasets")
126+
mock_config = Mock()
127+
mock_config.file_manager = mock_file_manager
128+
with patch.object(ConfigManager, "get", return_value=mock_config):
129+
mock_loader_instance = Mock()
130+
mock_loader_instance.load.return_value = DataFrame(
131+
sample_df, schema=mock_schema
132+
)
133+
mock_loader.return_value = mock_loader_instance
134+
135+
# Create DataFrame instance and call pull
136+
df = DataFrame(sample_df, path="test/path", schema=mock_schema)
137+
df.pull()
129138

130-
# Verify directory creation
131-
mock_makedirs.assert_called_with(
132-
os.path.dirname(
133-
os.path.join(str(tmp_path), "datasets", "test/path", "test.csv")
134-
),
135-
exist_ok=True,
136-
)
139+
# Verify directory creation
140+
mock_file_manager.mkdir.assert_called_with(
141+
os.path.dirname("test/path/test.csv")
142+
)

0 commit comments

Comments
 (0)