Skip to content

Commit

Permalink
Merge "[bugfix] Fix for positional_arg behavior of GeneratorFactory"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jan 15, 2017
2 parents f402a44 + 83c2f9a commit ee66372
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pywikibot/pagegenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
&params;
"""
#
# (C) Pywikibot team, 2008-2016
# (C) Pywikibot team, 2008-2017
#
# Distributed under the terms of the MIT license.
#
Expand Down Expand Up @@ -632,14 +632,15 @@ def intNone(v):
"""Return None if v is None or '' else return int(v)."""
return v if (v is None or v is '') else int(v)

arg, sep, value = arg.partition(':')
if value == '':
value = None

gen = None
if not arg.startswith('-') and self._positional_arg_name:
value = arg
arg = '-' + self._positional_arg_name
else:
arg, sep, value = arg.partition(':')

if value == '':
value = None

if arg == '-filelinks':
if not value:
Expand Down
15 changes: 14 additions & 1 deletion tests/pagegenerators_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,20 @@ def test_positionalargument(self):
self.assertIsNotNone(gen1)
gf2 = pagegenerators.GeneratorFactory(site=self.site)
gf2.handleArg('-page:Main Page')
gen2 = gf1.getCombinedGenerator()
gen2 = gf2.getCombinedGenerator()
self.assertIsNotNone(gen2)
self.assertEqual(list(gen1), list(gen2))

def test_positionalargument_with_colon(self):
"""Test page generator with positional argument with colon."""
gf1 = pagegenerators.GeneratorFactory(site=self.site,
positional_arg_name='page')
gf1.handleArg('Project:Main Page')
gen1 = gf1.getCombinedGenerator()
self.assertIsNotNone(gen1)
gf2 = pagegenerators.GeneratorFactory(site=self.site)
gf2.handleArg('-page:Project:Main Page')
gen2 = gf2.getCombinedGenerator()
self.assertIsNotNone(gen2)
self.assertEqual(list(gen1), list(gen2))

Expand Down

0 comments on commit ee66372

Please sign in to comment.