Use patch.object to satisfy type checker
This commit is contained in:
parent
99a200c9d2
commit
21a8f52893
1 changed files with 5 additions and 4 deletions
|
|
@ -59,6 +59,7 @@ async def test_local_chunker(qa_corpus: list[dict[str, str]]):
|
||||||
async def test_local_chunker_runs_off_event_loop_thread():
|
async def test_local_chunker_runs_off_event_loop_thread():
|
||||||
"""Chunking is CPU-bound; verify it runs in a worker thread."""
|
"""Chunking is CPU-bound; verify it runs in a worker thread."""
|
||||||
import threading
|
import threading
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
chunker = DoclingLocalChunker()
|
chunker = DoclingLocalChunker()
|
||||||
event_loop_thread = threading.current_thread()
|
event_loop_thread = threading.current_thread()
|
||||||
|
|
@ -66,15 +67,15 @@ async def test_local_chunker_runs_off_event_loop_thread():
|
||||||
|
|
||||||
original = chunker._chunk_sync
|
original = chunker._chunk_sync
|
||||||
|
|
||||||
def recording_chunk_sync(document):
|
def recording_chunk_sync(self, document):
|
||||||
called_from.append(threading.current_thread())
|
called_from.append(threading.current_thread())
|
||||||
return original(document)
|
return original(document)
|
||||||
|
|
||||||
chunker._chunk_sync = recording_chunk_sync
|
|
||||||
|
|
||||||
converter = get_converter(Config)
|
converter = get_converter(Config)
|
||||||
doc = await converter.convert_text("# Hello\n\nWorld", name="test.md")
|
doc = await converter.convert_text("# Hello\n\nWorld", name="test.md")
|
||||||
await chunker.chunk(doc)
|
|
||||||
|
with patch.object(DoclingLocalChunker, "_chunk_sync", recording_chunk_sync):
|
||||||
|
await chunker.chunk(doc)
|
||||||
|
|
||||||
assert called_from, "_chunk_sync was never called"
|
assert called_from, "_chunk_sync was never called"
|
||||||
assert called_from[0] is not event_loop_thread, (
|
assert called_from[0] is not event_loop_thread, (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue