jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/516636 )

Change subject: [bugfix] Test all packages with l10n_tests.py
......................................................................

[bugfix] Test all packages with l10n_tests.py

- add package parameter to test_method all packages
- use i18n.twhas_key to verify that a translation message exists;
  otherwise a TranslationError will be raised
- skip tests on some sites where these aren't applicable

Bug: T225631
Bug: T225781
Change-Id: I13ec0f1761db95a50c1a871659fdea52cc3ce2d0
---
M tests/l10n_tests.py
1 file changed, 30 insertions(+), 23 deletions(-)

Approvals:
  Huji: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/l10n_tests.py b/tests/l10n_tests.py
index 52bb522..e398f51 100644
--- a/tests/l10n_tests.py
+++ b/tests/l10n_tests.py
@@ -28,35 +28,42 @@

     def __new__(cls, name, bases, dct):
         """Create the new class."""
-        def test_method(site):
+        def test_method(site, package):

             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
-                    templates = extract_templates_and_params_regex_simple(msg)
-                    self.assertIsInstance(templates, list)
-                    self.assertIsNotEmpty(templates)

-                    # 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.')
-                    # check whether template exists
-                    title = templates[0][0]
-                    page = pywikibot.Page(site, title, ns=10)
-                    self.assertTrue(
-                        page.exists(),
-                        msg='Invalid L10N in package "{package}"\n'
-                        'template "{title}" does not exist for lang '
-                        '"{site.lang}" on site "{site}"'
-                        .format(package=package, title=title, site=site))
+                if not i18n.twhas_key(lang, package):
+                    return
+
+                msg = i18n.twtranslate(lang, package, fallback=False)
+
+                # check whether the message contains a template
+                templates = extract_templates_and_params_regex_simple(msg)
+                self.assertIsInstance(templates, list)
+                self.assertIsNotEmpty(templates)
+
+                # known problems
+                if (package == PACKAGES[0] and site.code in ['simple', 'test2']
+                        or package == PACKAGES[1] and site.code == 'test'):
+                    raise unittest.SkipTest(
+                        "{site} wiki has '{site.lang}' language code but "
+                        "missing template for package '{package}'. Must be "
+                        'solved by the corresponding script.'
+                        .format(site=site, package=package))
+
+                # check whether template exists
+                title = templates[0][0]
+                page = pywikibot.Page(site, title, ns=10)
+                self.assertTrue(
+                    page.exists(),
+                    msg='Invalid L10N in package "{package}"\n'
+                    'template "{title}" does not exist for lang '
+                    '"{site.lang}" on site "{site}"'
+                    .format(package=package, title=title, site=site))

             return test_template

@@ -75,7 +82,7 @@
                 test_name = ('test_{}_{}'
                              .format(package, code)).replace('-', '_')
                 cls.add_method(
-                    dct, test_name, test_method(current_site),
+                    dct, test_name, test_method(current_site, package),
                     doc_suffix='{0} and language {1}'.format(
                         package, code))


--
To view, visit https://gerrit.wikimedia.org/r/516636
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I13ec0f1761db95a50c1a871659fdea52cc3ce2d0
Gerrit-Change-Number: 516636
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: Dvorapa <[email protected]>
Gerrit-Reviewer: Huji <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to