Skip to content

Commit 12a7e5e

Browse files
author
Gerit Wagner
committed
Merge branch 'main' into cli
2 parents 82c5475 + a45b43e commit 12a7e5e

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed

search_query/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TokenTypes(Enum):
2828
SEARCH_TERM = "SEARCH_TERM"
2929
PARENTHESIS_OPEN = "PARENTHESIS_OPEN"
3030
PARENTHESIS_CLOSED = "PARENTHESIS_CLOSED"
31+
UNKNOWN = "UNKNOWN"
3132

3233

3334
@dataclass

search_query/linter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import search_query.parser
88
from search_query.constants import Colors
99
from search_query.constants import ExitCodes
10-
from search_query.search_file import SearchFile
10+
from search_query.search_file import load_search_file
1111
from search_query.utils import format_query_string_pos
1212

1313

@@ -29,7 +29,7 @@ def pre_commit_hook() -> int:
2929
file_path = sys.argv[1]
3030

3131
try:
32-
search_file = SearchFile(file_path)
32+
search_file = load_search_file(file_path)
3333
platform = search_query.parser.get_platform(search_file.platform)
3434
except Exception as e: # pylint: disable=broad-except
3535
print(e)
@@ -45,7 +45,7 @@ def pre_commit_hook() -> int:
4545
linter_messages = run_linter(
4646
search_file.search_string,
4747
platform=search_file.platform,
48-
search_field_general=search_file.search_field_general,
48+
search_field_general=search_file.search_field,
4949
)
5050

5151
if linter_messages:

search_query/not_query.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from search_query.query import Query
77
from search_query.query import SearchField
88

9+
# pylint: disable=duplicate-code
10+
911

1012
class NotQuery(Query):
1113
"""NOT Query"""

search_query/parser_ebsco.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def tokenize(self) -> None:
159159
validator.check_search_field_general(strict=self.mode)
160160

161161
previous_token_type = None
162-
token_type = None
162+
token_type = TokenTypes.UNKNOWN
163163

164164
for match in re.finditer(self.pattern, self.query_str):
165165
value = match.group()

search_query/parser_validation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from search_query.constants import QueryErrorCode
1010
from search_query.constants import TokenTypes
1111

12+
if typing.TYPE_CHECKING:
13+
import search_query.parser_ebsco
14+
1215

1316
# Could indeed be a general Validator class
1417
class QueryStringValidator:
@@ -141,7 +144,7 @@ def filter_search_field(self, strict: bool) -> None:
141144

142145
def validate_token_position(
143146
self,
144-
token_type: str,
147+
token_type: TokenTypes,
145148
previous_token_type: typing.Optional[TokenTypes],
146149
position: typing.Optional[tuple[int, int]],
147150
) -> None:

search_query/search_file.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(
2121
authors: Optional[list[dict]] = None,
2222
record_info: Optional[dict] = None,
2323
date: Optional[dict] = None,
24+
search_field: Optional[str] = None,
2425
filepath: Optional[str | Path] = None,
2526
**kwargs: dict,
2627
) -> None:
@@ -29,6 +30,7 @@ def __init__(
2930
self.authors = authors or []
3031
self.record_info = record_info or {}
3132
self.date = date or {}
33+
self.search_field = search_field or ""
3234
self._filepath = Path(filepath) if filepath else None
3335

3436
for key, value in kwargs.items():
@@ -101,4 +103,4 @@ def load_search_file(filepath: str | Path) -> SearchFile:
101103
platform=data.pop("platform"),
102104
filepath=path,
103105
**data,
104-
)
106+
)

test/test_search_file.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
"""Tests for SearchFile parser."""
33
from __future__ import annotations
44

5-
from search_query.search_file import SearchFile
5+
from search_query.search_file import load_search_file
66

77

88
def test_search_history_file_parser() -> None:
99
"""Test SearchFile parser."""
1010

11-
file_path = "test/search_history_file_1.json"
12-
13-
result = SearchFile(file_path)
11+
result = load_search_file("test/search_history_file_1.json")
1412

1513
assert hasattr(result, "parsed")

0 commit comments

Comments
 (0)