jenkins-bot has submitted this change and it was merged.
Change subject: [BREAK] [FEAT] SingleSiteBot and MultipleSitesBot
......................................................................
[BREAK] [FEAT] SingleSiteBot and MultipleSitesBot
Several bots can only work with pages on one site as they initialize stuff
which is site specific. In theory page generators can return pages for
different sites which can cause errors.
This also adds MultipleSitesBot which is specifically for bots that can work on
multiple sites in one run and it's not allowed to cache the site in self.site
there.
This converts all scripts which utilize Bot's run method where both new
subclasses will have an effect.
It breaks the usage of CurrentPageBot which now uses the BaseBot as the
superclass which does no site management. Instead it should be used with one of
the new subclasses or the site management should be done by the script itself.
Change-Id: I5e8759ccaef0063d6d6f9842bf3d3af3baa0f567
---
M pywikibot/bot.py
M scripts/basic.py
M scripts/capitalize_redirects.py
M scripts/category.py
M scripts/cosmetic_changes.py
M scripts/delete.py
M scripts/disambredir.py
M scripts/djvutext.py
M scripts/movepages.py
M scripts/piper.py
M scripts/protect.py
M scripts/selflink.py
M scripts/touch.py
M scripts/unlink.py
M tests/bot_tests.py
15 files changed, 299 insertions(+), 92 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 6cca348..4e8e37d 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -57,6 +57,21 @@
pywikibot.argvu = ui.argvu()
+# It's not possible to use pywikibot.exceptions.PageRelatedError as that is
+# importing pywikibot.data.api which then needs pywikibot.bot
+class SkipPageError(Exception):
+
+ """Skipped page in run."""
+
+ message = 'Page "{0}" skipped due to {1}.'
+
+ def __init__(self, page, reason):
+ """Constructor."""
+ super(SkipPageError, self).__init__(self.message.format(page, reason))
+ self.reason = reason
+ self.page = page
+
+
# Logging module configuration
class RotatingFileHandler(logging.handlers.RotatingFileHandler):
@@ -1124,7 +1139,7 @@
"""The user has cancelled processing at a prompt."""
-class Bot(object):
+class BaseBot(object):
"""
Generic Bot to be subclassed.
@@ -1159,11 +1174,6 @@
"""
if 'generator' in kwargs:
self.generator = kwargs.pop('generator')
-
- # TODO: add warning if site is specified and generator
- # contains pages from a different site.
- self._site = kwargs.pop('site', None)
- self._sites = set([self._site] if self._site else [])
self.setOptions(**kwargs)
@@ -1377,12 +1387,81 @@
raise NotImplementedError('Method %s.treat() not implemented.'
% self.__class__.__name__)
+ def init_page(self, page):
+ """Return whether treat should be executed for the page."""
+ pass
+
+ def run(self):
+ """Process all pages in generator."""
+ if not hasattr(self, 'generator'):
+ raise NotImplementedError('Variable %s.generator not set.'
+ % self.__class__.__name__)
+
+ maxint = 0
+ if sys.version_info[0] == 2:
+ maxint = sys.maxint
+
+ try:
+ for page in self.generator:
+ try:
+ self.init_page(page)
+ except SkipPageError as e:
+ pywikibot.warning('Skipped "{0}" due to: {1}'.format(
+ page, e.reason))
+ if sys.version_info[0] == 2:
+ # Python 2 does not clear the exception and it may seem
+ # that the generator stopped due to an exception
+ sys.exc_clear()
+ continue
+
+ # Process the page
+ self.treat(page)
+
+ self._treat_counter += 1
+ if maxint and self._treat_counter == maxint:
+ # Warn the user that the bot may not function correctly
+ pywikibot.error(
+ '\n%s: page count reached Python 2 sys.maxint (%d).\n'
+ 'Python 3 should be used to process very large batches'
+ % (self.__class__.__name__, sys.maxint))
+ except QuitKeyboardInterrupt:
+ pywikibot.output('\nUser quit %s bot run...' %
+ self.__class__.__name__)
+ except KeyboardInterrupt:
+ if config.verbose_output:
+ raise
+ else:
+ pywikibot.output('\nKeyboardInterrupt during %s bot run...' %
+ self.__class__.__name__)
+ finally:
+ self.exit()
+
+
+# TODO: Deprecate Bot class as self.site may be the site of the page or may be
+# a site previously defined
+class Bot(BaseBot):
+
+ """
+ Generic bot subclass for multiple sites.
+
+ If possible the MultipleSitesBot or SingleSiteBot classes should be used
+ instead which specifically handle multiple or single sites.
+ """
+
+ def __init__(self, **kwargs):
+ """Create a Bot instance and initalize cached sites."""
+ # TODO: add warning if site is specified and generator
+ # contains pages from a different site.
+ self._site = kwargs.pop('site', None)
+ self._sites = set([self._site] if self._site else [])
+
+ super(Bot, self).__init__(**kwargs)
+
@property
def site(self):
- """Site that the bot is using."""
+ """Get the current site."""
if not self._site:
warning('Bot.site was not set before being retrieved.')
- # TODO: peak at a page from the generator to determine the site
self.site = pywikibot.Site()
warning('Using the default site: %s' % self.site)
return self._site
@@ -1412,64 +1491,132 @@
self._site = site
def run(self):
- """Process all pages in generator."""
- if not hasattr(self, 'generator'):
- raise NotImplementedError('Variable %s.generator not set.'
- % self.__class__.__name__)
-
+ """Check if it automatically updates the site before run."""
# This check is to remove the possibility that the superclass changing
# self.site causes bugs in subclasses.
# If the subclass has set self.site before run(), it may be that the
# bot processes pages on sites other than self.site, and therefore
# this method cant alter self.site. To use this functionality, don't
# set self.site in __init__, and use page.site in treat().
- auto_update_site = not self._site
- if not auto_update_site:
+ self._auto_update_site = not self._site
+ if not self._auto_update_site:
warning(
'%s.__init__ set the Bot.site property; this is only needed '
'when the Bot accesses many sites.' % self.__class__.__name__)
else:
log('Bot is managing the %s.site property in run()'
% self.__class__.__name__)
+ super(Bot, self).run()
- maxint = 0
- if sys.version_info[0] == 2:
- maxint = sys.maxint
+ def init_page(self, page):
+ """Update site before calling treat."""
+ # When in auto update mode, set the site when it changes,
+ # so subclasses can hook onto changes to site.
+ if (self._auto_update_site and
+ (not self._site or page.site != self.site)):
+ self.site = page.site
- try:
- for page in self.generator:
- # When in auto update mode, set the site when it changes,
- # so subclasses can hook onto changes to site.
- if (auto_update_site and
- (not self._site or page.site != self.site)):
- self.site = page.site
- # Process the page
- self.treat(page)
+class SingleSiteBot(BaseBot):
- self._treat_counter += 1
- if maxint and self._treat_counter == maxint:
- # Warn the user that the bot may not function correctly
- pywikibot.error(
- '\n%s: page count reached Python 2 sys.maxint (%d).\n'
- 'Python 3 should be used to process very large batches'
- % (self.__class__.__name__, sys.maxint))
- except QuitKeyboardInterrupt:
- pywikibot.output('\nUser quit %s bot run...' %
- self.__class__.__name__)
- except KeyboardInterrupt:
- if config.verbose_output:
- raise
+ """
+ A bot only working on one site and ignoring the others.
+
+ If no site is given from the start it'll use the first page's site. Any
page
+ after the site has been defined and is not on the defined site will be
+ ignored.
+ """
+
+ def __init__(self, site=True, **kwargs):
+ """
+ Create a SingleSiteBot instance.
+
+ @param site: If True it'll be set to the configured site using
+ pywikibot.Site.
+ @type site: True or None or Site
+ """
+ if site is True:
+ site = pywikibot.Site()
+ self._site = site
+ super(SingleSiteBot, self).__init__(**kwargs)
+
+ @property
+ def site(self):
+ """Site that the bot is using."""
+ if not self._site:
+ raise ValueError('The site has not been defined yet.')
+ return self._site
+
+ @site.setter
+ def site(self, value):
+ """Set the current site but warns if different."""
+ if self._site:
+ # Warn in any case where the site is (probably) changed after
+ # setting it the first time. The appropriate variant is not to use
+ # self.site at all or define it once and never change it again
+ if self._site == value:
+ pywikibot.warning('Defined site without changing it.')
else:
- pywikibot.output('\nKeyboardInterrupt during %s bot run...' %
- self.__class__.__name__)
- finally:
- self.exit()
+ pywikibot.warning('Changed the site from "{0}" to '
+ '"{1}"'.format(self._site, value))
+ self._site = value
+
+ def init_page(self, page):
+ """Set site if not defined and return if it's on the defined site."""
+ if not self._site:
+ self.site = page.site
+ elif page.site != self.site:
+ raise SkipPageError(page,
+ 'The bot is on site "{0}" but the page on '
+ 'site "{1}"'.format(self.site, page.site))
-class CurrentPageBot(Bot):
+class MultipleSitesBot(BaseBot):
- """A bot which automatically sets 'current_page' on each treat()."""
+ """
+ A bot class working on multiple sites.
+
+ The bot should accommodate for that case and not store site specific
+ information on only one site.
+ """
+
+ def __init__(self, **kwargs):
+ """Constructor."""
+ self._site = None
+ super(MultipleSitesBot, self).__init__(**kwargs)
+
+ @property
+ @deprecated("the page's site property")
+ def site(self):
+ """
+ Return the site if it's set and ValueError otherwise.
+
+ The site is only defined while in treat and it is preferred to use
+ the page's site instead.
+ """
+ if self._site is None:
+ raise ValueError('Requesting the site not while in treat is not '
+ 'allowed.')
+ return self._site
+
+ def run(self):
+ """Reset the bot's site after run."""
+ super(MultipleSitesBot, self).run()
+ self._site = None
+
+ def init_page(self, page):
+ """Define the site for this page."""
+ self._site = page.site
+
+
+class CurrentPageBot(BaseBot):
+
+ """
+ A bot which automatically sets 'current_page' on each treat().
+
+ This class should be always used together with either the MultipleSitesBot
+ or SingleSiteBot class as there is no site managment in this class.
+ """
ignore_save_related_errors = True
ignore_server_errors = False
diff --git a/scripts/basic.py b/scripts/basic.py
index 192d85f..7582c97 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -26,8 +26,9 @@
#
import pywikibot
-from pywikibot import i18n, pagegenerators, Bot
+from pywikibot import i18n, pagegenerators
+from pywikibot.bot import SingleSiteBot
from pywikibot.tools import issue_deprecation_warning
# This is required for the text that is shown when you run this script
@@ -37,7 +38,7 @@
}
-class BasicBot(Bot):
+class BasicBot(SingleSiteBot):
"""An incomplete sample bot."""
@@ -59,12 +60,11 @@
if dry:
issue_deprecation_warning('dry argument',
'pywikibot.config.simulate', 1)
pywikibot.config.simulate = True
- super(BasicBot, self).__init__(**kwargs)
+ super(BasicBot, self).__init__(site=True, **kwargs)
self.generator = generator
# Set the edit summary message
- site = pywikibot.Site()
- self.summary = i18n.twtranslate(site, 'basic-changing')
+ self.summary = i18n.twtranslate(self.site, 'basic-changing')
def treat(self, page):
"""Load the given page, does some changes, and saves it."""
diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py
index 01746de..82b93c0 100755
--- a/scripts/capitalize_redirects.py
+++ b/scripts/capitalize_redirects.py
@@ -36,14 +36,16 @@
import pywikibot
from pywikibot import i18n, pagegenerators
-from pywikibot.bot import FollowRedirectPageBot, ExistingPageBot
+from pywikibot.bot import (
+ MultipleSitesBot, FollowRedirectPageBot, ExistingPageBot
+)
docuReplacements = {
'¶ms;': pagegenerators.parameterHelp
}
-class CapitalizeBot(FollowRedirectPageBot, ExistingPageBot):
+class CapitalizeBot(MultipleSitesBot, FollowRedirectPageBot, ExistingPageBot):
"""Capitalization Bot."""
diff --git a/scripts/category.py b/scripts/category.py
index 0741fa5..bda9623 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -124,9 +124,9 @@
import sys
import pywikibot
-from pywikibot import Bot
from pywikibot import config, pagegenerators
from pywikibot import i18n, textlib
+from pywikibot.bot import MultipleSitesBot
from pywikibot.tools import (
deprecated_args, deprecated, ModuleDeprecationWrapper
)
@@ -282,7 +282,7 @@
% config.shortpath(filename))
-class CategoryAddBot(Bot):
+class CategoryAddBot(MultipleSitesBot):
"""A robot to mass-add a category to a list of pages."""
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index c7e1934..3aff85f 100644
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -36,7 +36,7 @@
import pywikibot
from pywikibot import i18n, pagegenerators, cosmetic_changes
-from pywikibot.bot import ExistingPageBot, NoRedirectPageBot
+from pywikibot.bot import MultipleSitesBot, ExistingPageBot, NoRedirectPageBot
warning = """
@@ -51,7 +51,7 @@
}
-class CosmeticChangesBot(ExistingPageBot, NoRedirectPageBot):
+class CosmeticChangesBot(MultipleSitesBot, ExistingPageBot, NoRedirectPageBot):
"""Cosmetic changes bot."""
diff --git a/scripts/delete.py b/scripts/delete.py
index ed27a1e..0391072 100755
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -41,7 +41,8 @@
import pywikibot
from pywikibot import exceptions
-from pywikibot import i18n, pagegenerators, CurrentPageBot
+from pywikibot import i18n, pagegenerators
+from pywikibot.bot import MultipleSitesBot, CurrentPageBot
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -50,7 +51,7 @@
}
-class DeletionRobot(CurrentPageBot):
+class DeletionRobot(MultipleSitesBot, CurrentPageBot):
"""This robot allows deletion of pages en masse."""
diff --git a/scripts/disambredir.py b/scripts/disambredir.py
index 741081f..4673238 100755
--- a/scripts/disambredir.py
+++ b/scripts/disambredir.py
@@ -22,7 +22,7 @@
import pywikibot
from pywikibot import i18n, textlib, pagegenerators
-from pywikibot.bot import CurrentPageBot, InteractiveReplace
+from pywikibot.bot import MultipleSitesBot, CurrentPageBot, InteractiveReplace
msg = {
'ar': u'تغيير التحويلات في صفحة توضيح',
@@ -40,7 +40,7 @@
}
-class DisambiguationRedirectBot(CurrentPageBot):
+class DisambiguationRedirectBot(MultipleSitesBot, CurrentPageBot):
"""Change redirects from disambiguation pages."""
diff --git a/scripts/djvutext.py b/scripts/djvutext.py
index 3e274af..688b19a 100644
--- a/scripts/djvutext.py
+++ b/scripts/djvutext.py
@@ -40,12 +40,13 @@
import pywikibot
-from pywikibot import i18n, Bot
+from pywikibot import i18n
+from pywikibot.bot import SingleSiteBot
from pywikibot.tools.djvu import DjVuFile
from pywikibot.proofreadpage import ProofreadPage
-class DjVuTextBot(Bot):
+class DjVuTextBot(SingleSiteBot):
"""
A bot that uploads text-layer from djvu files to Page:namespace.
@@ -68,7 +69,7 @@
'force': False,
'summary': None
})
- super(DjVuTextBot, self).__init__(**kwargs)
+ super(DjVuTextBot, self).__init__(site=index.site, **kwargs)
self._djvu = djvu
self._index = index
self._prefix = self._index.title(withNamespace=False)
diff --git a/scripts/movepages.py b/scripts/movepages.py
index 300f2e0..a27837a 100755
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -45,7 +45,8 @@
import re
import pywikibot
-from pywikibot import i18n, pagegenerators, Bot
+from pywikibot import i18n, pagegenerators
+from pywikibot.bot import MultipleSitesBot
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -54,7 +55,7 @@
}
-class MovePagesBot(Bot):
+class MovePagesBot(MultipleSitesBot):
"""Page move bot."""
diff --git a/scripts/piper.py b/scripts/piper.py
index ecb4c4f..7303bde 100755
--- a/scripts/piper.py
+++ b/scripts/piper.py
@@ -45,7 +45,7 @@
import pywikibot
from pywikibot import i18n, pagegenerators
-from pywikibot.bot import ExistingPageBot, NoRedirectPageBot
+from pywikibot.bot import MultipleSitesBot, ExistingPageBot, NoRedirectPageBot
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -54,7 +54,7 @@
}
-class PiperBot(ExistingPageBot, NoRedirectPageBot):
+class PiperBot(MultipleSitesBot, ExistingPageBot, NoRedirectPageBot):
"""Bot for munging text using external filtering programs."""
diff --git a/scripts/protect.py b/scripts/protect.py
index d82367c..750c1cf 100755
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -44,7 +44,7 @@
# Written by https://it.wikisource.org/wiki/Utente:Qualc1
# Created by modifying delete.py
#
-# (C) Pywikibot team, 2008-2014
+# (C) Pywikibot team, 2008-2015
#
# Distributed under the terms of the MIT license.
#
@@ -54,7 +54,8 @@
#
import pywikibot
-from pywikibot import i18n, pagegenerators, Bot
+from pywikibot import i18n, pagegenerators
+from pywikibot.bot import SingleSiteBot
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -63,11 +64,11 @@
}
-class ProtectionRobot(Bot):
+class ProtectionRobot(SingleSiteBot):
"""This bot allows protection of pages en masse."""
- def __init__(self, generator, protections, **kwargs):
+ def __init__(self, generator, protections, site=None, **kwargs):
"""
Create a new ProtectionRobot.
@@ -75,12 +76,16 @@
@type generator: generator
@param protections: protections as a dict with "type": "level"
@type protections: dict
+ @param site: The site to which the protections apply. By default it's
+ using the site of the first page returned from the generator. If
+ True it's using the configured site.
+ @type site: None, True or Site
@param kwargs: additional arguments directly feed to Bot.__init__()
"""
self.availableOptions.update({
'summary': None,
})
- super(ProtectionRobot, self).__init__(**kwargs)
+ super(ProtectionRobot, self).__init__(site=site, **kwargs)
self.generator = generator
self.protections = protections
@@ -243,7 +248,7 @@
if not options.get('summary'):
options['summary'] = pywikibot.input(
u'Enter a reason for the protection change:')
- bot = ProtectionRobot(generator, combined_protections, **options)
+ bot = ProtectionRobot(generator, combined_protections, site, **options)
bot.run()
else:
# Show help text from the top of this file
diff --git a/scripts/selflink.py b/scripts/selflink.py
index b577d9f..961f696 100755
--- a/scripts/selflink.py
+++ b/scripts/selflink.py
@@ -11,7 +11,7 @@
ATTENTION: Use this with care!
"""
#
-# (C) Pywikibot team, 2006-2014
+# (C) Pywikibot team, 2006-2015
#
# Distributed under the terms of the MIT license.
#
@@ -19,7 +19,8 @@
import re
import pywikibot
-from pywikibot import i18n, Bot
+from pywikibot import i18n
+from pywikibot.bot import SingleSiteBot
from pywikibot.editor import TextEditor
from pywikibot.pagegenerators import GeneratorFactory, PreloadingGenerator, \
parameterHelp
@@ -31,14 +32,14 @@
}
-class SelflinkBot(Bot):
+class SelflinkBot(SingleSiteBot):
"""Self-link removal bot."""
def __init__(self, generator, **kwargs):
super(SelflinkBot, self).__init__(**kwargs)
self.generator = generator
- linktrail = pywikibot.Site().linktrail()
+ linktrail = self.site.linktrail()
# The regular expression which finds links. Results consist of four
# groups:
# group title is the target page title, everything before | or ].
diff --git a/scripts/touch.py b/scripts/touch.py
index 286d091..20dad4c 100755
--- a/scripts/touch.py
+++ b/scripts/touch.py
@@ -25,11 +25,12 @@
import pywikibot
from pywikibot import pagegenerators
+from pywikibot.bot import MultipleSitesBot
docuReplacements = {'¶ms;': pagegenerators.parameterHelp}
-class TouchBot(pywikibot.Bot):
+class TouchBot(MultipleSitesBot):
"""Page touch bot."""
@@ -52,7 +53,7 @@
% page.title(asLink=True))
-class PurgeBot(pywikibot.Bot):
+class PurgeBot(MultipleSitesBot):
"""Purge each page on the generator."""
diff --git a/scripts/unlink.py b/scripts/unlink.py
index 32256e4..a5deb82 100755
--- a/scripts/unlink.py
+++ b/scripts/unlink.py
@@ -21,7 +21,7 @@
Removes links to the page [[Foo bar]] in articles and image descriptions.
"""
#
-# (C) Pywikibot team, 2007-2014
+# (C) Pywikibot team, 2007-2015
#
# Distributed under the terms of the MIT license.
#
@@ -33,10 +33,11 @@
import re
import pywikibot
from pywikibot.editor import TextEditor
-from pywikibot import i18n, Bot
+from pywikibot import i18n
+from pywikibot.bot import SingleSiteBot
-class UnlinkBot(Bot):
+class UnlinkBot(SingleSiteBot):
"""Page unlinking bot."""
@@ -48,7 +49,7 @@
# default to [] which means all namespaces will be processed
})
- super(UnlinkBot, self).__init__(**kwargs)
+ super(UnlinkBot, self).__init__(site=pageToUnlink.site, **kwargs)
self.pageToUnlink = pageToUnlink
linktrail = self.pageToUnlink.site.linktrail()
diff --git a/tests/bot_tests.py b/tests/bot_tests.py
index c8b8316..b2a9a7c 100644
--- a/tests/bot_tests.py
+++ b/tests/bot_tests.py
@@ -34,11 +34,15 @@
"""
def treat(page):
self.assertEqual(page, next(self._page_iter))
- self.assertIsNotNone(self.bot._site)
- self.assertEqual(self.bot.site, self.bot._site)
- if self._treat_site:
- self.assertEqual(self.bot._site, self._treat_site)
- self.assertEqual(page.site, self.bot.site)
+ if self._treat_site is None:
+ self.assertFalse(hasattr(self.bot, 'site'))
+ self.assertFalse(hasattr(self.bot, '_site'))
+ else:
+ self.assertIsNotNone(self.bot._site)
+ self.assertEqual(self.bot.site, self.bot._site)
+ if self._treat_site:
+ self.assertEqual(self.bot._site, self._treat_site)
+ self.assertEqual(page.site, self.bot.site)
if post_treat:
post_treat(page)
self._page_iter = iter(pages)
@@ -105,6 +109,49 @@
yield pywikibot.Page(self.de, 'Page 3')
yield pywikibot.Page(self.en, 'Page 4')
+ def test_SingleSiteBot_automatic(self):
+ """Test SingleSiteBot class with no predefined site."""
+ self._treat_site = self.de
+ self.bot = pywikibot.bot.SingleSiteBot(site=None,
+ generator=self._generator())
+ self.bot.treat = self._treat([pywikibot.Page(self.de, 'Page 1'),
+ pywikibot.Page(self.de, 'Page 3')])
+ self.bot.exit = self._exit(2)
+ self.bot.run()
+ self.assertEqual(self.bot.site, self._treat_site)
+
+ def test_SingleSiteBot_specific(self):
+ """Test SingleSiteBot class with predefined site."""
+ self._treat_site = self.en
+ self.bot = pywikibot.bot.SingleSiteBot(site=self.en,
+ generator=self._generator())
+ self.bot.treat = self._treat([pywikibot.Page(self.en, 'Page 2'),
+ pywikibot.Page(self.en, 'Page 4')])
+ self.bot.exit = self._exit(2)
+ self.bot.run()
+ self.assertEqual(self.bot.site, self._treat_site)
+
+ def test_MultipleSitesBot(self):
+ """Test MultipleSitesBot class."""
+ # Assert no specific site
+ self._treat_site = False
+ self.bot = pywikibot.bot.MultipleSitesBot(generator=self._generator())
+ with self.assertRaises(AttributeError):
+ self.bot.site = self.de
+ with self.assertRaises(ValueError):
+ self.bot.site
+ if sys.version_info[0] == 2:
+ # The exc_info still contains the AttributeError :/
+ sys.exc_clear()
+ self.bot.treat = self._treat(self._generator())
+ self.bot.exit = self._exit(4)
+ self.bot.run()
+ with self.assertRaises(ValueError):
+ self.bot.site
+ if sys.version_info[0] == 2:
+ # The exc_info still contains the AttributeError :/
+ sys.exc_clear()
+
def test_Bot(self):
"""Test normal Bot class."""
# Assert no specific site
@@ -119,7 +166,7 @@
def post_treat(page):
self.assertIs(self.bot.current_page, page)
# Assert no specific site
- self._treat_site = False
+ self._treat_site = None
self.bot = pywikibot.bot.CurrentPageBot(generator=self._generator())
self.bot.treat_page = self._treat_page(self._generator(), post_treat)
self.bot.exit = self._exit(4)
@@ -198,7 +245,7 @@
"""Verify the page exists."""
self.assertTrue(page.exists())
- self._treat_site = False
+ self._treat_site = None
self.bot = pywikibot.bot.ExistingPageBot(
generator=self._missing_generator())
self.bot.treat_page = self._treat_page(post_treat=post_treat)
@@ -217,7 +264,7 @@
"""Verify the page is missing."""
self.assertFalse(page.exists())
- self._treat_site = False
+ self._treat_site = None
self.bot = pywikibot.bot.CreatingPageBot(
generator=self._missing_generator())
self.bot.treat_page = self._treat_page(treat_generator(), post_treat)
--
To view, visit https://gerrit.wikimedia.org/r/218313
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5e8759ccaef0063d6d6f9842bf3d3af3baa0f567
Gerrit-PatchSet: 12
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits