Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/137904

Change subject: L10N test for valid redirect-broken-redirect-template template
......................................................................

L10N test for valid redirect-broken-redirect-template template

Change-Id: I891a4862e16d2d51eec0cca03367e74feedf4d2b
---
A tests/l10n_tests.py
1 file changed, 86 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/04/137904/1

diff --git a/tests/l10n_tests.py b/tests/l10n_tests.py
new file mode 100644
index 0000000..8f12aaa
--- /dev/null
+++ b/tests/l10n_tests.py
@@ -0,0 +1,86 @@
+# -*- coding: utf-8  -*-
+#
+# (C) Pywikibot team, 2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+
+import os
+import re
+import shutil
+from tests.utils import unittest
+import pywikibot
+from pywikibot import i18n
+
+
+PACKAGE = 'redirect'
+
+
+class TestValidTemplateMeta(type):
+    """Test meta class"""
+
+    def __new__(cls, name, bases, dct):
+        """create the new class"""
+
+        def test_method(msg, code):
+
+            def test_template(self):
+                """Test validity of template"""
+                if msg:
+                    #check whether the message contains a template
+                    template = re.findall(u'.*?{{(.*?)[|}]', msg)
+                    self.assertTrue(template)
+
+                    if template:
+                        # check whether site is valid
+                        site = pywikibot.Site('en', 'wikipedia')
+                        self.assertTrue(code in 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
+
+        # copy redirect file from scripts/i18n
+        filename = PACKAGE + '.py'
+        cls.path = os.path.split(os.path.realpath(__file__))[0]
+        shutil.copyfile(os.path.join(cls.path, '..', 'scripts', 'i18n', 
filename),
+                        os.path.join(cls.path, 'i18n', filename))
+        transdict = getattr(__import__("i18n", {}, {}, [PACKAGE]), PACKAGE).msg
+
+        # create test methods processed by unittest
+        for code in sorted(transdict):
+            if code == 'qqq':
+                continue
+            trans = transdict[code]
+            template_msg = trans.get('redirect-broken-redirect-template')
+            test_name = "test_" + code
+            dct[test_name] = test_method(template_msg, code)
+        return type.__new__(cls, name, bases, dct)
+
+
+class TestValidTemplate(unittest.TestCase):
+    """Test cases for date library processed by unittest"""
+
+    __metaclass__ = TestValidTemplateMeta
+
+    @classmethod
+    def tearDownClass(cls):
+        """ delete local redirect file(s) """
+        filename = PACKAGE + '.py'
+        os.remove(os.path.join(cls.path, 'i18n', filename))
+        try:
+            os.remove(os.path.join(cls.path, 'i18n', filename + 'c'))
+        except OSError:
+            pass
+
+
+if __name__ == '__main__':
+    try:
+        unittest.main()
+    except SystemExit:
+        pass

-- 
To view, visit https://gerrit.wikimedia.org/r/137904
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I891a4862e16d2d51eec0cca03367e74feedf4d2b
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <i...@gno.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to