Example #1
0
 def setUpClass(cls):
     """Verify that the translations are available."""
     if not i18n.messages_available():
         raise unittest.SkipTest(
             "i18n messages package '%s' not available." %
             i18n._messages_package_name)
     super(TWNBotTestCase, cls).setUpClass()
Example #2
0
 def setUpClass(cls):
     """Skip test gracefully if i18n package is missing."""
     super().setUpClass()
     if not i18n.messages_available():
         raise unittest.SkipTest(
             "i18n messages package '{}' not available.".format(
                 i18n._messages_package_name))
Example #3
0
 def setUpClass(cls):
     """Verify that the translations are available."""
     if not i18n.messages_available():
         raise unittest.SkipTest(
             "i18n messages package '{}' not available.".format(
                 i18n._messages_package_name))
     super().setUpClass()
Example #4
0
    def __new__(cls, name, bases, dct):
        """Create the new class."""
        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
                    templates = extract_templates_and_params_regex_simple(msg)
                    self.assertIsInstance(templates, list)
                    self.assertGreater(len(templates), 0)

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

            return test_template

        # create test methods for package messages processed by unittest
        if not i18n.messages_available():
            raise unittest.SkipTest(
                "i18n messages package '{}' not available.".format(
                    i18n._messages_package_name))

        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, dct['family'])
                test_name = ('test_{}_{}'.format(package,
                                                 code)).replace('-', '_')
                cls.add_method(dct,
                               test_name,
                               test_method(current_site),
                               doc_suffix='{0} and language {1}'.format(
                                   package, code))

        return super(TestValidTemplateMeta, cls).__new__(cls, name, bases, dct)
Example #5
0
 def setUpClass(cls):
     """Verify that the test translations are not empty."""
     if not isinstance(cls.message_package, StringTypes):
         raise TypeError('{0!s}.message_package must be a package name'.format(cls.__name__))
     # The call to set_messages_package below exists only to confirm
     # that the package exists and messages are available, so
     # that tests can be skipped if the i18n data doesnt exist.
     cls.orig_messages_package_name = i18n._messages_package_name
     i18n.set_messages_package(cls.message_package)
     has_messages = i18n.messages_available()
     i18n._messages_package_name = cls.orig_messages_package_name
     if not has_messages:
         raise unittest.SkipTest("i18n messages package '{0!s}' not available.".format(cls.message_package))
     super(TWNTestCaseBase, cls).setUpClass()
Example #6
0
 def setUpClass(cls):
     if not isinstance(cls.message_package, basestring):
         raise TypeError('%s.message_package must be a package name'
                         % cls.__name__)
     # Th call to set_messages_package below exists only to confirm
     # that the package exists and messages are available, so
     # that tests can be skipped if the i18n data doesnt exist.
     cls.orig_messages_package_name = i18n._messages_package_name
     i18n.set_messages_package(cls.message_package)
     has_messages = i18n.messages_available()
     i18n._messages_package_name = cls.orig_messages_package_name
     if not has_messages:
         raise unittest.SkipTest("i18n messages package '%s' not available."
                                 % cls.message_package)
     super(TWNTestCaseBase, cls).setUpClass()
Example #7
0
    def __new__(cls, name, bases, dct):
        """Create the new class."""
        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)
                    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.")
                    # 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
        if not i18n.messages_available():
            raise unittest.SkipTest(
                "i18n messages package '%s' not available." %
                i18n._messages_package_name)

        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, dct['family'])
                test_name = ("test_%s_%s" % (package, code)).replace('-', '_')
                cls.add_method(dct,
                               test_name,
                               test_method(current_site),
                               doc_suffix='{0} and language {1}'.format(
                                   package, code))

        return super(TestValidTemplateMeta, cls).__new__(cls, name, bases, dct)
Example #8
0
    def __new__(cls, name, bases, dct):
        """Create the new class."""
        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
                    templates = extract_templates_and_params_regex_simple(msg)
                    self.assertIsInstance(templates, list)
                    self.assertGreater(len(templates), 0)

                    # 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())

            return test_template

        # create test methods for package messages processed by unittest
        if not i18n.messages_available():
            raise unittest.SkipTest("i18n messages package '%s' not available."
                                    % i18n._messages_package_name)

        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, dct['family'])
                test_name = ("test_%s_%s" % (package, code)).replace('-', '_')
                cls.add_method(
                    dct, test_name, test_method(current_site),
                    doc_suffix='{0} and language {1}'.format(
                        package, code))

        return super(TestValidTemplateMeta, cls).__new__(cls, name, bases, dct)
Example #9
0
 def setUpClass(cls):
     """Verify that the test translations are not empty."""
     if not isinstance(cls.message_package, StringTypes):
         raise TypeError('{}.message_package must be a package name'
                         .format(cls.__name__))
     # The call to set_messages_package below exists only to confirm
     # that the package exists and messages are available, so
     # that tests can be skipped if the i18n data doesnt exist.
     cls.orig_messages_package_name = i18n._messages_package_name
     i18n.set_messages_package(cls.message_package)
     has_messages = i18n.messages_available()
     i18n._messages_package_name = cls.orig_messages_package_name
     if not has_messages:
         raise unittest.SkipTest("i18n messages package '{}' not available."
                                 .format(cls.message_package))
     super(TWNTestCaseBase, cls).setUpClass()
 def setUpClass(cls):
     """Verify that the translations are available."""
     if not i18n.messages_available():
         raise unittest.SkipTest("i18n messages package '%s' not available." % i18n._messages_package_name)
     super(TWNBotTestCase, cls).setUpClass()
Example #11
0
    'disambredir',
    'isbn',
    'protectbot',
    'reflinks',
    'template_bot',
    'replacebot',
    'uploadbot',
    'weblinkchecker',
    'cache',
]

disabled_test_modules = [
    'tests',  # tests of the tests package
    'l10n',
]
if not i18n.messages_available():
    disabled_test_modules.append('l10n')

disabled_tests = {
    'textlib': [
        'test_interwiki_format',  # example; very slow test
    ],
    'weblib': [
        'testWebCiteOlder',  # fails. T110640
    ],
}


def _unknown_test_modules():
    """List tests which are to be executed."""
    dir_list = os.listdir(join_tests_path())
Example #12
0
    'isbn',
    'protectbot',
    'reflinks',
    'replacebot',
    'uploadbot',
    'weblinkchecker',
    'cache',
]

disabled_test_modules = [
    'tests',  # tests of the tests package
    # weblib is deprecated, the tests fail for weblib,
    # but the tests are run in weblinkchecker_tests.
    'weblib',
]
if not i18n.messages_available():
    disabled_test_modules.append('l10n')

disabled_tests = {
    'textlib': [
        'test_interwiki_format',  # example; very slow test
    ],
    'site_detect': [
        'test_IWM',  # very slow and tests include unnecessary sites
    ],
}


def _unknown_test_modules():
    """List tests which are to be executed."""
    dir_list = os.listdir(_tests_dir)