Skip to content

Commit 8b9e6fa

Browse files
Update test_parsers.py
Defined `test_search_query` method in `TestFileDataQueryParser` class for testing file data query parser with search queries. Also defined attributes comprising parameters and results for the same.
1 parent afecbca commit 8b9e6fa

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/test_query/test_handlers/test_parsers.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,47 @@ def test_delete_query(self, subquery: str, is_absolute: bool) -> None:
187187
examine_delete_query(parser, is_absolute)
188188

189189

190+
class TestFileDataQueryParser:
191+
"""Tests the FileDataQueryParser class."""
192+
193+
search_query_test_params = [
194+
"* FROM .",
195+
"name, path, dataline FROM ABSOLUTE '.'",
196+
"path, lineno, dataline FROM RELATIVE . WHERE type = '.py'",
197+
"* FROM '.' WHERE lineno BETWEEN (0, 100)",
198+
]
199+
200+
# The following are test results for the search query tests comprising sub-lists, each with
201+
# a variable length where the first element of each of them signifies whether the path is
202+
# absolute (True) or relative (False) whereas the last element in it is a list comprising
203+
# names of the search fields. All the remaining objects within the list are test specific
204+
# and may differ in different tests.
205+
206+
search_query_test_results = [
207+
[False, list(constants.DATA_FIELDS)],
208+
[True, ["name", "path", "dataline"]],
209+
[False, ["path", "lineno", "dataline"]],
210+
[False, list(constants.DATA_FIELDS)],
211+
]
212+
213+
@pytest.mark.parametrize(
214+
("subquery", "results"),
215+
zip(search_query_test_params, search_query_test_results),
216+
)
217+
def test_search_query(self, subquery: str, results: list[Any]) -> None:
218+
"""
219+
Tests the file data query parser with search queries.
220+
"""
221+
222+
query: list[str] = tools.parse_query(subquery)
223+
parser = FileDataQueryParser(query)
224+
225+
search_query: SearchQuery = examine_search_query(parser, results)
226+
fields: list[str] = results[1]
227+
228+
assert [field.field for field in search_query.fields] == fields
229+
230+
190231
class TestDirectoryQueryParser:
191232
"""Tests the DirectoryQueryParser class"""
192233

0 commit comments

Comments
 (0)