jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] Throw an error for incorrect logtypes for pagegenerators.handleArgs() ......................................................................
[bugfix] Throw an error for incorrect logtypes for pagegenerators.handleArgs()
- check whether given logevents is a valid logtype - throw an exception if they are wrong - add test for wrong arguments - remove @unittest.expectedFailure
Bug: T130928 Change-Id: I7abf905a965b02ca1f2ac233adfbd6adf86d0013 --- M pywikibot/pagegenerators.py M tests/pagegenerators_tests.py 2 files changed, 15 insertions(+), 8 deletions(-)
Approvals: Magul: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 1622766..c553b68 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -50,6 +50,7 @@
from pywikibot import date, config, i18n, xmlreader from pywikibot.exceptions import ArgumentDeprecationWarning, UnknownExtension +from pywikibot.logentries import LogEntryFactory from pywikibot.proofreadpage import ProofreadPage
if sys.version_info[0] > 2: @@ -900,12 +901,19 @@ self.subpage_max_depth = int(value) return True elif arg == '-logevents': - gen = self._parse_log_events(*value.split(',')) + params = value.split(',') + if params[0] not in LogEntryFactory.logtypes: + raise NotImplementedError( + 'Invalid -logevents parameter "{0}"'.format(params[0])) + gen = self._parse_log_events(*params) elif arg.startswith('-'): mode, log, tail = arg.partition('log') # exclude -log, -nolog if log == 'log' and mode not in ['-', '-no'] and not tail: - mode = mode[1:] + logtype = mode[1:] + if logtype not in LogEntryFactory.logtypes: + raise NotImplementedError( + 'Invalid logevent option "{0}log"'.format(mode)) total = 500 if value: try: @@ -923,9 +931,9 @@ issue_deprecation_warning( 'The usage of "{0}"'.format(arg), '-logevents:"{0}"'.format( - ','.join((mode, value or '', str(total)))), + ','.join((logtype, value or '', str(total)))), 2, ArgumentDeprecationWarning) - gen = self._parse_log_events(mode, value, total) + gen = self._parse_log_events(logtype, value, total)
if gen: self.gens.append(gen) diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index f0e123e..06d0bab 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -1079,15 +1079,14 @@
user = True
- @unittest.expectedFailure def test_logevents_parse(self): """Test wrong logevents option.""" gf = pagegenerators.GeneratorFactory() self.assertFalse(gf.handleArg("-log")) self.assertFalse(gf.handleArg("-log:text_here")) - # TODO: Throw an error for incorrect logtypes - self.assertRaises(gf.handleArg("-this_will_never_be_a_typelog"), - Exception) + self.assertRaises(NotImplementedError, + gf.handleArg, '-logevents:anyevent') + self.assertRaises(NotImplementedError, gf.handleArg, '-anotherlog')
def test_logevents_default(self): """Test old logevents option handling."""