tests.textlib_tests module#

Test textlib module.

class tests.textlib_tests.TestAddText(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, DefaultDrySiteTestCase

Test add_text function.

abstract_class = False#
code = 'test'#
dry = True#
family = 'wikipedia'#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_add_text()[source]#

Test adding text.

class tests.textlib_tests.TestCategoryRearrangement(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, DefaultDrySiteTestCase

Ensure that sorting keys are not being lost.

Tests .getCategoryLinks() and .replaceCategoryLinks(), with both a newline and an empty string as separators.

abstract_class = False#
code = 'test'#
dry = True#
family = 'wikipedia'#
old = '[[Category:Cat1]]\n[[Category:Cat2|]]\n[[Category:Cat1| ]]\n[[Category:Cat2|key]]'#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_in_place_replace()[source]#

Test in-place category change is reversible.

test_in_place_retain_sort()[source]#

Test in-place category change does not alter the sortkey.

test_indentation()[source]#

Test indentation from previous block.

Test getting and replacing categories.

class tests.textlib_tests.TestDigitsConversion(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

Test to verify that local digits are correctly being handled.

abstract_class = False#
test_to_latin()[source]#

Test converting local digits to Latin digits.

test_to_local()[source]#

Test converting Latin digits to local digits.

class tests.textlib_tests.TestDisabledParts(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, DefaultDrySiteTestCase

Test the removeDisabledParts function in textlib.

abstract_class = False#
code = 'test'#
dry = True#
family = 'wikipedia'#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_remove_disabled_parts()[source]#

Test removeDisabledParts function.

test_remove_disabled_parts_include()[source]#

Test removeDisabledParts function with the include argument.

test_remove_disabled_parts_order()[source]#

Test the order of the replacements in removeDisabledParts.

class tests.textlib_tests.TestExtractSections(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, DefaultDrySiteTestCase

Test the extract_sections function.

abstract_class = False#
code = 'test'#
dry = True#
family = 'wikipedia'#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_long_comment()[source]#

Test for text having a long expanse of white space.

This is to catch certain regex issues caused by patterns like r’(s+)*$’ (as found in older versions of extract_section). They may not halt.

c.f. https://www.regular-expressions.info/catastrophic.html

Test for text having no sections or footer.

Test for text having footer but no section.

test_with_h1_and_h2_sections()[source]#

Test for text having h1 and h2 sections.

test_with_h4_and_h2_sections()[source]#

Test for text having h4 and h2 sections.

Test for text having sections but no footer.

Test for text having sections and footer.

class tests.textlib_tests.TestFormatCategory(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, DefaultDrySiteTestCase

Test category formatting.

abstract_class = False#
catresult = '[[Category:Cat1]]\n[[Category:Cat2]]\n'#
code = 'test'#
dry = True#
family = 'wikipedia'#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_category_format_Category()[source]#

Test formatting categories as Category instances.

test_category_format_Page()[source]#

Test formatting categories as Page instances.

test_category_format_bare()[source]#

Test formatting categories as strings.

test_category_format_raw()[source]#

Test formatting categories as strings formatted as links.

class tests.textlib_tests.TestFormatInterwiki(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, ForceCacheMixin, TestCase

Test format functions.

abstract_class = False#
cached = True#
code = 'en'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:en': {'code': 'en', 'family': 'wikipedia'}}#

Test formatting interwiki links using Page instances.

test_interwiki_format_Page()[source]#

Test formatting interwiki links using Page instances.

Bases: CheckHostnameMixin, SiteAttributeTestCase

Test textlib.getLanguageLinks function.

abstract_class = False#
example_text = '[[en:Site]] [[de:Site|Piped]] [[commons:Site]] [[baden:Site]] [[fr:{{PAGENAME}}]]'#
net = True#
classmethod setUpClass()[source]#

Define set of valid targets for the example text.

site = True#
sites = {'commons': {'code': 'commons', 'family': 'commons'}, 'dewp': {'code': 'de', 'family': 'wikipedia'}, 'enwp': {'code': 'en', 'family': 'wikipedia'}}#

Test if the function returns the correct titles and sites on commons:commons

Test if the function returns the correct titles and sites on wikipedia:de

Test if the function returns the correct titles and sites on wikipedia:en

class tests.textlib_tests.TestMultiTemplateMatchBuilder(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, DefaultDrySiteTestCase

Test MultiTemplateMatchBuilder.

abstract_class = False#
code = 'test'#
dry = True#
family = 'wikipedia'#
classmethod setUpClass()[source]#

Cache namespace 10 (Template) case sensitivity.

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

Test text with one match without parameters.

test_match_msg()[source]#

Test text with {{msg:..}}.

test_match_template_prefix()[source]#

Test pages with {{template:..}}.

test_match_with_params()[source]#

Test text with one match with parameters.

test_no_match()[source]#

Test text without any desired templates.

class tests.textlib_tests.TestReplaceExcept(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, DefaultDrySiteTestCase

Test to verify the replacements with exceptions are done correctly.

abstract_class = False#
code = 'test'#
dry = True#
family = 'wikipedia'#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_case_sensitive()[source]#

Test replacing with different case sensitivity.

test_no_replace()[source]#

Test replacing when the old text does not match.

test_overlapping_replace()[source]#

Test replacing with and without overlap.

test_regex_replace()[source]#

Test replacing with a regex.

test_replace_exception()[source]#

Test replacing not inside a specific regex.

test_replace_source_reference()[source]#

Test replacing in text which contains back references.

test_replace_tag_category()[source]#

Test replacing not inside category links.

test_replace_tag_file()[source]#

Test replacing not inside file links.

test_replace_tag_file_failure()[source]#

Test showing limits of the file link regex.

test_replace_tag_file_invalid()[source]#

Test replacing not inside file links with invalid titles.

test_replace_tags()[source]#

Test replacing not inside various tags.

test_replace_tags_interwiki()[source]#

Test replacing not inside interwiki links.

test_replace_template()[source]#

Test replacing not inside templates.

test_replace_with_count()[source]#

Test replacing with count argument.

test_replace_with_marker()[source]#

Test replacing with a marker.

test_simple_replace()[source]#

Test replacing without regex.

Bases: DisconnectedSiteMixin, TestCase

Test the replace_links function in textlib.

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

Create a fake interwiki cache.

site = True#
sites = {'wp': {'code': 'en', 'family': 'wikipedia'}, 'wt': {'code': 'en', 'family': 'wiktionary'}}#
test_bytes_callback()[source]#

Test returning bytes in the callback.

test_label_diff_namespace()[source]#

Test that it uses the old label when the new doesn’t match.

test_linktrails()[source]#

Test that the linktrails are used or applied.

test_replace_different_case()[source]#

Test that it uses piped links when the case is different.

test_replace_file()[source]#

Test that it respects the namespace.

Make sure interwiki links cannot be replaced.

Test that it doesn’t pipe a link when it’s an invalid link.

test_replace_modes()[source]#

Test replacing with or without label and section.

test_replace_neighbour()[source]#

Test that it replaces two neighbouring links.

test_replace_strings()[source]#

Test if strings can be used.

test_replacements_function()[source]#

Test a dynamic function as the replacements.

test_replacements_once()[source]#

Test dynamic replacement.

test_replacements_simplify()[source]#

Test a tuple as replacement removing the need for a piped link.

test_unicode_callback()[source]#

Test returning unicode in the callback.

Test unlinking.

Test unlinking only some links.

text = 'Hello [[World]], [[how|are]] [[you#section|you]]? Are [[you]] a [[bug:1337]]?'#
class tests.textlib_tests.TestReplaceLinksNonDry(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, ForceCacheMixin, TestCase

Test the replace_links function in textlib non-dry.

abstract_class = False#
cached = True#
code = 'en'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:en': {'code': 'en', 'family': 'wikipedia'}}#

Test replacing interlanguage links.

class tests.textlib_tests.TestSectionFunctions(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

Test wikitext section handling function.

abstract_class = False#
assertContains(fn, sn, *args, **kwargs)[source]#

Test that files[fn] contains sn.

assertNotContains(fn, sn, *args, **kwargs)[source]#

Test that files[fn] does not contain sn.

static contains(fn, sn)[source]#

Invoke does_text_contain_section().

setUp()[source]#

Setup tests.

testCurrentBehaviour()[source]#

Test that ‘Editing’ is found.

testSpacesInSection()[source]#

Test with spaces in section.

test_encoded_chars_in_section()[source]#

Test encoded chars in section.

Test with link inside section.

test_spaces_outside_section()[source]#

Test with spaces around section.

test_underline_characters_in_section()[source]#

Test with underline chars in section.

class tests.textlib_tests.TestTemplateParams(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

Test to verify that template params extraction works.

abstract_class = False#
test_extract_templates_params()[source]#

Test that the normal entry point works.

test_extract_templates_params_mwpfh()[source]#

Test using mwparserfromhell.

test_extract_templates_params_parser()[source]#

Test using wikitextparser.

test_extract_templates_params_parser_stripped()[source]#

Test using mwparserfromhell with stripping.

test_nested_template_regex_match()[source]#

Test NESTED_TEMPLATE_REGEX match.

Test NESTED_TEMPLATE_REGEX search.

test_template_simple_regex()[source]#

Test using simple regex.

class tests.textlib_tests.TestTemplatesInCategory(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, ForceCacheMixin, TestCase

Tests to verify that templates in category links are handled.

abstract_class = False#
cached = True#
code = 'en'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:en': {'code': 'en', 'family': 'wikipedia'}}#
test_templates()[source]#

Test normal templates inside category links.