File size: 754 Bytes
e4f9cbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Test the Substring Search signal."""

import pytest
from pydantic import ValidationError

from ..schema import field
from .splitters.text_splitter_test_utils import text_to_expected_spans
from .substring_search import SubstringSignal


def test_substring_fields() -> None:
  signal = SubstringSignal(query='test')
  assert signal.fields() == field(fields=['string_span'])


def test_query_is_required() -> None:
  with pytest.raises(ValidationError):
    SubstringSignal()


def test_compute() -> None:
  signal = SubstringSignal(query='test')

  text = 'The word TEST shows up 3 times, teST and test'
  spans = list(signal.compute([text]))

  expected_spans = text_to_expected_spans(text, ['TEST', 'teST', 'test'])
  assert [expected_spans] == spans