Skip to content

Commit

Permalink
ci: Test queries in natural language
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay-Lysenko committed Feb 24, 2024
1 parent e7196e4 commit c6c692b
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def resources() -> None:
"""Generate resources for test app."""
notes_dir = os.path.join(os.path.dirname(__file__), "notes")
resources_dir = os.path.join(os.path.dirname(__file__), "resources")
make_resources(notes_dir, resources_dir)
make_resources(notes_dir, resources_dir, stemmer_language='ru')
yield
rmtree(resources_dir)

Expand Down
42 changes: 42 additions & 0 deletions tests/notes/lorem_ipsum/lorem_ipsum.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,48 @@
"\n",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ut massa sit amet velit congue suscipit non vitae nunc. Duis mattis at nunc non pulvinar."
]
},
{
"cell_type": "markdown",
"id": "7254751d",
"metadata": {
"tags": [
"рыба"
]
},
"source": [
"## 1\n",
"\n",
"Идейные соображения высшего порядка, а также современная методология разработки позволяет выполнить важные задания по разработке глубокомысленных рассуждений. В частности, новая модель организационной деятельности прекрасно подходит для реализации прогресса профессионального сообщества. Господа, выбранный нами инновационный путь требует анализа соответствующих условий активизации."
]
},
{
"cell_type": "markdown",
"id": "ada2a786",
"metadata": {
"tags": [
"рыба"
]
},
"source": [
"## 2\n",
"\n",
"Учитывая ключевые сценарии поведения, перспективное планирование однозначно определяет каждого участника как способного принимать собственные решения касаемо кластеризации усилий. Сложно сказать, почему представители современных социальных резервов, которые представляют собой яркий пример континентально-европейского типа политической культуры, будут разоблачены. В рамках спецификации современных стандартов, диаграммы связей формируют глобальную экономическую сеть и при этом — представлены в исключительно положительном свете."
]
},
{
"cell_type": "markdown",
"id": "938b743f",
"metadata": {
"tags": [
"lorem_ipsum"
]
},
"source": [
"## Лорем ипсум\n",
"\n",
"Лорем ипсум долор сит амет. Съешь ещё этих мягких французских булок, да выпей чаю."
]
}
],
"metadata": {
Expand Down
132 changes: 121 additions & 11 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_info_page(test_client: flask.testing.FlaskClient) -> None:
"field, included_patterns",
[
("digits_and_letters", ["letters (4)", "digits (2)", "list (1)"]),
("lorem_ipsum", ["lorem_ipsum (1)", "tag"]),
("lorem_ipsum", ["lorem_ipsum (2)"]),
]
)
def test_field_page(
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"list AND letters",
"tags: list AND letters",
# `included_patterns`
[
'C', '<li><p><em>c</em></p></li>', '<li><p>\\(c\\)</p></li>'
Expand All @@ -174,7 +174,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"list AND digits",
"tags: list AND digits",
# `included_patterns`
[
"<h2>Ничего не найдено</h2>"
Expand All @@ -189,7 +189,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"list OR letters",
"tags: list OR letters",
# `included_patterns`
[
'<li><p><em>c</em></p></li>',
Expand All @@ -205,7 +205,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"list OR digits",
"tags: list OR digits",
# `included_patterns`
[
'<li><p><em>c</em></p></li>',
Expand All @@ -221,7 +221,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"NOT list",
"tags: NOT list",
# `included_patterns`
[
'<p>1</p>',
Expand All @@ -237,7 +237,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"NOT letters",
"tags: NOT letters",
# `included_patterns`
[
'<p>2</p>',
Expand All @@ -252,7 +252,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"(list AND letters) OR (digits AND letters)",
"tags: (list AND letters) OR (digits AND letters)",
# `included_patterns`
[
'<li><p><em>c</em></p></li>',
Expand All @@ -270,7 +270,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"(list AND letters) AND ((digits OR letters OR list) OR list)",
"tags: (list AND letters) AND ((digits OR letters OR list) OR list)",
# `included_patterns`
[
'<li><p><em>c</em></p></li>',
Expand All @@ -287,7 +287,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"digits OR NOT (letters AND NOT list)",
"tags: digits OR NOT (letters AND NOT list)",
# `included_patterns`
[
'<li><p><em>c</em></p></li>',
Expand All @@ -303,7 +303,7 @@ def test_tag_page(
# `field`
"digits_and_letters",
# `query`
"(list AND letters) AND ((digits OR letters OR list) OR lists)",
"tags: (list AND letters) AND ((digits OR letters OR list) OR lists)",
# `included_patterns`
[
'<h2>Запрос не может быть обработан</h2>',
Expand Down Expand Up @@ -333,3 +333,113 @@ def test_tag_query_page(
assert pattern in result
for pattern in absent_patterns:
assert pattern not in result


@pytest.mark.parametrize(
"field, query, included_patterns, absent_patterns",
[
(
# `field`
"lorem_ipsum",
# `query`
"в",
# `included_patterns`
[
TITLE_TEMPLATE.format(field='lorem_ipsum', title='1'),
TITLE_TEMPLATE.format(field='lorem_ipsum', title='2'),
],
# `absent_patterns`
[
TITLE_TEMPLATE.format(field='lorem_ipsum', title='Lorem Ipsum'),
'Лорем ипсум',
]
),
(
# `field`
"lorem_ipsum",
# `query`
"разработка",
# `included_patterns`
[
TITLE_TEMPLATE.format(field='lorem_ipsum', title='1'),
],
# `absent_patterns`
[
TITLE_TEMPLATE.format(field='lorem_ipsum', title='2'),
'Lorem Ipsum',
'Лорем ипсум',
]
),
]
)
def test_tf_idf_query_page(
test_client: flask.testing.FlaskClient,
field: str,
query: str,
included_patterns: list[str],
absent_patterns: list[str]
) -> None:
"""Test page with results of search by natural language query."""
result = test_client.post(f'/{field}/query', data={'query': query}).data.decode('utf-8')
assert "/" in result
assert "⌂" in result
assert "?" in result
for pattern in included_patterns:
assert pattern in result
for pattern in absent_patterns:
assert pattern not in result


@pytest.mark.parametrize(
"field, query, included_patterns, absent_patterns",
[
(
# `field`
"lorem_ipsum",
# `query`
"это tags: рыба",
# `included_patterns`
[
TITLE_TEMPLATE.format(field='lorem_ipsum', title='2'),
],
# `absent_patterns`
[
'Лорем ипсум',
]
),
(
# `field`
"lorem_ipsum",
# `query`
" tags: ",
# `included_patterns`
[
"<h2>Ничего не найдено</h2>",
'<p><span style="background-color: #f1ece8"> tags: </span></p>'
],
# `absent_patterns`
[
TITLE_TEMPLATE.format(field='lorem_ipsum', title='1'),
TITLE_TEMPLATE.format(field='lorem_ipsum', title='2'),
'Lorem Ipsum',
'Лорем ипсум',
]
),
]
)
def test_combined_query_page(
test_client: flask.testing.FlaskClient,
field: str,
query: str,
included_patterns: list[str],
absent_patterns: list[str]
) -> None:
"""Test page with results of combined search."""
result = test_client.post(f'/{field}/query', data={'query': query}).data.decode('utf-8')
assert "/" in result
assert "⌂" in result
assert "?" in result
for pattern in included_patterns:
assert pattern in result
for pattern in absent_patterns:
assert pattern not in result

0 comments on commit c6c692b

Please sign in to comment.