jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Test unconnected page generators
......................................................................
[IMPROV] Test unconnected page generators
Add tests to the newly introduced generators from dff802ba.
Change-Id: I7204ab8da0feab9e9211c36ad9d5e2dcabd96eb0
---
M tests/pagegenerators_tests.py
M tests/site_tests.py
2 files changed, 36 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index dccd20c..ce51bfc 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -905,6 +905,31 @@
"user", "bot"]:
self.assertIn(key, rcinfo.keys())
+
+class TestUnconnectedPageGenerator(DefaultSiteTestCase):
+
+ """Test UnconnectedPageGenerator."""
+
+ def test_unconnected_with_repo(self):
+ """Test that the ItemPage returned raises NoPage."""
+ if not self.site.data_repository():
+ raise unittest.SkipTest('Site is not using a Wikibase repository')
+ cnt = 0
+ for page in pagegenerators.UnconnectedPageGenerator(self.site, total=5):
+ self.assertRaises(pywikibot.NoPage, pywikibot.ItemPage.fromPage,
+ page)
+ cnt += 1
+ self.assertLessEqual(cnt, 5)
+
+ def test_unconnected_without_repo(self):
+ """Test that it raises a ValueError on sites without repository."""
+ if self.site.data_repository():
+ raise unittest.SkipTest('Site is using a Wikibase repository')
+ with self.assertRaises(ValueError):
+ for page in pagegenerators.UnconnectedPageGenerator(self.site,
+ total=5):
+ assert False # this shouldn't be reached
+
if __name__ == "__main__":
try:
unittest.main()
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 0b9c726..5e3db05 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -811,6 +811,17 @@
self.assertNotIn(page.protection()['edit'][0], invalid_levels)
self.assertLessEqual(len(pages), 10)
+ def test_unconnected(self):
+ """Test that the ItemPage returned raises NoPage."""
+ if not self.site.data_repository():
+ raise unittest.SkipTest('Site is not using a Wikibase repository')
+ cnt = 0
+ for page in self.site.unconnected_pages(total=5):
+ self.assertRaises(pywikibot.NoPage, pywikibot.ItemPage.fromPage,
+ page)
+ cnt += 1
+ self.assertLessEqual(cnt, 5)
+
class TestImageUsage(DefaultSiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/230394
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7204ab8da0feab9e9211c36ad9d5e2dcabd96eb0
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] ParamInfo: Separate fetch with initialize
......................................................................
[IMPROV] ParamInfo: Separate fetch with initialize
The `fetch()` method had an `_init` parameter to fetch modules without
initializing first. This separates the method into `_fetch()` and `fetch()`.
This also changes the way `_init()` works, as it now just skips it, when it's
already initialized. It also removes the private `__inited` attribute.
Change-Id: Id35db6b4c78145ae47513d8509748dcab6b89b37
---
M pywikibot/data/api.py
M tests/dry_api_tests.py
2 files changed, 35 insertions(+), 30 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index d864abf..7d08ea0 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -207,7 +207,6 @@
self.preloaded_modules = self.init_modules
if preloaded_modules:
self.preloaded_modules |= set(preloaded_modules)
- self.__inited = False
self.modules_only_mode = modules_only_mode
if self.modules_only_mode:
@@ -232,6 +231,9 @@
self._modules[name] = modules
def _init(self):
+ assert ('query' in self._modules) is ('main' in self._paraminfo)
+ if 'query' in self._modules:
+ return
_mw_ver = MediaWikiVersion(self.site.version())
if _mw_ver < MediaWikiVersion('1.15'):
@@ -250,7 +252,7 @@
if _mw_ver > MediaWikiVersion('1.26') or _mw_ver < MediaWikiVersion('1.19'):
self.preloaded_modules |= set(['query'])
- self.fetch(self.preloaded_modules, _init=True)
+ self._fetch(self.preloaded_modules)
# paraminfo 'mainmodule' was added 1.15
assert('main' in self._paraminfo)
@@ -277,7 +279,7 @@
if 'query' not in self._modules:
assert 'query' not in self._paraminfo
- self.fetch(set(['query']), _init=True)
+ self._fetch(set(['query']))
assert 'query' in self._modules
_reused_module_names = self._action_modules & self._modules['query']
@@ -288,8 +290,6 @@
if _reused_module_names > set(['tokens']):
warn('Unexpected overlap between action and query submodules: %s'
% (_reused_module_names - set(['tokens'])), UserWarning)
-
- self.__inited = True
def _emulate_pageset(self):
"""Emulate the pageset module, which existed in MW 1.15-1.24."""
@@ -535,7 +535,7 @@
self._emulate_pageset()
- def fetch(self, modules, _init=False):
+ def fetch(self, modules):
"""
Fetch paraminfo for multiple modules.
@@ -543,6 +543,29 @@
Use __getitem__ to cause an exception if a module does not exist.
@param modules: API modules to load
+ @type modules: iterable or str
+ @rtype: NoneType
+ """
+ if 'main' not in self._paraminfo:
+ # The first request should be 'paraminfo', so that
+ # query modules can be prefixed with 'query+'
+ self._init()
+
+ if 'query' in self._modules:
+ # It does fetch() while initializing, and this method can't be
+ # called before it's initialized.
+ modules = self._normalize_modules(modules)
+ elif self._action_modules:
+ # At least we do know the valid action modules and require a subset
+ assert not modules - self._action_modules - self.root_modules
+
+ self._fetch(modules)
+
+ def _fetch(self, modules):
+ """
+ Fetch paraminfo for multiple modules without initializing beforehand.
+
+ @param modules: API modules to load and which haven't been loaded yet.
@type modules: set
@rtype: NoneType
"""
@@ -555,20 +578,11 @@
del failed_modules[:]
yield batch
- # The first request should be 'paraminfo', so that
- # query modules can be prefixed with 'query+'
- # If _init is True, dont call _init().
- if 'paraminfo' not in self._paraminfo and not _init:
- self._init()
-
- if self.__inited:
- modules = self._normalize_modules(modules)
-
modules = modules - set(self._paraminfo.keys())
if not modules:
return
- assert 'query' in self._modules or _init
+ assert 'query' in self._modules or 'paraminfo' not in self._paraminfo
if MediaWikiVersion(self.site.version()) < MediaWikiVersion("1.12"):
# When the help is parsed, all paraminfo should already be loaded
@@ -593,13 +607,12 @@
if self.modules_only_mode and 'pageset' in module_batch:
pywikibot.debug('paraminfo fetch: removed pageset', _logger)
module_batch.remove('pageset')
- if 'query' not in self._paraminfo:
- pywikibot.debug('paraminfo batch: added query', _logger)
- module_batch.append('query')
# If this occurred during initialisation,
# also record it in the preloaded_modules.
# (at least so tests know an extra load was intentional)
- if not self.__inited:
+ if 'query' not in self._paraminfo:
+ pywikibot.debug('paraminfo batch: added query', _logger)
+ module_batch.append('query')
self.preloaded_modules |= set(['query'])
params = {
@@ -742,8 +755,7 @@
@return: The modules converted into a module paths
@rtype: set
"""
- if not self.__inited:
- self._init()
+ self._init()
return self._normalize_modules(modules)
@classmethod
@@ -901,8 +913,6 @@
# As soon as modules() is removed, module_paths and _module_set can be
# combined, so don't add any code between these two methods.
def _module_set(self, path):
- if not self.__inited:
- self._init()
# Load the submodules of all action modules available
self.fetch(self.action_modules)
modules = set(self.action_modules)
@@ -915,8 +925,7 @@
@property
def action_modules(self):
"""Set of all action modules."""
- if not self.__inited:
- self._init()
+ self._init()
return self._action_modules
@property
@@ -935,8 +944,6 @@
@return: The names or paths of the submodules.
@rtype: set
"""
- if not self.__inited:
- self._init()
if name not in self._modules:
self.fetch([name])
submodules = self._modules[name]
diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py
index b674f72..5266256 100644
--- a/tests/dry_api_tests.py
+++ b/tests/dry_api_tests.py
@@ -335,8 +335,6 @@
site._paraminfo._paraminfo[mod] = {}
site._paraminfo._action_modules = frozenset(['edit'])
site._paraminfo._modules = {'query': frozenset(['info'])}
- # TODO: remove access of this private member of ParamInfo
- site._paraminfo._ParamInfo__inited = True
def test_new_format(self):
pi = self.get_site()._paraminfo
--
To view, visit https://gerrit.wikimedia.org/r/230081
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id35db6b4c78145ae47513d8509748dcab6b89b37
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: English Wikipedia is not supported
......................................................................
English Wikipedia is not supported
The templates in the 'en' configuration were originally intended to
support Portuguese Wikipedia, not English Wikipedia.
https://mediawiki.org/wiki/Special:Code/pywikipedia/5104
The templates have been deleted from Portuguese Wikipedia.
Change-Id: I5192407a188e88d7ccd43188a9d6d4a423db7901
---
M scripts/unusedfiles.py
1 file changed, 0 insertions(+), 2 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index 36bd97a..472b81a 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -34,12 +34,10 @@
}
template_to_the_image = {
- 'en': u'{{subst:No-use2}}',
'it': u'{{immagine orfana}}',
'fa': u'{{تصاویر بدون استفاده}}',
}
template_to_the_user = {
- 'en': u'\n\n{{img-sem-uso|%(title)s}}',
'fa': u'\n\n{{جا:اخطار به کاربر برای تصاویر بدون استفاده|%(title)s}}--~~~~',
'it': u'\n\n{{Utente:Filbot/Immagine orfana}}',
}
--
To view, visit https://gerrit.wikimedia.org/r/231540
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5192407a188e88d7ccd43188a9d6d4a423db7901
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Fix TestSiteInfo.test_properties_with_defaults
......................................................................
Fix TestSiteInfo.test_properties_with_defaults
siteinfo.get must be used to access defaults.
Also fix a code comment.
Change-Id: Icd3fb0bc3c562e08a6e1688d849c5f870dd41903
---
M tests/site_tests.py
1 file changed, 5 insertions(+), 3 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_tests.py b/tests/site_tests.py
index ae56705..76f1db3 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1793,15 +1793,17 @@
"""Test the siteinfo properties with defaults."""
# This does not test that the defaults work correct,
# unless the default site is a version needing these defaults
- # 'fileextensions' introduced in v1.14:
+ # 'fileextensions' introduced in v1.15:
self.assertIsInstance(self.site.siteinfo.get('fileextensions'), list)
self.assertIn('fileextensions', self.site.siteinfo)
- self.assertIn({'ext': 'png'}, self.site.siteinfo['fileextensions'])
+ fileextensions = self.site.siteinfo.get('fileextensions')
+ self.assertIn({'ext': 'png'}, fileextensions)
# 'restrictions' introduced in v1.23:
mysite = self.site
self.assertIsInstance(mysite.siteinfo.get('restrictions'), dict)
self.assertIn('restrictions', mysite.siteinfo)
- self.assertIn('cascadinglevels', self.site.siteinfo['restrictions'])
+ restrictions = self.site.siteinfo.get('restrictions')
+ self.assertIn('cascadinglevels', restrictions)
def test_no_cache(self):
"""Test siteinfo caching can be disabled."""
--
To view, visit https://gerrit.wikimedia.org/r/231466
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icd3fb0bc3c562e08a6e1688d849c5f870dd41903
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] interwiki: Use correct integer range
......................................................................
[FIX] interwiki: Use correct integer range
In d15e0c44 the interwiki script uses IntegerOption with the maximum being one
element larger than allowed. This is now using a ListOption as a more
appropriate choice.
Change-Id: Icc92280566c7d972275a5dc344f6e5567e480f9c
---
M scripts/interwiki.py
1 file changed, 3 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index f6b4c5b..57bc1e3 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -359,7 +359,7 @@
import pywikibot
from pywikibot import config, i18n, pagegenerators, textlib, interwiki_graph, titletranslate
-from pywikibot.bot import IntegerOption, StandardOption
+from pywikibot.bot import ListOption, StandardOption
from pywikibot.tools import first_upper
if sys.version_info[0] > 2:
@@ -1575,13 +1575,13 @@
# TODO: allow answer to repeat previous or go back after a mistake
answer = pywikibot.input_choice(
'Which variant should be used?',
- (IntegerOption(maximum=len(pages) + 1),
+ (ListOption(pages),
StandardOption('none', 'n'),
StandardOption('give up', 'g')))
if answer == 'g':
return None
elif answer != 'n':
- result[site] = pages[answer[1] - 1]
+ result[site] = answer[1]
# Loop over the ones that have one solution, so are in principle
# not a problem.
--
To view, visit https://gerrit.wikimedia.org/r/231502
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icc92280566c7d972275a5dc344f6e5567e480f9c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>