Skip to content

Commit 9ac8dab

Browse files
authored
Merge pull request #160 from enoch3712/140-strategy-not-passed-raise-exception
Add splitter checker on process
2 parents cd8e195 + 3d6f930 commit 9ac8dab

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

extract_thinker/process.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def load_file(self, file):
199199

200200
def split(self, classifications: List[Classification], strategy: SplittingStrategy = SplittingStrategy.EAGER):
201201
"""Split the document into groups based on classifications."""
202+
if self.splitter is None:
203+
raise ValueError("No splitter loaded. Please load a splitter using load_splitter() before splitting.")
204+
202205
self.split_classifications = classifications
203206

204207
document_loader = self.get_document_loader(self.file_path)

tests/test_process.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from tests.models.driver_license import DriverLicense
88
from extract_thinker.image_splitter import ImageSplitter
99
from extract_thinker.text_splitter import TextSplitter
10+
import pytest
1011

1112
# Setup environment and paths
1213
load_dotenv()
@@ -154,5 +155,11 @@ def test_eager_splitting_strategy_vision():
154155
assert result[1].license_number.replace(" ", "") in ["0123456789", "123456789"]
155156
#assert result[1].license_number.replace(" ", "") == "0123456789" #small vision bug from the model, refuses to return 0 on driver license
156157

157-
if __name__ == "__main__":
158-
test_eager_splitting_strategy()
158+
def test_split_requires_splitter():
159+
"""Test that attempting to split without loading a splitter first raises an error"""
160+
# Arrange
161+
process = Process()
162+
163+
# Act & Assert
164+
with pytest.raises(ValueError, match="No splitter loaded"):
165+
process.split([]) # Empty classifications list is fine for this test

0 commit comments

Comments
 (0)