tests.i18n_tests module#

Test i18n module.

class tests.i18n_tests.InputTestCase(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TWNTestCaseBase, UserInterfaceLangTestCase, PwbTestCase

Test i18n.input.

abstract_class = False#
alt_code = 'nb'#
code = 'nn'#
family = 'wikipedia'#
message = 'pywikibot-enter-category-name'#
message_package = 'scripts.i18n'#
net = True#
pwb = True#
classmethod setUpClass()[source]#

Verify that a translation does not yet exist.

site = True#
sites = {'wikipedia:nn': {'code': 'nn', 'family': 'wikipedia'}}#
test_pagegen_i18n_input()[source]#

Test i18n.input fallback via pwb.

class tests.i18n_tests.MissingPackageTestCase(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TWNSetMessagePackageBase, UserInterfaceLangTestCase, DefaultSiteTestCase

Test missing messages package.

abstract_class = False#
code = 'test'#
family = 'wikipedia'#
message_package = 'scripts.foobar.i18n'#
net = True#
setUp()[source]#

Patch the output and input methods.

site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
tearDown()[source]#

Restore the output and input methods.

test_cosmetic_changes_hook()[source]#

Test summary result of Page._cosmetic_changes_hook.

test_i18n_input()[source]#

Test i18n.input falls back with missing message package.

test_i18n_twtranslate()[source]#

Test i18n.twtranslate falls back with missing message package.

class tests.i18n_tests.Site(code, family='wikipedia')[source]#

Bases: object

An object holding code and family, duck typing a pywikibot Site.

class Family[source]#

Bases: object

Nested class to hold the family name attribute.

class tests.i18n_tests.TWNSetMessagePackageBase(*args, **kwargs)[source]#

Bases: TestCase

Partial base class for TranslateWiki tests.

abstract_class = True#
message_package = None#
setUp()[source]#

Load the test translations.

tearDown()[source]#

Load the original translations back.

class tests.i18n_tests.TWNTestCaseBase(*args, **kwargs)[source]#

Bases: TWNSetMessagePackageBase

Base class for TranslateWiki tests.

abstract_class = True#
classmethod setUpClass()[source]#

Verify that the test translations are not empty.

class tests.i18n_tests.TestExtractPlural(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

Test extracting plurals from a dummy string.

abstract_class = False#
test_empty_fields()[source]#

Test default usage using a dict and no specific plurals.

test_less()[source]#

Test the number of plurals are less than expected.

test_more()[source]#

Test the number of plurals are more than expected.

test_specific()[source]#

Test using a specific plural.

test_standard()[source]#

Test default usage using a dict and no specific plurals.

class tests.i18n_tests.TestFallbackTranslate(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

Test translate method with fallback True.

abstract_class = False#
msg_localized = {'en': 'test-localized EN', 'fy': 'test-localized FY', 'nl': 'test-localized NL'}#
msg_no_english = {'ja': 'test-no-english JA'}#
msg_non_localized = {'en': 'test-non-localized EN'}#
msg_semi_localized = {'en': 'test-semi-localized EN', 'nl': 'test-semi-localized NL'}#
testNoEnglish()[source]#

Test translate with missing English text.

test_localized()[source]#

Test fully localized translations.

test_non_localized()[source]#

Test translate with missing localisation.

test_semi_localized()[source]#

Test translate by fallback to an alternative language.

class tests.i18n_tests.TestTWTranslate(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TWNTestCaseBase

Test twtranslate method.

abstract_class = False#
message_package = 'tests.i18n'#
testLocalized()[source]#

Test fully localized entry.

testNoEnglish()[source]#

Test translating into English with missing entry.

testNonLocalized()[source]#

Test translating non localized entries.

testSemiLocalized()[source]#

Test translating with fallback to alternative language.

class tests.i18n_tests.TestTranslate(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

Test translate method with fallback True.

abstract_class = False#
test_translate_commons()[source]#

Test localization with xdict for commons.

Test whether the localzation is found either with the Site object or with the site code.

test_translate_de()[source]#

Test localization fallbacks for ‘de’ with xdict.

‘de’ key is defined in a nested ‘wikipedia’ sub dict. This should always fall back to this nested ‘wikipedia’ entry.

test_translate_en()[source]#

Test localization fallbacks for ‘en’ with xdict.

‘en’ key is defined directly in xdict. This topmost key goes over site specific key. Therefore ‘test-localized WS-EN’ is not given back.

test_translate_fy()[source]#

Test localization fallbacks for ‘fy’ with xdict.

‘fy’ key is defined in ‘wikipedia’ and ‘wikisource’ sub dicts. They should have different localizations for these two families but ‘wikisource’ should have a fallback to the ‘wikipedia’ entry.

Note: If the translate code is given as string, the result depends on the current config.family entry. Therefore there is no test with the code given as string.

test_translate_ja()[source]#

Test localization fallbacks for ‘ja’ with xdict.

‘ja’ key is defined in ‘wkisource’ sub dict only. Therefore there is no fallback to the ‘wikipedia’ entry and the localization result is None.

test_translate_nl()[source]#

Test localization fallbacks for ‘nl’ with xdict.

‘nl’ key is defined in ‘wikipedia’ sub dict. Therefore all localizations have a fallback to the ‘wikipedia’ entry.

xdict = {'commons': 'test-localized COMMONS', 'en': 'test-localized EN', 'wikipedia': {'fy': 'test-localized WP-FY', 'nl': 'test-localized WP-NL', 'wikipedia': {'de': 'test-localized WP-DE'}}, 'wikisource': {'en': 'test-localized WS-EN', 'fy': 'test-localized WS-FY', 'ja': 'test-localized WS-JA'}}#
class tests.i18n_tests.UserInterfaceLangTestCase(*args, **kwargs)[source]#

Bases: TestCase

Base class for tests using config.userinterface_lang.

abstract_class = True#
setUp()[source]#

Change the userinterface language to the site’s code.

tearDown()[source]#

Reset the userinterface language.