-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sql_connectors): add unit tests for sql connectors
- Loading branch information
1 parent
1239987
commit 148d585
Showing
2 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -377,3 +377,44 @@ def test_load_direct_from_sqlite_schema(self, sqlite_schema): | |
assert mock_execute_query.call_args[0][0] == ( | ||
"SELECT email, first_name, timestamp FROM users ORDER BY created_at DESC LIMIT 100" | ||
) | ||
|
||
def test_load_without_schema_and_path(self, sample_schema): | ||
"""Test load by not providing a schema or path.""" | ||
with patch("os.path.exists", return_value=True), patch( | ||
"pandasai.data_loader.loader.DatasetLoader._read_csv_or_parquet" | ||
) as mock_read_csv_or_parquet, patch( | ||
"pandasai.data_loader.loader.DatasetLoader._apply_transformations" | ||
) as mock_apply_transformations: | ||
mock_read_csv_or_parquet.return_value = DataFrame( | ||
{"email": ["[email protected]"]} | ||
) | ||
mock_apply_transformations.return_value = DataFrame( | ||
{"email": ["[email protected]"]} | ||
) | ||
loader = DatasetLoader() | ||
|
||
with pytest.raises( | ||
ValueError, match="Either 'dataset_path' or 'schema' must be provided." | ||
): | ||
result = loader.load() | ||
|
||
def test_load_with_schema_and_path(self, sample_schema): | ||
"""Test load by providing both schema and path.""" | ||
with patch("os.path.exists", return_value=True), patch( | ||
"pandasai.data_loader.loader.DatasetLoader._read_csv_or_parquet" | ||
) as mock_read_csv_or_parquet, patch( | ||
"pandasai.data_loader.loader.DatasetLoader._apply_transformations" | ||
) as mock_apply_transformations: | ||
mock_read_csv_or_parquet.return_value = DataFrame( | ||
{"email": ["[email protected]"]} | ||
) | ||
mock_apply_transformations.return_value = DataFrame( | ||
{"email": ["[email protected]"]} | ||
) | ||
loader = DatasetLoader() | ||
|
||
with pytest.raises( | ||
ValueError, | ||
match="Provide only one of 'dataset_path' or 'schema', not both.", | ||
): | ||
result = loader.load("test/users", sample_schema) |