jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] L10N tests for site.lang key ......................................................................
[bugfix] L10N tests for site.lang key
Keys of i18n json files has been changed from site.code to site.lang. After updating the L10N test is broken due to some sites has different lang and code property.
- Now check templates for all sites in languages_by_size list. - skip known problems - create method name with lang and code - Check whether a given language has a corresponding site
Change-Id: I43131490147846d3486a6d457dc055ecb7593077 --- M tests/l10n_tests.py 1 file changed, 36 insertions(+), 9 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/l10n_tests.py b/tests/l10n_tests.py index 10e95b9..287d602 100644 --- a/tests/l10n_tests.py +++ b/tests/l10n_tests.py @@ -31,7 +31,7 @@ """Create the new class.""" # this comment is to avoid senseless flake8 warning
- def test_method(msg, code): + def test_method(msg, site):
def test_template(self): """Test validity of template.""" @@ -40,27 +40,37 @@ template = re.findall(u'.*?{{(.*?)[|}]', msg) self.assertTrue(template)
+ # known problem + if site.code == 'simple': + raise unittest.SkipTest( + "'simple' wiki has 'en' language code but " + "missing template. Must be solved by the " + "corresponding script.") if template: - # check whether site is valid - site = pywikibot.Site('en', 'wikipedia') - self.assertIn(code, site.languages()) - # check whether template exists title = template[0] - site = pywikibot.Site(code, 'wikipedia') 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') + codes = site.family.languages_by_size + del site for package in PACKAGES: - for lang in i18n.twget_keys(package): + 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" % (package.replace('-', '_'), lang) - dct[test_name] = test_method(template_msg, lang) + 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)
@@ -74,6 +84,23 @@ net = True # magic flag tells jenkins to not run the test.
+class TestSites(TestCase): + + """Other test L10N cases processed by unittest.""" + + site = pywikibot.Site('en', 'wikipedia') + + 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] + for package in PACKAGES: + keys = i18n.twget_keys(package) + for key in keys: + self.assertIn(key, languages, + "%s not found in site codes" % key) + + if __name__ == '__main__': try: unittest.main()
pywikibot-commits@lists.wikimedia.org