jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[tests] Skip SPARQL tests on TimeoutError

Bug: T261548
Change-Id: Idfc03aaac6037d822a81eef762fbab6cc6e6bb17
---
M tests/sparql_tests.py
M tests/utils.py
2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/tests/sparql_tests.py b/tests/sparql_tests.py
index 57e89d5..784d3e6 100644
--- a/tests/sparql_tests.py
+++ b/tests/sparql_tests.py
@@ -7,9 +7,11 @@
import unittest
from contextlib import suppress

+import pywikibot
import pywikibot.data.sparql as sparql
from tests import patch
from tests.aspects import TestCase, WikidataTestCase
+from tests.utils import skipping


# See: https://www.w3.org/TR/2013/REC-sparql11-results-json-20130321/
@@ -97,7 +99,8 @@
mock_method.return_value = Container(
SQL_RESPONSE_CONTAINER % '{}, {}'.format(
ITEM_Q498787, ITEM_Q677525))
- q = sparql.SparqlQuery()
+ with skipping(pywikibot.exceptions.TimeoutError):
+ q = sparql.SparqlQuery()
res = q.select('SELECT * WHERE { ?x ?y ?z }')
self.assertIsInstance(res, list, 'Result is not a list')
self.assertLength(res, 2)
@@ -119,7 +122,8 @@
mock_method.return_value = Container(
SQL_RESPONSE_CONTAINER % '{}, {}'.format(
ITEM_Q498787, ITEM_Q677525))
- q = sparql.SparqlQuery()
+ with skipping(pywikibot.exceptions.TimeoutError):
+ q = sparql.SparqlQuery()
res = q.select('SELECT * WHERE { ?x ?y ?z }', full_data=True)
self.assertIsInstance(res, list, 'Result is not a list')
self.assertLength(res, 2)
@@ -148,7 +152,8 @@
mock_method.return_value = Container(
SQL_RESPONSE_CONTAINER % '{0}, {1}, {1}'.format(ITEM_Q498787,
ITEM_Q677525))
- q = sparql.SparqlQuery()
+ with skipping(pywikibot.exceptions.TimeoutError):
+ q = sparql.SparqlQuery()
res = q.get_items('SELECT * WHERE { ?x ?y ?z }', 'cat')
self.assertSetEqual(res, {'Q498787', 'Q677525'})
res = q.get_items('SELECT * WHERE { ?x ?y ?z }', 'cat',
@@ -159,7 +164,8 @@
def testQueryAsk(self, mock_method):
"""Test ASK query."""
mock_method.return_value = Container(RESPONSE_TRUE)
- q = sparql.SparqlQuery()
+ with skipping(pywikibot.exceptions.TimeoutError):
+ q = sparql.SparqlQuery()

res = q.ask('ASK { ?x ?y ?z }')
self.assertTrue(res)
diff --git a/tests/utils.py b/tests/utils.py
index 71f8bfe..5575f38 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -7,6 +7,7 @@
import inspect
import os
import sys
+import unittest
import warnings
from contextlib import contextmanager
from subprocess import PIPE, Popen, TimeoutExpired
@@ -19,7 +20,7 @@
from pywikibot.exceptions import APIError
from pywikibot.login import LoginStatus
from pywikibot.site import Namespace
-from tests import _pwb_py, unittest
+from tests import _pwb_py


try:
@@ -515,3 +516,12 @@
pywikibot._sites = {}
pywikibot._code_fam_from_url.cache_clear()
yield
+
+
+@contextmanager
+def skipping(*exceptions):
+ """Context manager to skip test on specified exceptions."""
+ try:
+ yield
+ except exceptions as e:
+ raise unittest.SkipTest(e)

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

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