jenkins-bot has submitted this change and it was merged.
Change subject: Pagegenerators: ns handling for titleregex option ......................................................................
Pagegenerators: ns handling for titleregex option
Workaround for Bug T85389, a previoulsy done for -newpages.
If namespace is given before -titleregex, it can be handled. With argparse support, it will be possible to completely solve the bug.
Bug: T57226 Change-Id: I69bf8b9782b97426c0b67ef97b3892f152fe0fb1 --- M pywikibot/pagegenerators.py M tests/pagegenerators_tests.py 2 files changed, 37 insertions(+), 9 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 601f809..0053ce6 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -116,6 +116,8 @@ before -newpages. If used with -recentchanges, efficiency is improved if -namepace/ns is provided before -recentchanges. + If used with -titleregex, -namepace/ns must be provided + before -titleregex and shall contain only one value.
-interwiki Work on the given page and all equivalent pages in other languages. This can, for example, be used to fight @@ -698,7 +700,15 @@ regex = pywikibot.input(u'What page names are you looking for?') else: regex = arg[12:] - gen = RegexFilterPageGenerator(self.site.allpages(), regex) + # partial workaround for bug T85389 + # to use -namespace/ns with -newpages, -ns must be given + # before -titleregex, otherwise default namespace is 0. + # allpages only accepts a single namespace, and will raise a + # TypeError if self.namespaces contains more than one namespace. + namespaces = self.namespaces or 0 + gen = RegexFilterPageGenerator( + self.site.allpages(namespace=namespaces), + regex) elif arg.startswith('-grep'): if len(arg) == 5: self.articlefilter_list.append(pywikibot.input( diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index b6fc34d..25e0875 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -548,21 +548,39 @@ self.assertIsInstance(page, pywikibot.Page) self.assertRegex(page.title().lower(), '(.)\1+')
- def test_regexfilter_ns(self): - raise unittest.SkipTest('This test takes over 10 minutes due to T85389') + def test_regexfilter_ns_after(self): + """Bug: T85389: -ns after -titleregex is ignored with a warning.""" gf = pagegenerators.GeneratorFactory() self.assertTrue(gf.handleArg('-titleregex:.*')) - gf.handleArg('-limit:10') gf.handleArg('-ns:1') + gf.handleArg('-limit:10') gen = gf.getCombinedGenerator() - # The code below takes due to bug T85389 pages = list(gen) - # TODO: Fix RegexFilterPageGenerator to handle namespaces other than 0 - # Bug: T85389 - # Below should fail self.assertGreater(len(pages), 0) self.assertLessEqual(len(pages), 10) - self.assertPagesInNamespaces(gen, 1) + self.assertPagesInNamespaces(pages, 0) + + def test_regexfilter_ns_first(self): + gf = pagegenerators.GeneratorFactory() + # Workaround for Bug: T85389 + # Give -ns before -titleregex (as for -newpages) + gf.handleArg('-ns:1') + self.assertTrue(gf.handleArg('-titleregex:.*')) + gf.handleArg('-limit:10') + gen = gf.getCombinedGenerator() + pages = list(gen) + self.assertGreater(len(pages), 0) + self.assertLessEqual(len(pages), 10) + self.assertPagesInNamespaces(pages, 1) + + def test_regexfilter_two_ns_first(self): + gf = pagegenerators.GeneratorFactory() + gf.handleArg('-ns:3,1') + self.assertRaisesRegex( + TypeError, + 'allpages module does not support multiple namespaces', + gf.handleArg, + '-titleregex:.*')
def test_prefixing_default(self): gf = pagegenerators.GeneratorFactory()
pywikibot-commits@lists.wikimedia.org