forked from khoj-ai/khoj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_word_filter.py
84 lines (59 loc) · 2.38 KB
/
test_word_filter.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Application Packages
from khoj.search_filter.word_filter import WordFilter
from khoj.utils.rawconfig import Entry
# Test
# ----------------------------------------------------------------------------------------------------
def test_no_word_filter():
# Arrange
word_filter = WordFilter()
q_with_no_filter = "head tail"
# Act
can_filter = word_filter.can_filter(q_with_no_filter)
filter_terms = word_filter.get_filter_terms(q_with_no_filter)
# Assert
assert can_filter == False
assert filter_terms == []
# ----------------------------------------------------------------------------------------------------
def test_word_exclude_filter():
# Arrange
word_filter = WordFilter()
q_with_exclude_filter = 'head -"exclude_word" tail'
# Act
can_filter = word_filter.can_filter(q_with_exclude_filter)
# Assert
assert can_filter == True
# ----------------------------------------------------------------------------------------------------
def test_word_include_filter():
# Arrange
word_filter = WordFilter()
query_with_include_filter = 'head +"include_word" tail'
# Act
can_filter = word_filter.can_filter(query_with_include_filter)
# Assert
assert can_filter == True
# ----------------------------------------------------------------------------------------------------
def test_word_include_and_exclude_filter():
# Arrange
word_filter = WordFilter()
query_with_include_and_exclude_filter = 'head +"include_word" -"exclude_word" tail'
# Act
can_filter = word_filter.can_filter(query_with_include_and_exclude_filter)
# Assert
assert can_filter == True
# ----------------------------------------------------------------------------------------------------
def test_get_word_filter_terms():
# Arrange
word_filter = WordFilter()
query_with_include_and_exclude_filter = 'head +"include_word" -"exclude_word" tail'
# Act
filter_terms = word_filter.get_filter_terms(query_with_include_and_exclude_filter)
# Assert
assert filter_terms == ["+include_word", "-exclude_word"]
def arrange_content():
entries = [
Entry(compiled="", raw="Minimal Entry"),
Entry(compiled="", raw="Entry with exclude_word"),
Entry(compiled="", raw="Entry with include_word"),
Entry(compiled="", raw="Entry with include_word and exclude_word"),
]
return entries