[Refactor] Update dependencies and loaders (#1062)

This commit is contained in:
Sidharth Mohanty
2023-12-30 20:52:20 +05:30
committed by GitHub
parent a304ded500
commit aee5bbb44b
8 changed files with 350 additions and 294 deletions

View File

@@ -1,21 +1,15 @@
import pytest
from llama_hub.readwise.base import Document
from embedchain.loaders.gmail import GmailLoader
@pytest.fixture
def mock_quopri(mocker):
return mocker.patch("embedchain.loaders.gmail.quopri.decodestring", return_value=b"your_test_decoded_string")
@pytest.fixture
def mock_beautifulsoup(mocker):
return mocker.patch("embedchain.loaders.gmail.BeautifulSoup", return_value=mocker.MagicMock())
@pytest.fixture
def gmail_loader(mock_quopri, mock_beautifulsoup):
def gmail_loader(mock_beautifulsoup):
return GmailLoader()
@@ -33,7 +27,12 @@ def test_load_data(gmail_loader, mocker):
"id": "your_test_id",
"snippet": "your_test_snippet",
}
mock_gmail_reader_instance.load_data.return_value = [Document(text=text, extra_info=metadata)]
mock_gmail_reader_instance.load_data.return_value = [
{
"text": text,
"extra_info": metadata,
}
]
with mocker.patch("os.path.isfile", return_value=True):
response_data = gmail_loader.load_data("your_query")

View File

@@ -1,7 +1,6 @@
import hashlib
import pytest
from llama_index.readers.schema.base import Document
from embedchain.loaders.json import JSONLoader
@@ -42,8 +41,15 @@ def test_load_data_url(mocker):
mocker.patch("os.path.isfile", return_value=False)
mocker.patch(
"llama_hub.jsondata.base.JSONDataReader.load_data",
return_value=[Document(text="content1"), Document(text="content2")],
"embedchain.loaders.json.JSONReader.load_data",
return_value=[
{
"text": "content1",
},
{
"text": "content2",
},
],
)
mock_response = mocker.Mock()
@@ -98,8 +104,15 @@ def test_load_data_from_json_string(mocker):
mocker.patch("os.path.isfile", return_value=False)
mocker.patch(
"llama_hub.jsondata.base.JSONDataReader.load_data",
return_value=[Document(text="content1"), Document(text="content2")],
"embedchain.loaders.json.JSONReader.load_data",
return_value=[
{
"text": "content1",
},
{
"text": "content2",
},
],
)
result = JSONLoader.load_data(content)

View File

@@ -28,7 +28,7 @@ def test_load_data(notion_loader):
mock_page.text = mock_text
mock_documents = [mock_page]
with patch("embedchain.loaders.notion.NotionPageReader") as mock_reader:
with patch("embedchain.loaders.notion.NotionPageLoader") as mock_reader:
mock_reader.return_value.load_data.return_value = mock_documents
result = notion_loader.load_data(source)