1
1
import os
2
2
from io import BytesIO
3
- from unittest .mock import Mock , mock_open , patch
3
+ from unittest .mock import Mock , PropertyMock , mock_open , patch
4
4
from zipfile import ZipFile
5
5
6
6
import pandas as pd
7
7
import pytest
8
8
9
+ from pandasai .config import ConfigManager
9
10
from pandasai .data_loader .semantic_layer_schema import (
10
11
Column ,
11
12
SemanticLayerSchema ,
12
13
Source ,
13
14
)
14
15
from pandasai .dataframe .base import DataFrame
15
16
from pandasai .exceptions import DatasetNotFound , PandaAIApiKeyError
17
+ from pandasai .helpers .path import find_project_root
16
18
17
19
18
20
@pytest .fixture
@@ -47,7 +49,7 @@ def mock_schema():
47
49
48
50
def test_pull_success (mock_env , sample_df , mock_zip_content , mock_schema , tmp_path ):
49
51
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"
51
53
) as mock_root , patch (
52
54
"pandasai.DatasetLoader.create_loader_from_path"
53
55
) 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):
103
105
104
106
def test_pull_file_exists (mock_env , sample_df , mock_zip_content , mock_schema , tmp_path ):
105
107
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"
107
109
) as mock_root , patch (
108
110
"pandasai.DatasetLoader.create_loader_from_path"
109
111
) 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
117
119
mock_root .return_value = str (tmp_path )
118
120
mock_exists .return_value = True
119
121
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 ()
129
138
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