Skip to content

Commit

Permalink
fix: windows test formatting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
scaliseraoul committed Jan 16, 2025
1 parent 02f5cf8 commit 5e38b30
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 24 deletions.
4 changes: 2 additions & 2 deletions tests/unit_tests/dataframe/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_load_schema_file_not_found(self):
with pytest.raises(FileNotFoundError):
loader._load_schema()

def test_read_csv_or_parquet_parquet(self, sample_schema):
def test_read_parquet(self, sample_schema):
loader = DatasetLoader()
loader.schema = sample_schema

Expand All @@ -167,7 +167,7 @@ def test_read_csv_or_parquet_parquet(self, sample_schema):
assert isinstance(result, pd.DataFrame)
assert result.equals(mock_df)

def test_read_csv_or_parquet_csv(self, sample_schema):
def test_read_csv(self, sample_schema):
loader = DatasetLoader()
loader.schema = sample_schema

Expand Down
82 changes: 60 additions & 22 deletions tests/unit_tests/test_pandasai_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_load_valid_dataset(
self, mock_exists, mock_find_project_root, mock_dataset_loader
):
"""Test loading a valid dataset."""
mock_find_project_root.return_value = "/mock/root"
mock_find_project_root.return_value = os.path.join("mock", "root")
mock_dataset_loader.load.return_value = MagicMock(name="DataFrame")
mock_exists.return_value = True
pandasai._dataset_loader = mock_dataset_loader
Expand Down Expand Up @@ -277,18 +277,21 @@ def test_create_valid_dataset_no_params(
self, mock_makedirs, mock_find_project_root, sample_df
):
"""Test creating a dataset with valid inputs."""
mock_find_project_root.return_value = "/mock/root"
mock_find_project_root.return_value = os.path.join("mock", "root")

with patch("builtins.open", mock_open()) as mock_file, patch.object(
sample_df, "to_parquet"
) as mock_to_parquet, patch(
"pandasai.find_project_root", return_value="/mock/root"
"pandasai.find_project_root", return_value=os.path.join("mock", "root")
):
result = pandasai.create("test-org/test-dataset", sample_df)

# Check if directories were created
mock_makedirs.assert_called_once_with(
"/mock/root/datasets/test-org/test-dataset", exist_ok=True
os.path.join(
os.path.join("mock", "root", "datasets", "test-org", "test-dataset")
),
exist_ok=True,
)

# Check if DataFrame was saved
Expand All @@ -298,7 +301,15 @@ def test_create_valid_dataset_no_params(

# Check if schema was saved
mock_file.assert_called_once_with(
"/mock/root/datasets/test-org/test-dataset/schema.yaml", "w"
os.path.join(
"mock",
"root",
"datasets",
"test-org",
"test-dataset",
"schema.yaml",
),
"w",
)

# Check returned DataFrame
Expand Down Expand Up @@ -341,7 +352,7 @@ def test_create_empty_dataset_name(self, sample_df):
@patch("pandasai.helpers.path.find_project_root")
def test_create_existing_dataset(self, mock_find_project_root, sample_df):
"""Test creating a dataset that already exists."""
mock_find_project_root.return_value = "/mock/root"
mock_find_project_root.return_value = os.path.join("mock", "root")

with patch("os.path.exists") as mock_exists:
# Mock that both directory and schema file exist
Expand All @@ -358,7 +369,7 @@ def test_create_existing_directory_no_dataset(
self, mock_find_project_root, sample_df
):
"""Test creating a dataset in an existing directory but without existing dataset files."""
mock_find_project_root.return_value = "/mock/root"
mock_find_project_root.return_value = os.path.join("mock", "root")

def mock_exists_side_effect(path):
# Return True for directory, False for schema and data files
Expand All @@ -369,7 +380,7 @@ def mock_exists_side_effect(path):
) as mock_makedirs, patch(
"builtins.open", mock_open()
) as mock_file, patch.object(sample_df, "to_parquet") as mock_to_parquet, patch(
"pandasai.find_project_root", return_value="/mock/root"
"pandasai.find_project_root", return_value=os.path.join("mock", "root")
):
result = pandasai.create("test-org/test-dataset", sample_df)

Expand All @@ -386,18 +397,19 @@ def test_create_valid_dataset_with_name(
self, mock_makedirs, mock_find_project_root, sample_df
):
"""Test creating a dataset with valid inputs."""
mock_find_project_root.return_value = "/mock/root"
mock_find_project_root.return_value = os.path.join("mock", "root")

with patch("builtins.open", mock_open()) as mock_file, patch.object(
sample_df, "to_parquet"
) as mock_to_parquet, patch(
"pandasai.find_project_root", return_value="/mock/root"
"pandasai.find_project_root", return_value=os.path.join("mock", "root")
):
result = pandasai.create("test-org/test-dataset", sample_df, "test_name")

# Check if directories were created
mock_makedirs.assert_called_once_with(
"/mock/root/datasets/test-org/test-dataset", exist_ok=True
os.path.join("mock", "root", "datasets", "test-org", "test-dataset"),
exist_ok=True,
)

# Check if DataFrame was saved
Expand All @@ -407,7 +419,15 @@ def test_create_valid_dataset_with_name(

# Check if schema was saved
mock_file.assert_called_once_with(
"/mock/root/datasets/test-org/test-dataset/schema.yaml", "w"
os.path.join(
"mock",
"root",
"datasets",
"test-org",
"test-dataset",
"schema.yaml",
),
"w",
)

# Check returned DataFrame
Expand All @@ -422,20 +442,21 @@ def test_create_valid_dataset_with_description(
self, mock_makedirs, mock_find_project_root, sample_df
):
"""Test creating a dataset with valid inputs."""
mock_find_project_root.return_value = "/mock/root"
mock_find_project_root.return_value = os.path.join("mock", "root")

with patch("builtins.open", mock_open()) as mock_file, patch.object(
sample_df, "to_parquet"
) as mock_to_parquet, patch(
"pandasai.find_project_root", return_value="/mock/root"
"pandasai.find_project_root", return_value=os.path.join("mock", "root")
):
result = pandasai.create(
"test-org/test-dataset", sample_df, description="test_description"
)

# Check if directories were created
mock_makedirs.assert_called_once_with(
"/mock/root/datasets/test-org/test-dataset", exist_ok=True
os.path.join("mock", "root", "datasets", "test-org", "test-dataset"),
exist_ok=True,
)

# Check if DataFrame was saved
Expand All @@ -445,7 +466,15 @@ def test_create_valid_dataset_with_description(

# Check if schema was saved
mock_file.assert_called_once_with(
"/mock/root/datasets/test-org/test-dataset/schema.yaml", "w"
os.path.join(
"mock",
"root",
"datasets",
"test-org",
"test-dataset",
"schema.yaml",
),
"w",
)

# Check returned DataFrame
Expand All @@ -460,12 +489,12 @@ def test_create_valid_dataset_with_columns(
self, mock_makedirs, mock_find_project_root, sample_df
):
"""Test creating a dataset with valid inputs."""
mock_find_project_root.return_value = "/mock/root"
mock_find_project_root.return_value = os.path.join("mock", "root")

with patch("builtins.open", mock_open()) as mock_file, patch.object(
sample_df, "to_parquet"
) as mock_to_parquet, patch(
"pandasai.find_project_root", return_value="/mock/root"
"pandasai.find_project_root", return_value=os.path.join("mock", "root")
):
columns_dict = [{"name": "a"}, {"name": "b"}]
result = pandasai.create(
Expand All @@ -474,7 +503,8 @@ def test_create_valid_dataset_with_columns(

# Check if directories were created
mock_makedirs.assert_called_once_with(
"/mock/root/datasets/test-org/test-dataset", exist_ok=True
os.path.join("mock", "root", "datasets", "test-org", "test-dataset"),
exist_ok=True,
)

# Check if DataFrame was saved
Expand All @@ -484,7 +514,15 @@ def test_create_valid_dataset_with_columns(

# Check if schema was saved
mock_file.assert_called_once_with(
"/mock/root/datasets/test-org/test-dataset/schema.yaml", "w"
os.path.join(
"mock",
"root",
"datasets",
"test-org",
"test-dataset",
"schema.yaml",
),
"w",
)

# Check returned DataFrame
Expand All @@ -502,12 +540,12 @@ def test_create_dataset_wrong_columns(
self, mock_makedirs, mock_find_project_root, sample_df
):
"""Test creating a dataset with valid inputs."""
mock_find_project_root.return_value = "/mock/root"
mock_find_project_root.return_value = os.path.join("mock", "root")

with patch("builtins.open", mock_open()) as mock_file, patch.object(
sample_df, "to_parquet"
) as mock_to_parquet, patch(
"pandasai.find_project_root", return_value="/mock/root"
"pandasai.find_project_root", return_value=os.path.join("mock", "root")
):
columns_dict = [{"no-name": "a"}, {"name": "b"}]

Expand Down

0 comments on commit 5e38b30

Please sign in to comment.