jenkins-bot has submitted this change and it was merged.
Change subject: site.py: raise NoPage instead of Error ......................................................................
site.py: raise NoPage instead of Error
In site.movepage() raise NoPage instead of Error if no page exists. This can be a problem for scripts that expect the proper exception. E.g. movepages.py expects NoPage to be raised.
Added test in site_tests.py. Also reordered imports in site_tests.py.
Change-Id: Ie89ec7dc8bd4ee99af4c8e51a779fedb52e098da --- M pywikibot/site.py M tests/site_tests.py 2 files changed, 15 insertions(+), 5 deletions(-)
Approvals: XZise: Looks good to me, but someone else must approve Ladsgroup: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index a19afa5..b125b54 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3530,8 +3530,8 @@ raise Error("Cannot move page %s to its own title." % oldtitle) if not page.exists(): - raise Error("Cannot move page %s because it does not exist on %s." - % (oldtitle, self)) + raise NoPage("Cannot move page %s because it does not exist on %s." + % (oldtitle, self)) token = self.token(page, "move") self.lock_page(page) req = api.Request(site=self, action="move", to=newtitle, diff --git a/tests/site_tests.py b/tests/site_tests.py index b4e0540..3477872 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -8,14 +8,16 @@ __version__ = '$Id$'
+import sys from distutils.version import LooseVersion as LV from collections import Iterable -import pywikibot -from tests.utils import PywikibotTestCase, unittest from datetime import datetime import re
-import sys +import pywikibot +from pywikibot.exceptions import Error, NoPage +from tests.utils import PywikibotTestCase, unittest + if sys.version_info[0] > 2: basestring = (str, )
@@ -1035,6 +1037,14 @@ self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).values())) self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).keys()))
+ def test_movepage(self): + self.assertRaises(Error, mysite.movepage, mainpage, 'Main Page', 'test') + + page_from = pywikibot.Page(mysite, 'Not exiting page') + if not page_from.exists(): + self.assertRaises(NoPage, mysite.movepage, + page_from, 'Main Page', 'test') +
class TestSiteLoadRevisions(PywikibotTestCase):
pywikibot-commits@lists.wikimedia.org