jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/622980 )
Change subject: [tests] rename tests/basepage_tests to tests/basepage.py ......................................................................
[tests] rename tests/basepage_tests to tests/basepage.py
tests/basepage_tests is not a test script but provides BasePageTestBase classes which is used by other test scripts.
- rename tests/basepage_tests to tests/basepage.py - update imports accordingly - update super() calls - remove superfluous setUp/setUpClass methods which just calls the super().setUp/setUpClass - remove basepage from library_test_modules
Change-Id: I71e7cd6d151b4248d1be90c86c520ed476163a82 --- M tests/__init__.py R tests/basepage.py M tests/flow_tests.py M tests/proofreadpage_tests.py M tests/site_tests.py M tests/wikibase_tests.py 6 files changed, 56 insertions(+), 68 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/__init__.py b/tests/__init__.py index 628cfe0..4130000 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -73,7 +73,6 @@
library_test_modules = { 'api', - 'basepage', 'bot', 'category', 'cosmetic_changes', diff --git a/tests/basepage_tests.py b/tests/basepage.py similarity index 100% rename from tests/basepage_tests.py rename to tests/basepage.py diff --git a/tests/flow_tests.py b/tests/flow_tests.py index fc48680..df04850 100644 --- a/tests/flow_tests.py +++ b/tests/flow_tests.py @@ -13,7 +13,7 @@ from tests import unittest
from tests.aspects import TestCase -from tests.basepage_tests import ( +from tests.basepage import ( BasePageMethodsTestBase, BasePageLoadRevisionsCachingTestBase, ) diff --git a/tests/proofreadpage_tests.py b/tests/proofreadpage_tests.py index a677a23..a95d830 100644 --- a/tests/proofreadpage_tests.py +++ b/tests/proofreadpage_tests.py @@ -5,11 +5,11 @@ # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - import difflib import json
+from contextlib import suppress + import pywikibot
from pywikibot.data import api @@ -18,7 +18,7 @@
from tests import unittest_print from tests.aspects import unittest, require_modules, TestCase -from tests.basepage_tests import ( +from tests.basepage import ( BasePageMethodsTestBase, BasePageLoadRevisionsCachingTestBase, ) @@ -50,7 +50,7 @@ """Set up test case.""" self._page = ProofreadPage( self.site, 'Page:Popular Science Monthly Volume 1.djvu/12') - super(TestBasePageMethodsProofreadPage, self).setUp() + super().setUp()
def test_basepage_methods(self): """Test ProofreadPage methods inherited from superclass BasePage.""" @@ -70,7 +70,7 @@ """Set up test case.""" self._page = ProofreadPage( self.site, 'Page:Popular Science Monthly Volume 1.djvu/12') - super(TestLoadRevisionsCachingProofreadPage, self).setUp() + super().setUp()
def test_page_text(self): """Test site.loadrevisions() with Page.text.""" @@ -125,11 +125,6 @@ }, }
- @classmethod - def setUpClass(cls): - """Prepare get_page dataset for tests.""" - super(TestProofreadPageParseTitle, cls).setUpClass() - def test_parse_title(self, key): """Test ProofreadPage_parse_title() function.""" data = self.sites[key] @@ -353,7 +348,7 @@ .format(module=__name__, doc=cls.__doc__, name=cls.__name__), end='\n') cls.skipTest(cls, 'bs4 not installed') - super(BS4TestCase, cls).setUpClass() + super().setUpClass()
class TestPageOCR(BS4TestCase): @@ -385,7 +380,7 @@ site = self.get_site() title = self.data['title'] self.page = ProofreadPage(site, title) - super(TestPageOCR, self).setUp() + super().setUp()
def test_ocr_exceptions(self): """Test page.ocr() exceptions.""" @@ -562,7 +557,7 @@ """Set up test case.""" self._page = IndexPage( self.site, 'Index:Popular Science Monthly Volume 1.djvu') - super(TestBasePageMethodsIndexPage, self).setUp() + super().setUp()
def test_basepage_methods(self): """Test IndexPage methods inherited from superclass BasePage.""" @@ -582,7 +577,7 @@ """Set up test case.""" self._page = IndexPage( self.site, 'Index:Popular Science Monthly Volume 1.djvu') - super(TestLoadRevisionsCachingIndexPage, self).setUp() + super().setUp()
def test_page_text(self): """Test site.loadrevisions() with Page.text.""" @@ -645,7 +640,7 @@ @classmethod def setUpClass(cls): """Prepare get_page dataset for tests.""" - super(TestIndexPageMappings, cls).setUpClass() + super().setUpClass() for key, site_def in cls.sites.items(): site = cls.get_site(name=key) base_title = site_def['page'] @@ -780,7 +775,7 @@ @classmethod def setUpClass(cls): """Prepare tests by creating page instances.""" - super(TestIndexPageMappingsRedlinks, cls).setUpClass() + super().setUpClass() cls.index = IndexPage(cls.site, cls.index_name) cls.pages = [ProofreadPage(cls.site, page) for page in cls.page_names] cls.missing = ProofreadPage(cls.site, cls.missing_name) @@ -820,7 +815,7 @@ @classmethod def setUpClass(cls): """Prepare tests by creating an IndexPage instance.""" - super(TestIndexPageHasValidContent, cls).setUpClass() + super().setUpClass() cls.index = IndexPage(cls.site, cls.index_name)
def test_has_valid_content_empty(self): @@ -881,7 +876,5 @@
if __name__ == '__main__': # pragma: no cover - try: + with suppress(SystemExit): unittest.main() - except SystemExit: - pass diff --git a/tests/site_tests.py b/tests/site_tests.py index 68b8373..ec9ab45 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -25,16 +25,18 @@
from tests import patch, unittest_print, MagicMock from tests.aspects import ( - unittest, TestCase, DeprecationTestCase, - TestCaseBase, - DefaultSiteTestCase, + AlteredDefaultSiteTestCase, DefaultDrySiteTestCase, + DefaultSiteTestCase, + DefaultWikidataClientTestCase, + DeprecationTestCase, + TestCase, + TestCaseBase, + unittest, WikimediaDefaultSiteTestCase, WikidataTestCase, - DefaultWikidataClientTestCase, - AlteredDefaultSiteTestCase, ) -from tests.basepage_tests import BasePageLoadRevisionsCachingTestBase +from tests.basepage import BasePageLoadRevisionsCachingTestBase from tests.utils import entered_loop
@@ -44,7 +46,7 @@
def setUp(self): """Skip test if user does not have token and clear site wallet.""" - super(TokenTestBase, self).setUp() + super().setUp() mysite = self.get_site() ttype = self.token_type try: @@ -63,7 +65,7 @@ def tearDown(self): """Restore site tokens.""" self.site.tokens = self._orig_wallet - super(TokenTestBase, self).tearDown() + super().tearDown()
class TestSiteObjectDeprecatedFunctions(DefaultSiteTestCase, @@ -476,7 +478,7 @@
def setUp(self): """Initialize self.site and self.mainpage.""" - super(TestSiteGenerators, self).setUp() + super().setUp() self.site = self.get_site() self.mainpage = self.get_mainpage()
@@ -1129,7 +1131,7 @@
def setUp(self): """Initialize self.site and self.mainpage.""" - super(TestSiteGeneratorsUsers, self).setUp() + super().setUp() self.site = self.get_site() self.mainpage = self.get_mainpage()
@@ -1197,7 +1199,7 @@
def setUp(self): """Skip tests if Linter extension is missing.""" - super(TestLinterPages, self).setUp() + super().setUp() if not self.site.has_extension('Linter'): self.skipTest( 'The site {0} does not use Linter extension'.format(self.site)) @@ -1444,7 +1446,7 @@ @classmethod def setUpClass(cls): """Test up test class.""" - super(TestRecentChanges, cls).setUpClass() + super().setUpClass() mysite = cls.get_site() try: # 1st image on main page @@ -2293,14 +2295,14 @@
def setUp(self): """Store version.""" - super(TestSiteTokens, self).setUp() + super().setUp() self.mysite = self.get_site() self._version = self.mysite.mw_version self.orig_version = self.mysite.version
def tearDown(self): """Restore version.""" - super(TestSiteTokens, self).tearDown() + super().tearDown() self.mysite.version = self.orig_version
def _test_tokens(self, version, test_version, additional_token): @@ -2591,7 +2593,7 @@ def setUp(self): """Setup tests.""" self._page = self.get_mainpage(force=True) - super(TestSiteLoadRevisionsCaching, self).setUp() + super().setUp()
def test_page_text(self): """Test site.loadrevisions() with Page.text.""" @@ -2611,7 +2613,7 @@ # were not completely disposed and recreated but retained 'memory' def setUp(self): """Setup tests.""" - super(TestSiteLoadRevisions, self).setUp() + super().setUp() self.mysite = self.get_site() self.mainpage = pywikibot.Page(pywikibot.Link('Main Page', self.mysite)) @@ -2742,7 +2744,7 @@
def setUp(self): """Setup tests.""" - super(TestBacklinks, self).setUp() + super().setUp() self.page = pywikibot.Page(self.site, 'File:BoA – Woman.png') self.backlinks = list(self.page.backlinks(follow_redirects=False, filter_redirects=True, @@ -2959,7 +2961,7 @@
def setUp(self): """Setup tests.""" - super(TestLoadPagesFromPageids, self).setUp() + super().setUp() self.site = self.get_site() mainpage = self.get_mainpage() self.links = [ diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index 546da66..7c24600 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -5,11 +5,10 @@ # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - import copy import json
+from contextlib import suppress from decimal import Decimal
import pywikibot @@ -23,12 +22,13 @@
from tests import join_pages_path, mock from tests.aspects import ( - unittest, TestCase, - WikidataTestCase, DeprecationTestCase, + TestCase, + unittest, + WikidataTestCase, )
-from tests.basepage_tests import ( +from tests.basepage import ( BasePageMethodsTestBase, BasePageLoadRevisionsCachingTestBase, ) @@ -49,10 +49,6 @@
"""Test methods inherited or extended from _WbRepresentation."""
- def setUp(self): - """Setup tests.""" - super(WbRepresentationTestCase, self).setUp() - def _test_hashable(self, representation): """Test that the representation is hashable.""" list_of_dupes = [representation, representation] @@ -67,7 +63,7 @@ def setUp(self): """Setup test.""" self._page = ItemPage(self.get_repo(), 'Q60') - super(TestLoadRevisionsCaching, self).setUp() + super().setUp()
def test_page_text(self): """Test site.loadrevisions() with Page.text.""" @@ -115,7 +111,7 @@ @classmethod def setUpClass(cls): """Setup test class.""" - super(TestGeneral, cls).setUpClass() + super().setUpClass() enwiki = pywikibot.Site('en', 'wikipedia') cls.mainpage = pywikibot.Page(pywikibot.page.Link('Main Page', enwiki))
@@ -511,7 +507,7 @@
def setUp(self): """Override setup to store repo and it's version.""" - super(WikidataTestCase, self).setUp() + super().setUp() self.repo = self.get_repo() self.version = self.repo.mw_version
@@ -678,7 +674,7 @@ """Setup tests.""" self.commons = pywikibot.Site('commons', 'commons') self.page = Page(self.commons, 'Data:Lyngby Hovedgade.map') - super(TestWbGeoShapeNonDry, self).setUp() + super().setUp()
def test_WbGeoShape_WbRepresentation_methods(self): """Test inherited or extended methods from _WbRepresentation.""" @@ -754,7 +750,7 @@ """Setup tests.""" self.commons = pywikibot.Site('commons', 'commons') self.page = Page(self.commons, 'Data:Bea.gov/GDP by state.tab') - super(TestWbTabularDataNonDry, self).setUp() + super().setUp()
def test_WbTabularData_WbRepresentation_methods(self): """Test inherited or extended methods from _WbRepresentation.""" @@ -858,7 +854,7 @@
def setUp(self): """Setup test.""" - super(TestLoadUnknownType, self).setUp() + super().setUp() wikidata = self.get_repo() self.wdp = ItemPage(wikidata, 'Q60') self.wdp.id = 'Q60' @@ -928,12 +924,12 @@ @classmethod def setUpClass(cls): """Setup test class.""" - super(TestItemLoad, cls).setUpClass() + super().setUpClass() cls.site = cls.get_site('enwiki')
def setUp(self): """Setup test.""" - super(TestItemLoad, self).setUp() + super().setUp() self.nyc = pywikibot.Page(pywikibot.page.Link('New York City', self.site))
@@ -1690,7 +1686,7 @@ def setUp(self): """Setup tests.""" self._page = ItemPage(self.get_repo(), 'Q60') - super(TestItemBasePageMethods, self).setUp() + super().setUp()
def test_basepage_methods(self): """Test ItemPage methods inherited from superclass BasePage.""" @@ -1710,7 +1706,7 @@ def setUp(self): """Setup tests.""" self._page = pywikibot.Page(self.site, 'Q60') - super(TestPageMethodsWithItemTitle, self).setUp() + super().setUp()
def test_basepage_methods(self): """Test Page methods inherited from superclass BasePage with Q60.""" @@ -1740,7 +1736,7 @@
def setUp(self): """Setup Tests.""" - super(TestLinks, self).setUp() + super().setUp() self.wdp = ItemPage(self.get_repo(), 'Q60') self.wdp.id = 'Q60' with open(join_pages_path('Q60_only_sitelinks.wd')) as f: @@ -1773,7 +1769,7 @@
def setUp(self): """Setup tests.""" - super(TestLanguageDict, self).setUp() + super().setUp() self.site = self.get_site() self.lang_out = {'en': 'foo'}
@@ -1848,7 +1844,7 @@
def setUp(self): """Setup tests.""" - super(TestAliasesDict, self).setUp() + super().setUp() self.site = self.get_site() self.lang_out = {'en': ['foo', 'bar']}
@@ -1944,7 +1940,7 @@
def setUp(self): """Setup tests.""" - super(TestWriteNormalizeData, self).setUp() + super().setUp() self.data_out = { 'labels': {'en': {'language': 'en', 'value': 'Foo'}}, 'descriptions': {'en': {'language': 'en', 'value': 'Desc'}}, @@ -2133,7 +2129,7 @@ @classmethod def setUpClass(cls): """Setup test class.""" - super(TestAlternateNamespaces, cls).setUpClass() + super().setUpClass()
cls.get_repo()._namespaces = NamespacesDict({ 90: Namespace(id=90, @@ -2264,7 +2260,7 @@
def setUp(self): """Setup test.""" - super(TestJSON, self).setUp() + super().setUp() wikidata = self.get_repo() self.wdp = ItemPage(wikidata, 'Q60') self.wdp.id = 'Q60' @@ -2387,7 +2383,5 @@
if __name__ == '__main__': # pragma: no cover - try: + with suppress(SystemExit): unittest.main() - except SystemExit: - pass
pywikibot-commits@lists.wikimedia.org