Skip to content

Commit

Permalink
update tests and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed May 27, 2024
1 parent 4be6d13 commit a32ac42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/gypsum_client/search_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __invert__(self):

def search_metadata_text(
path: str,
query: Union[str, GypsumSearchClause],
query: Union[str, List[str], GypsumSearchClause],
latest: bool = True,
include_metadata: bool = True,
) -> List[Dict]:
Expand Down Expand Up @@ -169,8 +169,10 @@ def search_metadata_text(

if cond:
stmt += " WHERE " + " AND ".join(cond)
cursor = conn.execute(stmt, params)
else:
cursor = conn.execute(stmt)

cursor = conn.execute(stmt, params)
results = [dict(row) for row in cursor.fetchall()]
if include_metadata:
for result in results:
Expand Down Expand Up @@ -207,7 +209,7 @@ def define_text_query(


def search_metadata_text_filter(
query: Union[str, GypsumSearchClause], pid_name: str = "paths.pid"
query: Union[str, List[str], GypsumSearchClause], pid_name: str = "paths.pid"
) -> Dict[str, Union[str, List]]:
query = sanitize_query(query)

Expand All @@ -220,7 +222,7 @@ def search_metadata_text_filter(


def sanitize_query(
query: Union[str, GypsumSearchClause],
query: Union[str, List[str], GypsumSearchClause],
) -> Optional[GypsumSearchClause]:
if isinstance(query, list):
if len(query) > 1:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def test_search_metadata_text_text_searches():
assert len(result) == 1
assert result[0]["path"] == "mikoto.txt"

result1 = search_metadata_text(
sqlite_path, "mikoto", include_metadata=False, latest=False
)
assert len(result1) == 1
assert result1[0]["path"] == "mikoto.txt"

result = search_metadata_text(
sqlite_path, ["kuroko"], include_metadata=False, latest=False
)
Expand Down

0 comments on commit a32ac42

Please sign in to comment.