Skip to content

Commit

Permalink
test(cli): update the tests for multiword search - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Jan 30, 2025
1 parent 0cd3e4e commit 0b471e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions pikaur/search_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from .exceptions import AURError, SysExit
from .i18n import translate
from .logging_extras import create_logger
from .pacman import PackageDB, get_pkg_id, refresh_pkg_db_if_needed
from .pikaprint import print_error, print_stderr
from .pikatypes import AURPackageInfo
Expand All @@ -29,6 +30,9 @@
SamePackageTypeT = TypeVar("SamePackageTypeT", AURPackageInfo, pyalpm.Package)


logger = create_logger("search")


def filter_search_results(
results: "dict[str, list[SamePackageTypeT]]",
query: str,
Expand Down Expand Up @@ -73,6 +77,7 @@ def package_search_thread_aur( # pylint: disable=too-many-branches
queries: list[str],
) -> list[AURPackageInfo]:
args = parse_args()
logger.debug("queries: {}", queries)
result = {}
if queries:
use_as_filters: list[str] = []
Expand Down
29 changes: 14 additions & 15 deletions pikaur_test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def test_search_multiword_too_small_query_error(self):
self.assertEqual(len(result_aur_too_many), 0)

def test_search_multiword_too_small_query_filter(self):
common_query = "mailman"
specific_query = "u"
common_result = "listadmin"
specific_result = "mailman3-public-inbox"
common_query = "fool"
specific_query = "python"
common_result = "fool"
specific_result = "python-foolscap"

result_for_one_query = pikaur(f"-Ssq --aur {common_query}").stdout.splitlines()
self.assertIn(specific_result, result_for_one_query)
Expand All @@ -83,27 +83,26 @@ def test_search_multiword_too_small_query_filter(self):
self.assertNotIn(common_result, result_all)

def test_search_multiword_too_small_query_filter_namesonly(self):
common_query = "mailman"
specific_query = "d"
specific_result = "listadmin"
specific_query_names_only = "u"
specific_result_names_only = "mailman3-public-inbox"
common_query = "fool"
specific_query = "python"
specific_result = "python-ippserver"
specific_result_names_only = "python-foolscap"

result_all = pikaur(
f"-Ssq --aur {common_query} {specific_query}",
).stdout.splitlines()
self.assertIn(specific_result, result_all)

result_namesonly_w = pikaur(
result_namesonly_1 = pikaur(
f"-Ssq --aur {common_query} {specific_query} --namesonly",
).stdout.splitlines()
self.assertEqual(len(result_namesonly_w), 0)
self.assertNotIn(specific_result, result_namesonly_1)

result_namesonly_x = pikaur(
f"-Ssq --aur {common_query} {specific_query_names_only} --namesonly",
result_namesonly_2 = pikaur(
f"-Ssq --aur {common_query} {specific_query} --namesonly",
).stdout.splitlines()
self.assertNotIn(specific_result, result_namesonly_x)
self.assertIn(specific_result_names_only, result_namesonly_x)
self.assertNotIn(specific_result, result_namesonly_2)
self.assertIn(specific_result_names_only, result_namesonly_2)

def test_list(self):
result_all = pikaur("-Ssq").stdout.splitlines()
Expand Down

0 comments on commit 0b471e6

Please sign in to comment.