jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/459370 )
Change subject: SearchTestCase.test_search_where_title: Don't look for the searched word ......................................................................
SearchTestCase.test_search_where_title: Don't look for the searched word
Don't look for the searched word in the results. Matches do not always contain the exact searched term. See T203886#4569832.
Just test that params are correct and that the results are page objects from the requested namespace.
pywikibot.site.APISite.search: Checking for the family is not the best way to learn about the search engine params. Change the `isinstance(self.family, WikimediaFamily)` condition to `self.has_extension('CirrusSearch')` which hopefully is more accurate.
Bug: T203886 Change-Id: I3438eecad5197b1d7a2707fbf1ee10894fd6ead8 --- M pywikibot/site.py M tests/site_tests.py 2 files changed, 19 insertions(+), 10 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index 8a15511..304dcdc 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -67,7 +67,6 @@ UnknownSite, UserBlocked, ) -from pywikibot.family import WikimediaFamily from pywikibot.throttle import Throttle from pywikibot.tools import ( compute_file_hash, @@ -4802,7 +4801,7 @@ if where not in where_types: raise Error("search: unrecognized 'where' value: %s" % where) if where in ('title', 'titles'): - if isinstance(self.family, WikimediaFamily): + if self.has_extension('CirrusSearch'): # 'title' search was disabled, use intitle instead searchstring = 'intitle:' + searchstring issue_deprecation_warning( diff --git a/tests/site_tests.py b/tests/site_tests.py index ee7b90e..d676b11 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -1585,17 +1585,27 @@ @suppress_warnings("where='title' is deprecated", DeprecationWarning) def test_search_where_title(self): """Test site.search() method with 'where' parameter set to title.""" + search_gen = self.site.search( + 'wiki', namespaces=0, total=10, get_redirects=True, where='title') + expected_params = { + 'prop': ['info', 'imageinfo', 'categoryinfo'], + 'inprop': ['protection'], + 'iiprop': [ + 'timestamp', 'user', 'comment', 'url', 'size', 'sha1', + 'metadata'], + 'iilimit': ['max'], 'generator': ['search'], 'action': ['query'], + 'indexpageids': [True], 'continue': [True], 'gsrnamespace': [0]} + if self.site.has_extension('CirrusSearch'): + expected_params.update({ + 'gsrsearch': ['intitle:wiki'], 'gsrwhat': [None]}) + else: + expected_params.update({ + 'gsrsearch': ['wiki'], 'gsrwhat': ['title']}) + self.assertEqual(search_gen.request._params, expected_params) try: - for hit in self.site.search('wiki', namespaces=0, total=10, - get_redirects=True, where='title'): + for hit in search_gen: self.assertIsInstance(hit, pywikibot.Page) self.assertEqual(hit.namespace(), 0) - if 'wiki' not in hit.title().lower(): - self.assertTrue( - any('wiki' in r.title().lower() - for r in hit.getReferences(filter_redirects=True)), - "'wiki' neither found in '{0}'.lower() " - 'nor in its redirects'.format(hit.title())) except pywikibot.data.api.APIError as e: if e.code in ('search-title-disabled', 'gsrsearch-title-disabled'): raise unittest.SkipTest(