-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_search_config.py
More file actions
57 lines (39 loc) · 1.64 KB
/
Copy pathtest_search_config.py
File metadata and controls
57 lines (39 loc) · 1.64 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Tests for search stopword configuration."""
import pytest
from rockgarden.config import Config, SearchConfig, SiteConfig
from rockgarden.output.builder import build_site
def test_stopwords_default():
config = SearchConfig()
assert config.stopwords == "default"
def test_stopwords_none():
config = SearchConfig(stopwords="none")
assert config.stopwords == "none"
def test_stopwords_custom_list():
config = SearchConfig(stopwords=["the", "a", "an"])
assert config.stopwords == ["the", "a", "an"]
def test_stopwords_invalid_string():
with pytest.raises(ValueError, match="stopwords must be"):
SearchConfig(stopwords="custom")
def _build_and_get_html(tmp_path, stopwords="default"):
source = tmp_path / "content"
source.mkdir()
(source / "page.md").write_text("# Hello\n\nSome content.\n")
output = tmp_path / "output"
config = Config(
site=SiteConfig(source=source, output=output),
search=SearchConfig(stopwords=stopwords),
)
build_site(config, source, output)
return (output / "page" / "index.html").read_text()
def test_default_stopwords_no_pipeline_change(tmp_path):
html = _build_and_get_html(tmp_path, "default")
assert "lunr.stopWordFilter" not in html
assert "generateStopWordFilter" not in html
def test_none_stopwords_removes_filter(tmp_path):
html = _build_and_get_html(tmp_path, "none")
assert "this.pipeline.remove(lunr.stopWordFilter)" in html
def test_custom_stopwords_sets_filter(tmp_path):
html = _build_and_get_html(tmp_path, ["the", "a"])
assert "generateStopWordFilter" in html
assert '"the"' in html
assert '"a"' in html