jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[doc] Raise a RuntimeError if -namespace is provided too late

If -namespace is used together with
-newpages/-random/-randomredirect/-linter generators,
-namespace/-ns must be provided before
-newpages/-random/-randomredirect/-linter.
Raise a RuntimeError with such comment instead of
just AssertionError without this hint

Bug: T276916
Change-Id: I66906f03dc837a59f07590eac8072e1a4d54c807
---
M pywikibot/pagegenerators.py
M tests/pagegenerators_tests.py
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 63d27a7..56ac03a 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -927,7 +927,9 @@

def _handle_namespaces(self, value):
"""Handle `-namespaces` argument."""
- assert not isinstance(self._namespaces, frozenset)
+ if isinstance(self._namespaces, frozenset):
+ raise RuntimeError('-namespace/ns option must be provided before '
+ '-newpages/-random/-randomredirect/-linter')
if not value:
value = pywikibot.input('What namespace are you filtering on?')
NOT_KEY = 'not:'
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 7d84dbe..b50aa56 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -707,7 +707,7 @@
gf.handle_arg('-ns:1,6')
self.assertEqual(gf.namespaces, {1, 6})
self.assertIsInstance(gf.namespaces, frozenset)
- with self.assertRaises(AssertionError):
+ with self.assertRaises(RuntimeError):
gf.handle_arg('-ns:0')
self.assertEqual(gf.namespaces, {1, 6})


To view, visit change 670163. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I66906f03dc837a59f07590eac8072e1a4d54c807
Gerrit-Change-Number: 670163
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: DannyS712 <DannyS712.enwiki@gmail.com>
Gerrit-CC: Inductiveload <inductiveload@gmail.com>
Gerrit-MessageType: merged