Skip to content

Commit

Permalink
Update test_parsers.py
Browse files Browse the repository at this point in the history
Defined `test_file_search_query_parser_with_size_fields` method in
`TestFileQueryParser` class for testing file query parser with
search query comprising size fields.
rahul4732saini committed Jul 14, 2024
1 parent 6aa8b0d commit 668bbdb
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_query/test_handlers/test_parsers.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,12 @@ class TestFileQueryParser:
"* FROM '.' WHERE atime >= '2024-02-20'",
]

file_search_query_with_size_fields_test_params = [
"size, size[B] FROM . WHERE type = '.py' AND size[KiB] > 512",
"size[b],size,size[TiB] FROM ABSOLUTE .",
"size[MB], size[GB], size[B] FROM . WHERE size[MiB] > 10",
]

# The following list comprises results for the file search query test comprising sub-lists,
# each with a length of 2. The first element of each sub-list signifies whether the path is
# absolute (True) or relative (False) whereas the second element is a list comprising names
@@ -37,6 +43,12 @@ class TestFileQueryParser:
[False, list(constants.FILE_FIELDS)],
]

file_search_query_with_size_fields_test_results = [
[False, ["B", "B"], ["size", "size[B]"]],
[True, ["b", "B", "TiB"], ["size[b]", "size", "size[TiB]"]],
[False, ["MB", "GB", "B"], ["size[MB]", "size[GB]", "size[B]"]],
]

@pytest.mark.parametrize(
("subquery", "results"),
zip(file_search_query_test_params, file_search_query_test_results),
@@ -58,3 +70,31 @@ def test_file_search_query_parser(self, subquery, results) -> None:
assert search_query.path == path
assert [field.field for field in search_query.fields] == columns
assert search_query.columns == columns

@pytest.mark.parametrize(
("subquery", "results"),
zip(
file_search_query_with_size_fields_test_params,
file_search_query_with_size_fields_test_results,
),
)
def test_file_search_query_parser_with_size_fields(self, subquery, results) -> None:
"""
Tests the file query parser with search queries comprising size fields.
"""

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

parser = FileQueryParser(query, "search")
search_query: SearchQuery = parser.parse_query()

path: Path = Path(".")
units: list[str] = results[1]
columns: list[str] = results[2]

if results[0]:
path = path.resolve()

assert search_query.path == path
assert [field.unit for field in search_query.fields] == units
assert search_query.columns == columns

0 comments on commit 668bbdb

Please sign in to comment.