jenkins-bot has submitted this change and it was merged.
Change subject: Have most other tests subclass PywikibotTestCase
......................................................................
Have most other tests subclass PywikibotTestCase
PywikibotTestCase now patches the request to use
the cached version
Change-Id: I0fe73bde40b456091fd451841438fd9bfcaabc17
---
M tests/api_tests.py
M tests/site_tests.py
M tests/utils.py
M tests/wikibase_tests.py
4 files changed, 14 insertions(+), 12 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 2954683..7c21ff0 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -7,9 +7,10 @@
__version__ = '$Id$'
import datetime
-import unittest
import pywikibot
import pywikibot.data.api as api
+import unittest
+from utils import PywikibotTestCase
mysite = pywikibot.Site('en', 'wikipedia')
@@ -33,8 +34,9 @@
self.assert_(all(len(item) == 2 for item in req.iteritems()))
-class TestPageGenerator(unittest.TestCase):
+class TestPageGenerator(PywikibotTestCase):
def setUp(self):
+ super(TestPageGenerator, self).setUp()
self.gen = api.PageGenerator(site=mysite,
generator="links",
titles="User:R'n'B")
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 01457ee..89f076c 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -14,32 +14,24 @@
import pywikibot
import warnings
from tests import patch_request, unpatch_request
+from utils import PywikibotTestCase
mysite = None
mainpage = None
imagepage = None
-class TestSiteObject(unittest.TestCase):
+class TestSiteObject(PywikibotTestCase):
"""Test cases for Site methods."""
family = "wikipedia"
code = "en"
@classmethod
def setUpClass(cls):
- patch_request()
global mysite, mainpage, imagepage
mysite = pywikibot.Site(cls.code, cls.family)
mainpage = pywikibot.Page(pywikibot.Link("Main Page", mysite))
imagepage = iter(mainpage.imagelinks()).next() # 1st image on main page
-
- @classmethod
- def tearDownClass(cls):
- unpatch_request
-
- def assertType(self, obj, cls):
- """Assert that obj is an instance of type cls"""
- return self.assertTrue(isinstance(obj, cls))
def testBaseMethods(self):
"""Test cases for BaseSite methods"""
diff --git a/tests/utils.py b/tests/utils.py
index 2aa8307..adb31b7 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -1,7 +1,14 @@
import unittest
+from tests import patch_request, unpatch_request
class PywikibotTestCase(unittest.TestCase):
def assertType(self, obj, cls):
"""Assert that obj is an instance of type cls"""
return self.assertTrue(isinstance(obj, cls))
+
+ def setUp(self):
+ patch_request()
+
+ def tearDown(self):
+ unpatch_request()
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 878de0a..fa3facd 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -58,6 +58,7 @@
class TestLinks(PywikibotTestCase):
"""Test cases to test links stored in wikidata"""
def setUp(self):
+ super(TestLinks, self).setUp()
self.wdp = pywikibot.ItemPage(wikidata, 'Q60')
self.wdp.id = 'q60'
self.wdp._content = json.load(open(os.path.join(os.path.split(__file__)[0],
'pages', 'Q60_only_sitelinks.wd')))
--
To view, visit
https://gerrit.wikimedia.org/r/82794
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0fe73bde40b456091fd451841438fd9bfcaabc17
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot