-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(DS-463): fix motherduck connector (#377)
* Fix duck base stager output file missing suffix * Fix motherduck uploader * version and changelog bump; motherduck fix * DuckDB base stager unit test * Fix imports
- Loading branch information
1 parent
667db4b
commit 485c4dc
Showing
6 changed files
with
85 additions
and
6 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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from pytest_mock import MockerFixture | ||
|
||
from unstructured_ingest.v2.interfaces import FileData | ||
from unstructured_ingest.v2.interfaces.file_data import SourceIdentifiers | ||
from unstructured_ingest.v2.interfaces.upload_stager import UploadStagerConfig | ||
from unstructured_ingest.v2.processes.connectors.duckdb.base import BaseDuckDBUploadStager | ||
|
||
|
||
@pytest.fixture | ||
def mock_instance() -> BaseDuckDBUploadStager: | ||
return BaseDuckDBUploadStager(UploadStagerConfig()) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("input_filepath", "output_filename", "expected"), | ||
[ | ||
( | ||
"/path/to/input_file.ndjson", | ||
"output_file.ndjson", | ||
"output_file.ndjson", | ||
), | ||
("input_file.txt", "output_file.json", "output_file.txt"), | ||
("/path/to/input_file.json", "output_file", "output_file.json"), | ||
], | ||
) | ||
def test_run_output_filename_suffix( | ||
mocker: MockerFixture, | ||
mock_instance: BaseDuckDBUploadStager, | ||
input_filepath: str, | ||
output_filename: str, | ||
expected: str, | ||
): | ||
output_dir = Path("/tmp/test/output_dir") | ||
|
||
# Mocks | ||
mock_get_data = mocker.patch( | ||
"unstructured_ingest.v2.processes.connectors.duckdb.base.get_data", | ||
return_value=[{"key": "value"}, {"key": "value2"}], | ||
) | ||
mock_conform_dict = mocker.patch.object( | ||
BaseDuckDBUploadStager, | ||
"conform_dict", | ||
side_effect=lambda element_dict, file_data: element_dict, | ||
) | ||
mock_get_output_path = mocker.patch.object( | ||
BaseDuckDBUploadStager, "get_output_path", return_value=output_dir / expected | ||
) | ||
mock_write_output = mocker.patch( | ||
"unstructured_ingest.v2.processes.connectors.duckdb.base.write_data", return_value=None | ||
) | ||
|
||
# Act | ||
result = mock_instance.run( | ||
elements_filepath=Path(input_filepath), | ||
file_data=FileData( | ||
identifier="test", | ||
connector_type="test", | ||
source_identifiers=SourceIdentifiers(filename=input_filepath, fullpath=input_filepath), | ||
), | ||
output_dir=output_dir, | ||
output_filename=output_filename, | ||
) | ||
|
||
# Assert | ||
mock_get_data.assert_called_once_with(path=Path(input_filepath)) | ||
assert mock_conform_dict.call_count == 2 | ||
mock_get_output_path.assert_called_once_with(output_filename=expected, output_dir=output_dir) | ||
mock_write_output.assert_called_once_with( | ||
path=output_dir / expected, data=[{"key": "value"}, {"key": "value2"}] | ||
) | ||
assert result.name == expected |
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.5.0-dev0" # pragma: no cover | ||
__version__ = "0.5.0-dev1" # pragma: no cover |
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