forked from langchain-ai/langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename Daxa to Pebblo, Aggregate size calculation, Initial unit tests (…
…langchain-ai#12) * 1. Calculate the Size of the page content * 2. Rename Daxa to Pebblo * unit test initial Signed-off-by: Rahul Tripathi <[email protected]> * Update test_imports.py * Rename Daxa to Pebblo --------- Signed-off-by: Rahul Tripathi <[email protected]> Co-authored-by: Rahul Tripathi <[email protected]>
- Loading branch information
Showing
7 changed files
with
116 additions
and
13 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
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,3 @@ | ||
column1,column2,column3 | ||
value1,value2,value3 | ||
value4,value5,value6 |
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
81 changes: 81 additions & 0 deletions
81
libs/community/tests/unit_tests/document_loaders/test_pebblo.py
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,81 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from langchain_core.documents import Document | ||
from langchain_community.document_loaders import CSVLoader | ||
|
||
EXAMPLE_DOCS_DIRECTORY = str(Path(__file__).parent.parent / "examples/") | ||
|
||
def test_pebblo_import() -> None: | ||
"""Test that the Pebblo safe loader can be imported.""" | ||
from langchain_community.document_loaders import PebbloSafeLoader # noqa: F401 | ||
|
||
def test_empty_filebased_loader() -> None: | ||
"""Test basic file based csv loader.""" | ||
# Setup | ||
from langchain_community.document_loaders import PebbloSafeLoader | ||
file_path = os.path.join(EXAMPLE_DOCS_DIRECTORY, "test_empty.csv") | ||
expected_docs: list = [] | ||
|
||
# Exercise | ||
loader = PebbloSafeLoader( | ||
CSVLoader(file_path=file_path), | ||
"dummy_app_name", "dummy_owner","dummy_description" | ||
) | ||
result = loader.load() | ||
|
||
# Assert | ||
assert result == expected_docs | ||
|
||
def test_csv_loader_load_valid_data() -> None: | ||
# Setup | ||
from langchain_community.document_loaders import PebbloSafeLoader | ||
file_path = os.path.join(EXAMPLE_DOCS_DIRECTORY, "test_nominal.csv") | ||
expected_docs = [ | ||
Document( | ||
page_content="column1: value1\ncolumn2: value2\ncolumn3: value3", | ||
metadata={"source": file_path, "row": 0}, | ||
), | ||
Document( | ||
page_content="column1: value4\ncolumn2: value5\ncolumn3: value6", | ||
metadata={"source": file_path, "row": 1}, | ||
), | ||
] | ||
|
||
# Exercise | ||
loader = PebbloSafeLoader( | ||
CSVLoader(file_path=file_path), | ||
"dummy_app_name", "dummy_owner","dummy_description" | ||
) | ||
result = loader.load() | ||
|
||
# Assert | ||
assert result == expected_docs | ||
|
||
def test_csv_lazy_load(): | ||
# Setup | ||
from langchain_community.document_loaders import PebbloSafeLoader | ||
file_path = os.path.join(EXAMPLE_DOCS_DIRECTORY, "test_nominal.csv") | ||
expected_docs = [ | ||
Document( | ||
page_content="column1: value1\ncolumn2: value2\ncolumn3: value3", | ||
metadata={"source": file_path, "row": 0}, | ||
), | ||
Document( | ||
page_content="column1: value4\ncolumn2: value5\ncolumn3: value6", | ||
metadata={"source": file_path, "row": 1}, | ||
), | ||
] | ||
|
||
# Exercise | ||
loader = PebbloSafeLoader( | ||
CSVLoader(file_path=file_path), | ||
"dummy_app_name", "dummy_owner","dummy_description" | ||
) | ||
|
||
result = [] | ||
for doc in loader.lazy_load(): | ||
result.extend(doc) | ||
|
||
# Assert | ||
assert result == expected_docs |