jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] tests: Automatic site attributes ......................................................................
[FEAT] tests: Automatic site attributes
The SiteAttributeTestCase class automatically sets the attributes of each site instance according to the sites defined (similar to how TestCase itself set 'cls.site' if only one site is defined).
Change-Id: Ib680dd7cb0ccfd6b9a8b05991e64294da22d0e83 --- M tests/aspects.py M tests/dry_api_tests.py M tests/page_tests.py 3 files changed, 21 insertions(+), 15 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py index c0a241c..ae29255 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -931,6 +931,19 @@ TestCase = six.add_metaclass(MetaTestCaseClass)(TestCase)
+class SiteAttributeTestCase(TestCase): + + """Add the sites as attributes to the instances.""" + + @classmethod + def setUpClass(cls): + """Add each initialized site as an attribute to cls.""" + super(SiteAttributeTestCase, cls).setUpClass() + for site in cls.sites: + if 'site' in cls.sites[site]: + setattr(cls, site, cls.sites[site]['site']) + + class DefaultSiteTestCase(TestCase):
"""Run tests against the config specified site.""" diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py index ab80178..8d8701f 100644 --- a/tests/dry_api_tests.py +++ b/tests/dry_api_tests.py @@ -24,10 +24,12 @@
from tests import _images_dir from tests.utils import DummySiteinfo -from tests.aspects import unittest, TestCase, DefaultDrySiteTestCase +from tests.aspects import ( + unittest, TestCase, DefaultDrySiteTestCase, SiteAttributeTestCase, +)
-class DryCachedRequestTests(TestCase): +class DryCachedRequestTests(SiteAttributeTestCase):
"""Test CachedRequest using real site objects."""
@@ -46,8 +48,6 @@
def setUp(self): super(DryCachedRequestTests, self).setUp() - self.basesite = self.get_site('basesite') - self.altsite = self.get_site('altsite') self.parms = {'site': self.basesite, 'action': 'query', 'meta': 'userinfo'} diff --git a/tests/page_tests.py b/tests/page_tests.py index 202189f..c031da4 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -15,7 +15,9 @@ from pywikibot import InvalidTitle import pywikibot.page
-from tests.aspects import unittest, TestCase, DefaultSiteTestCase +from tests.aspects import ( + unittest, TestCase, DefaultSiteTestCase, SiteAttributeTestCase, +) from tests.utils import expected_failure_if
if sys.version_info[0] > 2: @@ -23,7 +25,7 @@ unicode = str
-class TestLinkObject(TestCase): +class TestLinkObject(SiteAttributeTestCase):
"""Test cases for Link objects."""
@@ -51,15 +53,6 @@ }
cached = True - - @classmethod - def setUpClass(cls): - super(TestLinkObject, cls).setUpClass() - cls.enwiki = cls.get_site('enwiki') - cls.frwiki = cls.get_site('frwiki') - cls.itwikt = cls.get_site('itwikt') - cls.enws = cls.get_site('enws') - cls.itws = cls.get_site('itws')
namespaces = {0: [u""], # en.wikipedia.org namespaces for testing 1: [u"Talk:"], # canonical form first, then others
pywikibot-commits@lists.wikimedia.org