Skip to content

Commit

Permalink
Update test_parsers.py
Browse files Browse the repository at this point in the history
Defined `test_search_query_with_field_aliases` method in `TestFileDataQueryParser`
class for testing file query parser with delete queries. Also defined attributes
comprising parameters and results for the same.
  • Loading branch information
rahul4732saini committed Jul 15, 2024
1 parent 8b9e6fa commit 7c0faca
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_query/test_handlers/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ class TestFileDataQueryParser:
"* FROM '.' WHERE lineno BETWEEN (0, 100)",
]

search_query_with_field_aliases_test_params = [
"filename, data FROM .",
"filename, type, line FROM RELATIVE . WHERE type = '.py' AND line > 10",
"filename, filepath FROM ABSOLUTE . WHERE 'test' in data",
]

# The following are test results for the search query tests comprising sub-lists, each with
# a variable length where the first element of each of them signifies whether the path is
# absolute (True) or relative (False) whereas the last element in it is a list comprising
Expand All @@ -210,6 +216,12 @@ class TestFileDataQueryParser:
[False, list(constants.DATA_FIELDS)],
]

search_query_with_field_aliases_test_results = [
[False, ["name", "dataline"], ["filename", "data"]],
[False, ["name", "filetype", "dataline"], ["filename", "type", "line"]],
[True, ["name", "path"], ["filename", "filepath"]],
]

@pytest.mark.parametrize(
("subquery", "results"),
zip(search_query_test_params, search_query_test_results),
Expand All @@ -227,6 +239,26 @@ def test_search_query(self, subquery: str, results: list[Any]) -> None:

assert [field.field for field in search_query.fields] == fields

@pytest.mark.parametrize(
("subquery", "results"),
zip(
search_query_with_field_aliases_test_params,
search_query_with_field_aliases_test_results,
),
)
def test_search_query(self, subquery: str, results: list[Any]) -> None:
"""
Tests the file data query parser with search queries comprising field aliases.
"""

query: list[str] = tools.parse_query(subquery)
parser = FileDataQueryParser(query)

search_query: SearchQuery = examine_search_query(parser, results)
fields: list[str] = results[1]

assert [field.field for field in search_query.fields] == fields


class TestDirectoryQueryParser:
"""Tests the DirectoryQueryParser class"""
Expand Down

0 comments on commit 7c0faca

Please sign in to comment.