jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] l10n_tests: Do lazy network requests
......................................................................
[FIX] l10n_tests: Do lazy network requests
To get the site's language it needs to query the site's siteinfo. When this is
done in a test meta class it will do that regardless before something can check
the net flag of the class. To avoid this it's now requesting the language
inside the test method so that a testing environment can check the net flag
before.
This is also fixing other minor issues in the module:
- Removed senseless comment
- Use 'code' and 'family' attributes in both test classes
- Using super to call the actual super metaclass and not generic type metaclass
Change-Id: Iee5f4ad957b55139a07f711c30e682846df098f3
---
M tests/l10n_tests.py
1 file changed, 19 insertions(+), 23 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
XZise: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/tests/l10n_tests.py b/tests/l10n_tests.py
index f184ff7..294914a 100644
--- a/tests/l10n_tests.py
+++ b/tests/l10n_tests.py
@@ -29,12 +29,14 @@
def __new__(cls, name, bases, dct):
"""Create the new class."""
- # this comment is to avoid senseless flake8 warning
-
- def test_method(msg, site):
+ def test_method(site):
def test_template(self):
"""Test validity of template."""
+ lang = site.lang
+ if lang not in keys:
+ return
+ msg = i18n.twtranslate(lang, package, fallback=False)
if msg:
# check whether the message contains a template
template = re.findall(u'.*?{{(.*?)[|}]', msg)
@@ -46,32 +48,24 @@
"'simple' wiki has 'en' language code but "
"missing template. Must be solved by the "
"corresponding script.")
- if template:
- # check whether template exists
- title = template[0]
- page = pywikibot.Page(site, title, ns=10)
- self.assertTrue(page.exists())
+ # check whether template exists
+ title = template[0]
+ page = pywikibot.Page(site, title, ns=10)
+ self.assertTrue(page.exists())
return test_template
# create test methods for package messages processed by unittest
- site = pywikibot.Site('en', 'wikipedia')
+ site = pywikibot.Site(dct['code'], dct['family'])
codes = site.family.languages_by_size
del site
for package in PACKAGES:
keys = i18n.twget_keys(package)
for code in codes:
- current_site = pywikibot.Site(code, 'wikipedia')
- lang = current_site.lang
- if lang not in keys:
- continue
- template_msg = i18n.twtranslate(lang, package, fallback=False)
- if template_msg is None:
- continue
- test_name = ("test_%s_%s_%s"
- % (package, lang, code)).replace('-', '_')
- dct[test_name] = test_method(template_msg, current_site)
- return type.__new__(cls, name, bases, dct)
+ current_site = pywikibot.Site(code, dct['family'])
+ test_name = ("test_%s_%s" % (package, code)).replace('-', '_')
+ dct[test_name] = test_method(current_site)
+ return super(TestValidTemplateMeta, cls).__new__(cls, name, bases, dct)
@add_metaclass
@@ -81,19 +75,21 @@
__metaclass__ = TestValidTemplateMeta
- net = True # magic flag tells jenkins to not run the test.
+ family = 'wikipedia'
+ code = 'en'
class TestSites(TestCase):
"""Other test L10N cases processed by unittest."""
- site = pywikibot.Site('en', 'wikipedia')
+ family = 'wikipedia'
+ code = 'en'
def test_valid_sites(self):
"""Test whether language key has a corresponding site."""
codes = self.site.family.languages_by_size
- languages = [pywikibot.Site(code, 'wikipedia').lang for code in codes]
+ languages = [pywikibot.Site(code, self.family).lang for code in codes]
for package in PACKAGES:
keys = i18n.twget_keys(package)
for key in keys:
--
To view, visit https://gerrit.wikimedia.org/r/226329
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iee5f4ad957b55139a07f711c30e682846df098f3
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 <>
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #2574
Status: Broken
Duration: 30 minutes and 41 seconds
Commit: d708022 (master)
Author: Fabian Neundorf
Message: [IMPROV] page/textlib: add remaining docstrings
Only two docstrings were missing from the page module with PEP257 0.6.0 to
comply with the mandatory tox job. And the textlib module was missing only one.
Change-Id: Ied7846896301e2acb587e7414aebb4b26438a69c
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/6255530f833c...d708022e…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/72202118
--
You can configure recipients for build notifications in your .travis.yml file. See http://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] page/textlib: add remaining docstrings
......................................................................
[IMPROV] page/textlib: add remaining docstrings
Only two docstrings were missing from the page module with PEP257 0.6.0 to
comply with the mandatory tox job. And the textlib module was missing only one.
Change-Id: Ied7846896301e2acb587e7414aebb4b26438a69c
---
M pywikibot/page.py
M pywikibot/textlib.py
M tox.ini
3 files changed, 35 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
XZise: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 73c030f..1f94132 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4138,6 +4138,11 @@
'hash': data['hash']})
def toJSON(self):
+ """
+ Create dict suitable for the MediaWiki API.
+
+ @rtype: dict
+ """
data = {
'mainsnak': {
'snaktype': self.snaktype,
@@ -4524,6 +4529,17 @@
@property
def sha1(self):
+ """
+ Return and cache SHA1 checksum of the text.
+
+ @return: if the SHA1 checksum is cached it'll be returned which is the
+ case when it was requested from the API. Otherwise it'll use the
+ revision's text to calculate the checksum (encoding it using UTF8
+ first). That calculated checksum will be cached too and returned on
+ future calls. If the text is None (not queried) it will just return
+ None and does not cache anything.
+ @rtype: str or None
+ """
if self._sha1 is None:
if self.text is None:
# No text? No sha1 then.
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 1612436..a0b4d99 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -429,9 +429,23 @@
def expandmarker(text, marker='', separator=''):
- # set to remove any number of separator occurrences plus arbitrary
- # whitespace before, after, and between them,
- # by allowing to include them into marker.
+ """
+ Return a marker expanded whitespace and the separator.
+
+ It searches for the first occurrence of the marker and gets the combination
+ of the separator and whitespace directly before it.
+
+ @param text: the text which will be searched.
+ @type text: str
+ @param marker: the marker to be searched.
+ @type marker: str
+ @param separator: the separator string allowed before the marker. If empty
+ it won't include whitespace too.
+ @type separator: str
+ @return: the marker with the separator and whitespace from the text in front
+ of it. It'll be just the marker if the separator is empty.
+ @rtype: str
+ """
if separator:
firstinmarker = text.find(marker)
firstinseparator = firstinmarker
diff --git a/tox.ini b/tox.ini
index ae7e9c2..d85d20b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -56,8 +56,10 @@
pywikibot/fixes.py \
pywikibot/i18n.py \
pywikibot/login.py \
+ pywikibot/page.py \
pywikibot/pagegenerators.py \
pywikibot/plural.py \
+ pywikibot/textlib.py \
pywikibot/throttle.py \
pywikibot/tools/__init__.py \
pywikibot/tools/ip.py \
--
To view, visit https://gerrit.wikimedia.org/r/226306
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ied7846896301e2acb587e7414aebb4b26438a69c
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 <>
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #2573
Status: Passed
Duration: 27 minutes and 12 seconds
Commit: 6255530 (master)
Author: Fabian Neundorf
Message: [FIX] aspects: Imply user on write tests
At the moment all writes require a user to be logged in but tests may not
define user and in that case the write test might fail because it's not working
on a logged in user. This sets user to True if it hasn't been set and is a
write test. So in case someone writes a write test without requiring a logged
in user it's necessary to explicitly set write to False now.
Change-Id: I4ef37ed6d9b28b72c0a1aa6be447818408c7107f
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/9745542476f8...6255530f…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/72098968
--
You can configure recipients for build notifications in your .travis.yml file. See http://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] aspects: Imply user on write tests
......................................................................
[FIX] aspects: Imply user on write tests
At the moment all writes require a user to be logged in but tests may not
define user and in that case the write test might fail because it's not working
on a logged in user. This sets user to True if it hasn't been set and is a
write test. So in case someone writes a write test without requiring a logged
in user it's necessary to explicitly set write to False now.
Change-Id: I4ef37ed6d9b28b72c0a1aa6be447818408c7107f
---
M tests/aspects.py
1 file changed, 2 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py
index 8af9ade..df0a07c 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -763,6 +763,8 @@
bases = tuple([CheckHostnameMixin] + list(bases))
if 'write' in dct and dct['write']:
+ if 'user' not in dct:
+ dct['user'] = True
bases = tuple([SiteWriteMixin] + list(bases))
if ('user' in dct and dct['user']) or ('sysop' in dct and dct['sysop']):
--
To view, visit https://gerrit.wikimedia.org/r/226282
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4ef37ed6d9b28b72c0a1aa6be447818408c7107f
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 <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Convert comment to docstring
......................................................................
[IMPROV] Convert comment to docstring
The comment above CosmeticChangesToolkit.commonsfiledesc in
pywikibot.cosmetic_changes is converted into a proper docstring.
Change-Id: Ifc5aa5f30eaea8ef5f1937ffab9cdc6eddc26f9f
---
M pywikibot/cosmetic_changes.py
1 file changed, 8 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index c85548c..1fa7e21 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -886,8 +886,15 @@
text = textlib.replaceExcept(text, str(i), new[i], exceptions)
return text
- # Retrieved from "https://commons.wikimedia.org/wiki/Commons:Tools/pywiki_file_description_cl…"
def commonsfiledesc(self, text):
+ """
+ Clean up file descriptions on the Wikimedia Commons.
+
+ It is working according to [1] and works only on pages in the file
+ namespace on the Wikimedia Commons.
+
+ [1]: https://commons.wikimedia.org/wiki/Commons:Tools/pywiki_file_description_cl…
+ """
if self.site.sitename() != u'commons:commons' or self.namespace == 6:
return
# section headers to {{int:}} versions
--
To view, visit https://gerrit.wikimedia.org/r/225883
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc5aa5f30eaea8ef5f1937ffab9cdc6eddc26f9f
Gerrit-PatchSet: 3
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: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>