Files
wehub-resource-sync da6a09ff09
Auto Bump and Release / auto-bump-and-release (push) Has been cancelled
style-check / pre-commit (push) Has been cancelled
unit-test / unit testing with python (push) Has been cancelled
unit-test / unit testing with python 3.10 (push) Has been cancelled
unit-test / unit testing with python 3.11 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:49 +08:00

33 lines
971 B
Python

import pytest
from kotaemon.base import Document
from kotaemon.parsers import RegexExtractor
@pytest.fixture
def regex_extractor():
return RegexExtractor(
pattern=r"\d+", output_map={"1": "One", "2": "Two", "3": "Three"}
)
def test_run_document(regex_extractor):
document = Document(text="This is a test. 1 2 3")
extracted_document = regex_extractor(document)[0]
assert extracted_document.text == "One"
assert extracted_document.matches == ["One", "Two", "Three"]
def test_run_raw(regex_extractor):
output = regex_extractor("This is a test. 123")[0]
assert output.text == "123"
assert output.matches == ["123"]
def test_run_batch_raw(regex_extractor):
output = regex_extractor(["This is a test. 123", "456"])
extracted_text = [each.text for each in output]
extracted_matches = [each.matches for each in output]
assert extracted_text == ["123", "456"]
assert extracted_matches == [["123"], ["456"]]