tests: added tests (#250)
This commit is contained in:
42
tests/chunkers/test_text.py
Normal file
42
tests/chunkers/test_text.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# ruff: noqa: E501
|
||||
|
||||
import unittest
|
||||
|
||||
from embedchain.chunkers.text import TextChunker
|
||||
|
||||
|
||||
class TestTextChunker(unittest.TestCase):
|
||||
def test_chunks(self):
|
||||
"""
|
||||
Test the chunks generated by TextChunker.
|
||||
# TODO: Not a very precise test.
|
||||
"""
|
||||
chunker_config = {
|
||||
"chunk_size": 10,
|
||||
"chunk_overlap": 0,
|
||||
"length_function": len,
|
||||
}
|
||||
chunker = TextChunker(config=chunker_config)
|
||||
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
|
||||
|
||||
result = chunker.create_chunks(MockLoader(), text)
|
||||
|
||||
documents = result["documents"]
|
||||
|
||||
self.assertGreaterEqual(len(documents), 5)
|
||||
|
||||
# Additional test cases can be added to cover different scenarios
|
||||
|
||||
|
||||
class MockLoader:
|
||||
def load_data(self, src):
|
||||
"""
|
||||
Mock loader that returns a list of data dictionaries.
|
||||
Adjust this method to return different data for testing.
|
||||
"""
|
||||
return [
|
||||
{
|
||||
"content": src,
|
||||
"meta_data": {"url": "none"},
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user