jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[tests] Use skipping context manager for tests

Change-Id: Ia857e09f3bc228506e34e57b589d89e1bec98bd7
---
M tests/djvu_tests.py
M tests/paraminfo_tests.py
M tests/site_tests.py
M tests/utils.py
4 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/tests/djvu_tests.py b/tests/djvu_tests.py
index 4fe8c4d..7fc867a 100644
--- a/tests/djvu_tests.py
+++ b/tests/djvu_tests.py
@@ -14,6 +14,7 @@
from pywikibot.tools.djvu import DjVuFile
from tests import create_path_func, join_data_path
from tests.aspects import TestCase
+from tests.utils import skipping


join_djvu_data_path = create_path_func(join_data_path, 'djvu')
@@ -34,13 +35,11 @@
def setUpClass(cls):
"""Setup tests."""
super().setUpClass()
- try:
+ with skipping(OSError, msg='djvulibre library not installed.'):
dp = subprocess.Popen(['djvudump'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
dp.communicate()
- except OSError:
- raise unittest.SkipTest('djvulibre library not installed.')

def test_repr_method(self):
"""Test __repr__() method."""
diff --git a/tests/paraminfo_tests.py b/tests/paraminfo_tests.py
index c0f4e17..b34691f 100644
--- a/tests/paraminfo_tests.py
+++ b/tests/paraminfo_tests.py
@@ -14,6 +14,7 @@
WikimediaDefaultSiteTestCase,
unittest,
)
+from tests.utils import skipping


class KnownTypesTestBase(TestCaseBase):
@@ -22,11 +23,11 @@

def _get_param_values(self, site, module, parameter):
"""Perform check that a parameter matches the expected list."""
- try:
+ with skipping(
+ ValueError,
+ msg='Paraminfo for {} could not be loaded'.format(module)):
param = site._paraminfo.parameter(module, parameter)
- except ValueError:
- raise unittest.SkipTest(
- 'Paraminfo for {} could not be loaded'.format(module))
+
if not param or 'type' not in param:
raise unittest.SkipTest(
'No defined values for {}.{}'.format(module, parameter))
diff --git a/tests/site_tests.py b/tests/site_tests.py
index c64d0ee..d4b2721 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -38,6 +38,7 @@
WikimediaDefaultSiteTestCase,
)
from tests.basepage import BasePageLoadRevisionsCachingTestBase
+from tests.utils import skipping


class TestSiteObjectDeprecatedFunctions(DefaultSiteTestCase,
@@ -1072,11 +1073,10 @@

mysite = self.get_site()
page = pywikibot.Page(mysite, mysite.siteinfo['mainpage'])
- try:
+ with skipping(
+ StopIteration,
+ msg='No images on the main page of site {0!r}'.format(mysite)):
imagepage = next(iter(page.imagelinks())) # 1st image of page
- except StopIteration:
- raise unittest.SkipTest(
- 'No images on the main page of site {0!r}'.format(mysite))

pywikibot.output('site_tests.TestImageUsage found {} on {}'
.format(imagepage, page))
diff --git a/tests/utils.py b/tests/utils.py
index 5575f38..25d024b 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -519,9 +519,11 @@


@contextmanager
-def skipping(*exceptions):
+def skipping(*exceptions, msg=None):
"""Context manager to skip test on specified exceptions."""
try:
yield
except exceptions as e:
- raise unittest.SkipTest(e)
+ if msg is None:
+ msg = e
+ raise unittest.SkipTest(msg)

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia857e09f3bc228506e34e57b589d89e1bec98bd7
Gerrit-Change-Number: 692376
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged