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 <>