jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
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(-)

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(

To view, visit change 459370. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I3438eecad5197b1d7a2707fbf1ee10894fd6ead8
Gerrit-Change-Number: 459370
Gerrit-PatchSet: 3
Gerrit-Owner: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)