jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/787450 )
Change subject: [bugfix] clear _sites cache if called with pwb wrapper
......................................................................
[bugfix] clear _sites cache if called with pwb wrapper
Also update tests
Bug: T225594
Change-Id: I2a7d5578ae4cc85ff203f9687e500868cc67c8a1
---
M pywikibot/bot.py
M tests/__init__.py
M tests/reflinks_tests.py
M tests/replacebot_tests.py
4 files changed, 20 insertions(+), 31 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 5183905..1f94eca 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -966,6 +966,8 @@
except (UnknownFamilyError, UnknownSiteError):
pywikibot.exception()
sys.exit(1)
+ if calledModuleName() == 'pwb':
+ pywikibot._sites.clear()
if username:
config.usernames[config.family][config.mylang] = username
diff --git a/tests/__init__.py b/tests/__init__.py
index 58aac5e..c5295ad 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -35,13 +35,7 @@
_root_dir = os.path.split(os.path.split(__file__)[0])[0]
-# common warn() clauses...
-#
-# WARN_SITE_CODE is from T234147
-# WARN_SITE_OBJ is from T225594
-
-WARN_SITE_CODE = r'^Site .*:.* instantiated using different code *'
-WARN_SITE_OBJ = 'Site objects have been created before arguments were handled'
+WARN_SITE_CODE = '^Site .*:.* instantiated using different code *' # T234147
def join_root_path(*names):
diff --git a/tests/reflinks_tests.py b/tests/reflinks_tests.py
index 0098d16..f6768e9 100755
--- a/tests/reflinks_tests.py
+++ b/tests/reflinks_tests.py
@@ -7,9 +7,8 @@
#
import unittest
-from pywikibot.tools import suppress_warnings
from scripts.reflinks import ReferencesRobot, XmlDumpPageGenerator, main
-from tests import WARN_SITE_OBJ, join_xml_data_path
+from tests import join_xml_data_path
from tests.aspects import ScriptMainTestCase, TestCase
from tests.utils import empty_sites
@@ -126,13 +125,11 @@
def test_xml_multiple_namespace_ids(self):
"""Test the generator using multiple separate namespaces
parameters."""
- with suppress_warnings(WARN_SITE_OBJ, category=UserWarning):
- main('-xml:' + join_xml_data_path('dummy-reflinks.xml'),
- '-namespace:0', '-namespace:1', '-xmlstart:Fake
page')
- gen = self.constructor_kwargs['generator']
- self.assertPageTitlesCountEqual(gen, ['Fake page',
- 'Talk:Fake page'],
- site=self.get_site())
+ main('-xml:' + join_xml_data_path('dummy-reflinks.xml'),
+ '-namespace:0', '-namespace:1', '-xmlstart:Fake
page')
+ gen = self.constructor_kwargs['generator']
+ self.assertPageTitlesCountEqual(gen, ['Fake page', 'Talk:Fake
page'],
+ site=self.get_site())
def test_xml_multiple_namespace_ids_2(self):
"""Test the generator using multiple namespaces in one
parameter."""
@@ -152,13 +149,12 @@
filename = '-xml:' + join_xml_data_path('dummy-reflinks.xml')
for start in start_variants:
- with self.subTest(xmlstart=start):
- with suppress_warnings(WARN_SITE_OBJ, category=UserWarning):
- main(filename, '-namespace:1', start)
- gen = self.constructor_kwargs['generator']
- pages = list(gen)
- self.assertPageTitlesEqual(pages, ['Talk:Fake page'],
- site=self.site)
+ with self.subTest(xmlstart=start), empty_sites():
+ main(filename, '-namespace:1', start)
+ gen = self.constructor_kwargs['generator']
+ pages = list(gen)
+ self.assertPageTitlesEqual(pages, ['Talk:Fake page'],
+ site=self.site)
def test_xml_namespace_name(self):
"""Test the generator using a namespace name."""
diff --git a/tests/replacebot_tests.py b/tests/replacebot_tests.py
index a4ac228..203b5e9 100755
--- a/tests/replacebot_tests.py
+++ b/tests/replacebot_tests.py
@@ -10,9 +10,8 @@
import pywikibot
from pywikibot import fixes
-from pywikibot.tools import suppress_warnings
from scripts import replace
-from tests import WARN_SITE_OBJ, join_data_path
+from tests import join_data_path
from tests.bot_tests import TWNBotTestCase
from tests.utils import empty_sites
@@ -90,13 +89,11 @@
def _run(self, *args):
"""Run the :py:obj:`replace.main` with the given args.
- It also adds -site and -page parameter.
+ It also adds -site and -page parameters:
+ -page to not have an empty generator
+ -site as it will use Site() otherwise
"""
- # -page to not have an empty generator
- # -site as it will use Site() otherwise
- with suppress_warnings(WARN_SITE_OBJ, category=UserWarning):
- return replace.main(*(args + ('-site:wikipedia:test',
- '-page:TEST')))
+ return replace.main(*(args + ('-site:wikipedia:test',
'-page:TEST')))
def test_invalid_replacements(self):
"""Test invalid command line replacement
configurations."""
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/787450
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I2a7d5578ae4cc85ff203f9687e500868cc67c8a1
Gerrit-Change-Number: 787450
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged