[MediaWiki-commits] [Gerrit] Add classes for tests that alter mylang and family - change (pywikibot/core)
jenkins-bot has submitted this change and it was merged. Change subject: Add classes for tests that alter mylang and family .. Add classes for tests that alter mylang and family Change-Id: I247b44d55b2cf744b72fe0731b3beb67bb86ce1f --- M tests/aspects.py M tests/deletionbot_tests.py M tests/interwiki_link_tests.py M tests/link_tests.py M tests/reflinks_tests.py 5 files changed, 75 insertions(+), 93 deletions(-) Approvals: John Vandenberg: Looks good to me, but someone else must approve XZise: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/aspects.py b/tests/aspects.py index 86d1341..b6b0956 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -913,6 +913,35 @@ code = config.mylang +class AlteredDefaultSiteTestCase(TestCase): + +"""Save and restore the config.mylang and config.family.""" + +def setUp(self): +"""Prepare the environment for running main() in a script.""" +self.original_family = pywikibot.config.family +self.original_code = pywikibot.config.mylang +super(AlteredDefaultSiteTestCase, self).setUp() + +def tearDown(self): +"""Restore the environment.""" +pywikibot.config.family = self.original_family +pywikibot.config.mylang = self.original_code +super(AlteredDefaultSiteTestCase, self).tearDown() + + +class ScenarioDefinedDefaultSiteTestCase(AlteredDefaultSiteTestCase): + +"""Tests that depend on the default site being set to the test site.""" + +def setUp(self): +"""Prepare the environment for running main() in a script.""" +super(ScenarioDefinedDefaultSiteTestCase, self).setUp() +site = self.get_site() +pywikibot.config.family = site.family +pywikibot.config.mylang = site.code + + class DefaultDrySiteTestCase(DefaultSiteTestCase): """Run tests using the config specified site in offline mode.""" @@ -1072,6 +1101,13 @@ % (cls.__name__, cls.get_site())) +class ScriptMainTestCase(ScenarioDefinedDefaultSiteTestCase): + +"""Test running a script main().""" + +pass + + class PwbTestCase(TestCase): """ diff --git a/tests/deletionbot_tests.py b/tests/deletionbot_tests.py index 7c0d893..1a8d5ed 100644 --- a/tests/deletionbot_tests.py +++ b/tests/deletionbot_tests.py @@ -12,10 +12,10 @@ from scripts import delete -from tests.aspects import unittest, TestCase +from tests.aspects import unittest, ScriptMainTestCase -class TestDeletionBotWrite(TestCase): +class TestDeletionBotWrite(ScriptMainTestCase): """Test deletionbot script.""" @@ -48,7 +48,7 @@ '-undelete', '-summary=pywikibot unit tests') -class TestDeletionBotUser(TestCase): +class TestDeletionBotUser(ScriptMainTestCase): """Test deletionbot as a user (not sysop).""" @@ -75,7 +75,7 @@ p1.save('unit test', botflag=True) -class TestDeletionBot(TestCase): +class TestDeletionBot(ScriptMainTestCase): """Test deletionbot with patching to make it non-write.""" diff --git a/tests/interwiki_link_tests.py b/tests/interwiki_link_tests.py index ea7ec08..d5b44fb 100644 --- a/tests/interwiki_link_tests.py +++ b/tests/interwiki_link_tests.py @@ -10,24 +10,20 @@ from pywikibot import config2 as config from pywikibot.page import Link from pywikibot.exceptions import InvalidTitle -from tests.aspects import unittest, TestCase +from tests.aspects import ( +unittest, +AlteredDefaultSiteTestCase as LinkTestCase, +TestCase, +) -class TestPartiallyQualifiedLinkDifferentCodeParser(TestCase): +class TestPartiallyQualifiedLinkDifferentCodeParser(LinkTestCase): """Tests for interwiki links to local sites.""" family = 'wikipedia' code = 'en' cached = True - -def setUp(self): -self.old_lang = config.mylang -self.old_family = config.family - -def tearDown(self): -config.mylang = self.old_lang -config.family = self.old_family def test_partially_qualified_NS0_family(self): """Test that Link uses config.family for namespace 0.""" diff --git a/tests/link_tests.py b/tests/link_tests.py index a378c65..ab80d0d 100644 --- a/tests/link_tests.py +++ b/tests/link_tests.py @@ -11,7 +11,13 @@ from pywikibot import config2 as config from pywikibot.page import Link from pywikibot.exceptions import Error, InvalidTitle -from tests.aspects import unittest, DefaultDrySiteTestCase, TestCase +from tests.aspects import ( +unittest, +AlteredDefaultSiteTestCase as LinkTestCase, +DefaultDrySiteTestCase, +WikimediaDefaultSiteTestCase, +TestCase, +) # Tests checking if the parser does (not) accept (in)valid titles @@ -102,21 +108,13 @@ # The first set of tests are explicit links, starting with a ':'. -class TestPartiallyQualifiedExplicitLinkSameSiteParser(TestCase): +class TestPartiallyQualifiedExplicitLinkSameSitePars
[MediaWiki-commits] [Gerrit] Add classes for tests that alter mylang and family - change (pywikibot/core)
John Vandenberg has uploaded a new change for review. https://gerrit.wikimedia.org/r/183791 Change subject: Add classes for tests that alter mylang and family .. Add classes for tests that alter mylang and family Fix TestInvalidInterwikiLinks so it works on any site. Change-Id: I247b44d55b2cf744b72fe0731b3beb67bb86ce1f --- M tests/aspects.py M tests/deletionbot_tests.py M tests/interwiki_link_tests.py M tests/link_tests.py M tests/reflinks_tests.py 5 files changed, 79 insertions(+), 96 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/91/183791/1 diff --git a/tests/aspects.py b/tests/aspects.py index 86d1341..b6b0956 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -913,6 +913,35 @@ code = config.mylang +class AlteredDefaultSiteTestCase(TestCase): + +"""Save and restore the config.mylang and config.family.""" + +def setUp(self): +"""Prepare the environment for running main() in a script.""" +self.original_family = pywikibot.config.family +self.original_code = pywikibot.config.mylang +super(AlteredDefaultSiteTestCase, self).setUp() + +def tearDown(self): +"""Restore the environment.""" +pywikibot.config.family = self.original_family +pywikibot.config.mylang = self.original_code +super(AlteredDefaultSiteTestCase, self).tearDown() + + +class ScenarioDefinedDefaultSiteTestCase(AlteredDefaultSiteTestCase): + +"""Tests that depend on the default site being set to the test site.""" + +def setUp(self): +"""Prepare the environment for running main() in a script.""" +super(ScenarioDefinedDefaultSiteTestCase, self).setUp() +site = self.get_site() +pywikibot.config.family = site.family +pywikibot.config.mylang = site.code + + class DefaultDrySiteTestCase(DefaultSiteTestCase): """Run tests using the config specified site in offline mode.""" @@ -1072,6 +1101,13 @@ % (cls.__name__, cls.get_site())) +class ScriptMainTestCase(ScenarioDefinedDefaultSiteTestCase): + +"""Test running a script main().""" + +pass + + class PwbTestCase(TestCase): """ diff --git a/tests/deletionbot_tests.py b/tests/deletionbot_tests.py index 7c0d893..1a8d5ed 100644 --- a/tests/deletionbot_tests.py +++ b/tests/deletionbot_tests.py @@ -12,10 +12,10 @@ from scripts import delete -from tests.aspects import unittest, TestCase +from tests.aspects import unittest, ScriptMainTestCase -class TestDeletionBotWrite(TestCase): +class TestDeletionBotWrite(ScriptMainTestCase): """Test deletionbot script.""" @@ -48,7 +48,7 @@ '-undelete', '-summary=pywikibot unit tests') -class TestDeletionBotUser(TestCase): +class TestDeletionBotUser(ScriptMainTestCase): """Test deletionbot as a user (not sysop).""" @@ -75,7 +75,7 @@ p1.save('unit test', botflag=True) -class TestDeletionBot(TestCase): +class TestDeletionBot(ScriptMainTestCase): """Test deletionbot with patching to make it non-write.""" diff --git a/tests/interwiki_link_tests.py b/tests/interwiki_link_tests.py index ea7ec08..d5b44fb 100644 --- a/tests/interwiki_link_tests.py +++ b/tests/interwiki_link_tests.py @@ -10,24 +10,20 @@ from pywikibot import config2 as config from pywikibot.page import Link from pywikibot.exceptions import InvalidTitle -from tests.aspects import unittest, TestCase +from tests.aspects import ( +unittest, +AlteredDefaultSiteTestCase as LinkTestCase, +TestCase, +) -class TestPartiallyQualifiedLinkDifferentCodeParser(TestCase): +class TestPartiallyQualifiedLinkDifferentCodeParser(LinkTestCase): """Tests for interwiki links to local sites.""" family = 'wikipedia' code = 'en' cached = True - -def setUp(self): -self.old_lang = config.mylang -self.old_family = config.family - -def tearDown(self): -config.mylang = self.old_lang -config.family = self.old_family def test_partially_qualified_NS0_family(self): """Test that Link uses config.family for namespace 0.""" diff --git a/tests/link_tests.py b/tests/link_tests.py index a378c65..d206086 100644 --- a/tests/link_tests.py +++ b/tests/link_tests.py @@ -11,7 +11,13 @@ from pywikibot import config2 as config from pywikibot.page import Link from pywikibot.exceptions import Error, InvalidTitle -from tests.aspects import unittest, DefaultDrySiteTestCase, TestCase +from tests.aspects import ( +unittest, +AlteredDefaultSiteTestCase as LinkTestCase, +DefaultDrySiteTestCase, +DefaultSiteTestCase, +TestCase, +) # Tests checking if the parser does (not) accept (in)valid titles @@ -102,21 +108,13 @@ # The first set of tests are explicit links, starting with a ':'. -class TestPartiallyQualifiedExplicitLinkSameSiteParser(TestCase): +class TestPartiallyQua