File: test_trimmer.py

package info (click to toggle)
python-lunr 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,644 kB
  • sloc: python: 3,811; javascript: 114; makefile: 60
file content (32 lines) | stat: -rw-r--r-- 967 bytes parent folder | download | duplicates (2)
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
30
31
32
import pytest

from lunr.trimmer import trimmer
from lunr.token import Token
from lunr.pipeline import Pipeline


class TestTrimmer:
    def test_latin_characters(self):
        token = Token("hello")
        assert str(trimmer(token)) == str(token)

    @pytest.mark.parametrize(
        "description, string, expected",
        [
            ("full stop", "hello.", "hello"),
            ("inner apostrophe", "it's", "it's"),
            ("trailing apostrophe", "james'", "james"),
            ("exclamation mark", "stop!", "stop"),
            ("comma", "first,", "first"),
            ("brackets", "[tag]", "tag"),
        ],
    )
    def test_punctuation(self, description, string, expected):
        token = Token(string)
        trimmed = str(trimmer(token))

        assert trimmed == expected

    def test_is_a_registered_pipeline_function(self):
        assert trimmer.label == "trimmer"
        assert Pipeline.registered_functions["trimmer"] == trimmer