jenkins-bot merged this change.

View Change

Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
[bugfix] Refactor TestObsoleteSite

- use DefaultSiteTestCase and instantiate a Site in each test method
- use suppress_warnings if needed instead of mocking setUpClass
- take into account that closed sites has a ClosedSite interface

Bug: T225459
Change-Id: I97c2e4dabcacf74d5abfbf3bee84f8a0200b8fd8
---
M tests/site_tests.py
1 file changed, 8 insertions(+), 35 deletions(-)

diff --git a/tests/site_tests.py b/tests/site_tests.py
index 6c177b5..e94296e 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -3349,48 +3349,19 @@
self.assertFalse(site.sametitle('Invalid:Foo', 'Invalid:foo'))


-class TestObsoleteSite(TestCase):
+class TestObsoleteSite(DefaultSiteTestCase):

"""Test 'closed' and obsolete code sites."""

- # hostname() fails, so it is provided here otherwise the
- # test class fails with hostname not defined for mh.wikipedia.org
- sites = {
- 'mhwp': {
- 'family': 'wikipedia',
- 'code': 'mh',
- 'hostname': 'mh.wikipedia.org',
- },
- # pywikibot should never attempt to access jp.wikipedia.org,
- # however this entry ensures that there is a change in the builds
- # if jp.wikipedia.org goes offline.
- 'jpwp': {
- 'family': 'wikipedia',
- 'code': 'jp',
- 'hostname': 'jp.wikipedia.org',
- },
- 'jawp': {
- 'family': 'wikipedia',
- 'code': 'ja',
- },
- }
-
- @classmethod
- def setUpClass(cls):
- """Setup the class."""
- with patch.object(pywikibot, 'warn') as warn_mock:
- super(TestObsoleteSite, cls).setUpClass()
- warn_mock.assert_called_once_with(
- 'Site wikipedia:ja instantiated using different code "jp"',
- UserWarning, 2)
-
def test_locked_site(self):
"""Test Wikimedia closed/locked site."""
- site = self.get_site('mhwp')
+ with suppress_warnings('Interwiki removal mh is in wikipedia codes'):
+ site = pywikibot.Site('mh', 'wikipedia')
+ self.assertIsInstance(site, pywikibot.site.ClosedSite)
self.assertEqual(site.code, 'mh')
self.assertIsInstance(site.obsolete, bool)
self.assertTrue(site.obsolete)
- self.assertIsNotNone(site.hostname)
+ self.assertEqual(site.hostname(), 'mh.wikipedia.org')
r = http.fetch(uri='http://mh.wikipedia.org/w/api.php',
default_error_handling=False)
self.assertEqual(r.status, 200)
@@ -3408,7 +3379,9 @@

def test_alias_code_site(self):
"""Test Wikimedia site with an alias code."""
- site = self.get_site('jpwp')
+ with suppress_warnings(
+ 'Site wikipedia:ja instantiated using different code "jp"'):
+ site = pywikibot.Site('jp', 'wikipedia')
self.assertIsInstance(site.obsolete, bool)
self.assertEqual(site.code, 'ja')
self.assertFalse(site.obsolete)

To view, visit change 516333. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I97c2e4dabcacf74d5abfbf3bee84f8a0200b8fd8
Gerrit-Change-Number: 516333
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Lokal Profil <andre.costa@wikimedia.se>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Whym <whym@whym.org>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)