jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/377047 )
Change subject: site_tests.py: Avoid race conditions in test_pagetemplates and
test_pagelinks
......................................................................
site_tests.py: Avoid race conditions in test_pagetemplates and test_pagelinks
Instead of comparing the results of two generator calls that might not match,
either because of random functions used in the page or simultaneous user
edits, just make sure that the correct parameters are assigned to the
underlying Request.
In addition, for namespace-restricted generators confirm that the results are
all from the expected namespace.
Bug: T92856
Bug: T153501
Bug: T169649
Change-Id: I775729eb7153168140dbc832e0ae15790dd66779
---
M tests/site_tests.py
1 file changed, 36 insertions(+), 22 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 1a7f2b8..74d3b11 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -551,13 +551,23 @@
def test_pagetemplates(self):
"""Test Site.pagetemplates."""
- pagetemplates_all = set(self.site.pagetemplates(self.mainpage))
- pagetemplates_ns_10 = set(self.site.pagetemplates(self.mainpage,
namespaces=[10]))
+ tl_gen = self.site.pagetemplates(self.mainpage)
+ expected_params = {
+ 'titles': [self.mainpage.title()],
+ 'prop': ['info', 'imageinfo',
'categoryinfo'],
+ 'inprop': ['protection'],
+ 'iiprop': ['timestamp', 'user', 'comment',
'url', 'size',
+ 'sha1', 'metadata'],
+ 'generator': ['templates'], 'action':
['query'],
+ 'indexpageids': [True], 'continue': [True]}
+ self.assertEqual(tl_gen.request._params, expected_params)
- for te in pagetemplates_all:
+ tl_gen = self.site.pagetemplates(self.mainpage, namespaces=[10])
+ expected_params['gtlnamespace'] = [10]
+ self.assertEqual(tl_gen.request._params, expected_params)
+ for te in tl_gen:
self.assertIsInstance(te, pywikibot.Page)
-
- self.assertLessEqual(pagetemplates_ns_10, pagetemplates_all)
+ self.assertEqual(te.namespace(), 10)
def test_pagelanglinks(self):
"""Test Site.pagelanglinks."""
@@ -571,23 +581,27 @@
def test_pagelinks(self):
"""Test Site.pagelinks."""
- links = set(self.site.pagelinks(self.mainpage))
- for pl in links:
- self.assertIsInstance(pl, pywikibot.Page)
- # test links arguments
- # TODO: There have been build failures because the following assertion
- # wasn't true. Bug: T92856
- # Example:
https://travis-ci.org/wikimedia/pywikibot-core/jobs/54552081#L505
- namespace_links = set(self.site.pagelinks(self.mainpage, namespaces=[0, 1]))
- if namespace_links - links:
- unittest_print(
- 'FAILURE wrt T92856:\nSym. difference: "{0}"'.format(
- '", "'.join(
- '{0}(a){1}'.format(link.namespace()espace(),
- link.title(withNamespace=False))
- for link in namespace_links ^ links)))
- self.assertCountEqual(
- set(self.site.pagelinks(self.mainpage, namespaces=[0, 1])) - links, [])
+ links_gen = self.site.pagelinks(self.mainpage)
+ gen_params = links_gen.request._params.copy()
+ expected_params = {
+ 'redirects': [False],
+ 'prop': ['info', 'imageinfo',
'categoryinfo'],
+ 'inprop': ['protection'],
+ 'iiprop': ['timestamp', 'user', 'comment',
'url', 'size',
+ 'sha1', 'metadata'], 'generator':
['links'],
+ 'action': ['query'], 'indexpageids': [True],
'continue': [True]}
+ if 'pageids' in gen_params:
+ expected_params['pageids'] = [str(self.mainpage.pageid)]
+ else:
+ expected_params['titles'] = [self.mainpage.title()]
+ self.assertEqual(gen_params, expected_params)
+
+ links_gen = self.site.pagelinks(self.mainpage, namespaces=[0, 1])
+ gen_params = links_gen.request._params.copy()
+ expected_params['gplnamespace'] = [0, 1]
+ self.assertEqual(gen_params, expected_params)
+ self.assertPagesInNamespaces(links_gen, set([0, 1]))
+
for target in self.site.preloadpages(
self.site.pagelinks(self.mainpage, follow_redirects=True, total=5)):
self.assertIsInstance(target, pywikibot.Page)
--
To view, visit
https://gerrit.wikimedia.org/r/377047
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I775729eb7153168140dbc832e0ae15790dd66779
Gerrit-PatchSet: 11
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>