jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/405262 )
Change subject: Fix or suppress some of the expected warnings during dry tests
......................................................................
Fix or suppress some of the expected warnings during dry tests
api_tests.py:
- TestDryPageGenerator.setUp: The `titles` parameter is handled through
Request.clean_kwargs which issues a DeprecationWarning about using
parameters isntead. Do it to avoid the warning.
- test_mixed_mode: Suppress parameters related warnings.
pywikibot.diff.html_comparator:
- Explicitly use html.parser to avoid "bs4/__init__.py:181: UserWarning:
No parser was explicitly specified"
+ Similar suppressions in other dry test modules.
Bug: T185296
Change-Id: Ib108e513b66112956c19ce62746510e34c594a93
---
M pywikibot/diff.py
M tests/api_tests.py
M tests/bot_tests.py
M tests/dry_api_tests.py
M tests/http_tests.py
M tests/i18n_tests.py
M tests/textlib_tests.py
7 files changed, 49 insertions(+), 26 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index e7f029d..636be64 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Diff module."""
#
-# (C) Pywikibot team, 2014-2015
+# (C) Pywikibot team, 2014-2018
#
# Distributed under the terms of the MIT license.
#
@@ -607,7 +607,7 @@
from bs4 import BeautifulSoup
comparands = {'deleted-context': [], 'added-context': []}
- soup = BeautifulSoup(compare_string)
+ soup = BeautifulSoup(compare_string, 'html.parser')
for change_type, css_class in (('deleted-context',
'diff-deletedline'),
('added-context', 'diff-addedline')):
crutons = soup.find_all('td', class_=css_class)
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 7906847..c185ff5 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""API test module."""
#
-# (C) Pywikibot team, 2007-2016
+# (C) Pywikibot team, 2007-2018
#
# Distributed under the terms of the MIT license.
#
@@ -18,6 +18,7 @@
from pywikibot.throttle import Throttle
from pywikibot.tools import (
+ suppress_warnings,
MediaWikiVersion,
PY2,
UnicodeType,
@@ -143,6 +144,9 @@
for item in req.items():
self.assertEqual(len(item), 2, item)
+ @suppress_warnings(
+ 'Instead of using kwargs |Both kwargs and parameters are set',
+ DeprecationWarning)
def test_mixed_mode(self):
"""Test if parameters is used with kwargs."""
req1 = api.Request(site=self.site, action='test',
parameters='foo')
@@ -570,7 +574,7 @@
mysite = self.get_site()
self.gen = api.PageGenerator(site=mysite,
generator="links",
- titles="User:R'n'B")
+ parameters={'titles':
"User:R'n'B"})
# following test data is copied from an actual api.php response,
# but that query no longer matches this dataset.
#
http://en.wikipedia.org/w/api.php?action=query&generator=links&titl…
diff --git a/tests/bot_tests.py b/tests/bot_tests.py
index 47c3618..5cfade3 100644
--- a/tests/bot_tests.py
+++ b/tests/bot_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Bot tests."""
#
-# (C) Pywikibot team, 2015
+# (C) Pywikibot team, 2015-2018
#
# Distributed under the terms of the MIT license.
#
@@ -13,7 +13,7 @@
import pywikibot.bot
from pywikibot import i18n
-from pywikibot.tools import PY2
+from pywikibot.tools import PY2, suppress_warnings
from tests.aspects import (
unittest, DefaultSiteTestCase, SiteAttributeTestCase, TestCase,
@@ -222,6 +222,7 @@
self.bot.run()
self.assertEqual(self.bot.site, self._treat_site)
+ @suppress_warnings('pywikibot.bot.MultipleSitesBot.site is deprecated')
def test_MultipleSitesBot(self):
"""Test MultipleSitesBot class."""
# Assert no specific site
diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py
index ed405af..8cef292 100644
--- a/tests/dry_api_tests.py
+++ b/tests/dry_api_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""API tests which do not interact with a site."""
#
-# (C) Pywikibot team, 2012-2014
+# (C) Pywikibot team, 2012-2018
#
# Distributed under the terms of the MIT license.
#
@@ -17,8 +17,9 @@
QueryGenerator,
)
from pywikibot.family import Family
+from pywikibot.tools import suppress_warnings
-from tests import join_images_path
+from tests import join_images_path, patch
from tests.utils import DummySiteinfo
from tests.aspects import (
unittest, TestCase, DefaultDrySiteTestCase, SiteAttributeTestCase,
@@ -58,10 +59,11 @@
expiry=1, site=self.altsite,
parameters={'action': 'query', 'meta':
'userinfo'})
# When using ** the paramters are still unicode
- self.deprecated_explicit = CachedRequest(
- expiry=1, site=self.basesite, action='query',
meta='userinfo')
- self.deprecated_asterisks = CachedRequest(
- expiry=1, site=self.basesite, **self.parms)
+ with suppress_warnings('Instead of using kwargs ', DeprecationWarning):
+ self.deprecated_explicit = CachedRequest(
+ expiry=1, site=self.basesite, action='query',
meta='userinfo')
+ self.deprecated_asterisks = CachedRequest(
+ expiry=1, site=self.basesite, **self.parms)
def test_expiry_formats(self):
"""Test using a timedelta as expiry."""
@@ -250,8 +252,9 @@
site = self.get_site()
site._userinfo = {'name': 'other_username', 'groups':
[]}
site._username[0] = 'myusername'
-
- Request(site=site, parameters={'action': 'edit'})
+ # Ignore warning: API write action by unexpected username commenced.
+ with patch('pywikibot.warning'):
+ Request(site=site, parameters={'action': 'edit'})
def test_normal(self):
"""Test Request object when username is
correct."""
diff --git a/tests/http_tests.py b/tests/http_tests.py
index bd296c8..f0829a7 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Tests for http module."""
#
-# (C) Pywikibot team, 2014-2017
+# (C) Pywikibot team, 2014-2018
#
# Distributed under the terms of the MIT license.
#
@@ -19,10 +19,11 @@
from pywikibot.comms import http, threadedhttp
from pywikibot.tools import (
PYTHON_VERSION,
+ suppress_warnings,
UnicodeType as unicode,
)
-from tests import join_images_path
+from tests import join_images_path, patch
from tests.aspects import (
unittest,
TestCase,
@@ -123,8 +124,12 @@
'https://wmflabs.org': None,
'https://www.wikiquote.org/': None,
}
- for url, auth in pairs.items():
- self.assertEqual(http.get_authentication(url), auth)
+ with suppress_warnings(
+ r'config.authenticate\["\*.wmflabs.org"] has invalid
value.',
+ UserWarning,
+ ):
+ for url, auth in pairs.items():
+ self.assertEqual(http.get_authentication(url), auth)
class HttpsCertificateTestCase(TestCase):
@@ -546,7 +551,9 @@
"""Test decoding with different charsets and valid header
charset."""
req = CharsetTestCase._create_request('latin1')
self.assertEqual('latin1', req.charset)
- self.assertEqual('utf-8', req.encoding)
+ # Ignore WARNING: Encoding "latin1" requested but "utf-8"
received
+ with patch('pywikibot.warning'):
+ self.assertEqual('utf-8', req.encoding)
self.assertEqual(req.raw, CharsetTestCase.UTF8_BYTES)
self.assertEqual(req.content, CharsetTestCase.STR)
@@ -555,7 +562,9 @@
req = CharsetTestCase._create_request('latin1',
CharsetTestCase.LATIN1_BYTES)
self.assertEqual('latin1', req.charset)
- self.assertEqual('latin1', req.encoding)
+ # Ignore WARNING: Encoding "latin1" requested but "utf-8"
received
+ with patch('pywikibot.warning'):
+ self.assertEqual('latin1', req.encoding)
self.assertEqual(req.raw, CharsetTestCase.LATIN1_BYTES)
self.assertEqual(req.content, CharsetTestCase.STR)
@@ -564,7 +573,11 @@
req = CharsetTestCase._create_request('utf16',
CharsetTestCase.LATIN1_BYTES)
self.assertEqual('utf16', req.charset)
- self.assertRaisesRegex(UnicodeDecodeError, self.CODEC_CANT_DECODE_RE, lambda:
req.encoding)
+ # Ignore WARNING: Encoding "utf16" requested but "utf-8"
received
+ with patch('pywikibot.warning'):
+ self.assertRaisesRegex(
+ UnicodeDecodeError, self.CODEC_CANT_DECODE_RE,
+ lambda: req.encoding)
self.assertEqual(req.raw, CharsetTestCase.LATIN1_BYTES)
self.assertRaisesRegex(UnicodeDecodeError, self.CODEC_CANT_DECODE_RE, lambda:
req.content)
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index 12374f8..8b05058 100644
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Test i18n module."""
#
-# (C) Pywikibot team, 2007-2014
+# (C) Pywikibot team, 2007-2018
#
# Distributed under the terms of the MIT license.
#
@@ -336,7 +336,7 @@
u'Robot: Changer seulement une page.')
-class ScriptMessagesTestCase(TWNTestCaseBase):
+class ScriptMessagesTestCase(TWNTestCaseBase, AutoDeprecationTestCase):
"""Real messages test."""
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 476a7ba..6744d0b 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -18,7 +18,7 @@
from pywikibot import config, UnknownSite
from pywikibot.site import _IWEntry
-from pywikibot.tools import OrderedDict
+from pywikibot.tools import OrderedDict, suppress_warnings
from tests.aspects import (
unittest, require_modules, TestCase, DefaultDrySiteTestCase,
@@ -580,7 +580,8 @@
self.assertIsNone(func('{{a|{{c}} }}'))
self.assertIsNone(func('{{a|{{c|d}} }}'))
- func = textlib.TEMP_REGEX.search
+ with suppress_warnings('textlib.TEMP_REGEX is deprecated'):
+ func = textlib.TEMP_REGEX.search
self.assertIsNotNone(func('{{{1}}}'))
self.assertIsNotNone(func('{{a|b={{c}} }}'))
@@ -588,7 +589,8 @@
self.assertIsNotNone(func('{{a|{{c}} }}'))
self.assertIsNotNone(func('{{a|{{c|d}} }}'))
- func = textlib.TEMP_REGEX.match
+ with suppress_warnings('textlib.TEMP_REGEX is deprecated'):
+ func = textlib.TEMP_REGEX.match
self.assertIsNotNone(func('{{#if:foo}}'))
self.assertIsNotNone(func('{{foo:}}'))
--
To view, visit
https://gerrit.wikimedia.org/r/405262
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib108e513b66112956c19ce62746510e34c594a93
Gerrit-PatchSet: 14
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>