jenkins-bot has submitted this change and it was merged.
Change subject: add pagegenerators_tests.py to test suite ......................................................................
add pagegenerators_tests.py to test suite
Change-Id: I3257ffffa1ade83a80561ef088a2a30b1224050a --- A tests/pagegenerators_tests.py 1 file changed, 133 insertions(+), 0 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py new file mode 100644 index 0000000..de98968 --- /dev/null +++ b/tests/pagegenerators_tests.py @@ -0,0 +1,133 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# (C) Pywikibot team, 2014 +# +# Distributed under the terms of the MIT license. +__version__ = '$Id$' + +import sys +import pywikibot +from pywikibot import pagegenerators + +from tests.utils import unittest + + +class TestPageGenerators(unittest.TestCase): + """Test pagegenerators methods""" + + titles = [ + # just a bunch of randomly selected titles + u"Cities in Burkina Faso", + u"Eastern Sayan", + u"The Addams Family (pinball)", + u"Talk:Hispanic (U.S. Census)", + u"Talk:Stołpce", + u"Talk:Nowy Sącz", + u"Talk:Battle of Węgierska Górka", + u"Template:!", + u"Template:!/Doc", + u"Template:!/Meta", + u"Template:Template", + u"Template:Template/Doc", + u"Template:Template/Meta", + ] + + def setUp(self): + self.site = pywikibot.Site('en', 'wikipedia') + + def assertFunction(self, obj): + self.assertTrue(hasattr(pagegenerators, obj)) + self.assertTrue(hasattr(getattr(pagegenerators, obj), '__call__')) + + def test_module_import(self): + self.assertTrue("pywikibot.pagegenerators" in sys.modules) + + def test_PagesFromTitlesGenerator(self): + self.assertFunction("PagesFromTitlesGenerator") + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + self.assertTrue(len(self.titles) == len(tuple(gen))) + + def test_NamespaceFilterPageGenerator(self): + self.assertFunction("NamespaceFilterPageGenerator") + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.NamespaceFilterPageGenerator(gen, 0) + self.assertTrue(len(tuple(gen)) == 3) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.NamespaceFilterPageGenerator(gen, 1) + self.assertTrue(len(tuple(gen)) == 4) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.NamespaceFilterPageGenerator(gen, 10) + self.assertTrue(len(tuple(gen)) == 6) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.NamespaceFilterPageGenerator(gen, (1, 10)) + self.assertTrue(len(tuple(gen)) == 10) + + def test_RegexFilterPageGenerator(self): + self.assertFunction("RegexFilterPageGenerator") + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.RegexFilterPageGenerator(gen, '/doc') + self.assertTrue(len(tuple(gen)) == 2) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.RegexFilterPageGenerator(gen, '/doc', + quantifier='none') + self.assertTrue(len(tuple(gen)) == 11) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.RegexFilterPageGenerator(gen, ['/doc', '/meta']) + self.assertTrue(len(tuple(gen)) == 4) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.RegexFilterPageGenerator(gen, ['/doc', '/meta'], + quantifier='none') + self.assertTrue(len(tuple(gen)) == 9) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.RegexFilterPageGenerator(gen, ['/doc', '/meta'], + quantifier='all') + self.assertTrue(len(tuple(gen)) == 0) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.RegexFilterPageGenerator(gen, ['Template', '/meta'], + quantifier='all') + self.assertTrue(len(tuple(gen)) == 1) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles) + gen = pagegenerators.RegexFilterPageGenerator(gen, ['template', '/meta'], + quantifier='any') + self.assertTrue(len(tuple(gen)) == 4) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles, + site=self.site) + gen = pagegenerators.RegexFilterPageGenerator(gen, ['template', '/meta'], + quantifier='any', + ignore_namespace=False) + self.assertTrue(len(tuple(gen)) == 6) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles, + site=self.site) + gen = pagegenerators.RegexFilterPageGenerator(gen, ['template', '/meta'], + quantifier='all', + ignore_namespace=False) + self.assertTrue(len(tuple(gen)) == 2) + gen = pagegenerators.PagesFromTitlesGenerator(self.titles, + site=self.site) + gen = pagegenerators.RegexFilterPageGenerator(gen, ['template', '/meta'], + quantifier='none', + ignore_namespace=False) + self.assertTrue(len(tuple(gen)) == 7) + + def test_RegexBodyFilterPageGenerator(self): + self.assertFunction("RegexBodyFilterPageGenerator") + gen = pagegenerators.PagesFromTitlesGenerator(self.titles, + site=self.site) + pages = [] + for p in gen: + p.text = u"This is the content of %s as a sample" % p.title() + pages.append(p) + gen = pagegenerators.RegexBodyFilterPageGenerator(iter(pages), '/doc') + self.assertTrue(len(tuple(gen)) == 2) + gen = pagegenerators.RegexBodyFilterPageGenerator(iter(pages), 'This') + self.assertTrue(len(tuple(gen)) == 13) + gen = pagegenerators.RegexBodyFilterPageGenerator(iter(pages), 'talk', + quantifier='none') + self.assertTrue(len(tuple(gen)) == 9) + +if __name__ == "__main__": + try: + unittest.main() + except SystemExit: + pass
pywikibot-commits@lists.wikimedia.org