Пример #1
0
def test__calc_flex_warns_if_flex_longer_than_query(
        nlp: Language, searcher: FuzzySearcher) -> None:
    """It provides UserWarning if flex > len(query)."""
    query = nlp("Test query")
    with pytest.warns(FlexWarning):
        flex = searcher._calc_flex(query, 5)
    assert flex == 2
Пример #2
0
def test__calc_flex_warns_if_flex_less_than_0(nlp: Language,
                                              searcher: FuzzySearcher) -> None:
    """It provides UserWarning if flex < 0."""
    query = nlp("Test query")
    with pytest.warns(FlexWarning):
        flex = searcher._calc_flex(query, -1)
    assert flex == 0
Пример #3
0
def test__calc_flex_passes_through_valid_value(
        nlp: Language, searcher: FuzzySearcher) -> None:
    """It passes through a valid flex value (<= len(query))."""
    query = nlp("Test query")
    assert searcher._calc_flex(query, 0) == 0
Пример #4
0
def test__calc_flex_with_min(nlp: Language, searcher: FuzzySearcher) -> None:
    """It returns 0 if set with "min"."""
    query = nlp("Test query")
    assert searcher._calc_flex(query, "min") == 0
Пример #5
0
def test__calc_flex_with_max(nlp: Language, searcher: FuzzySearcher) -> None:
    """It returns len(query) if set with "max"."""
    query = nlp("Test query two")
    assert searcher._calc_flex(query, "max") == 3
Пример #6
0
def test__calc_flex_with_default(nlp: Language,
                                 searcher: FuzzySearcher) -> None:
    """It returns len(query) // 2 if set with "default"."""
    query = nlp("Test query")
    assert searcher._calc_flex(query, "default") == 1
Пример #7
0
def test__calc_flex_raises_error_if_non_valid_value(
        nlp: Language, searcher: FuzzySearcher) -> None:
    """It raises TypeError if flex is not an int or "default"."""
    query = nlp("Test query.")
    with pytest.raises(TypeError):
        searcher._calc_flex(query, None)  # type: ignore