Skip to content

Commit 17c717d

Browse files
committed
Skip the test if the sparql endpoints host is not available
1 parent d291420 commit 17c717d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

examples/sparqlstore_example.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Simple examples showing how to use the SPARQLStore
33
"""
4+
from urllib.request import urlopen
5+
import sys
46

57
from rdflib import Graph, Namespace, URIRef
68
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore, SPARQLStore
@@ -18,6 +20,14 @@
1820

1921
# THIS WILL ADD DATA TO THE /db dataset
2022

23+
24+
HOST = "http://localhost:3030"
25+
try:
26+
assert len(urlopen(HOST).read()) > 0
27+
except Exception:
28+
print(f"{HOST} is unavailable.")
29+
sys.exit(126)
30+
2131
if __name__ == "__main__":
2232
dbo = Namespace("http://dbpedia.org/ontology/")
2333
dbr = Namespace("http://dbpedia.org/resource/")

test/test_examples.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ def test_example(example_file: Path) -> None:
3939

4040
try:
4141
result.check_returncode()
42-
except subprocess.CalledProcessError:
43-
if (
44-
example_file.stem == "sparqlstore_example"
45-
and "http.client.RemoteDisconnected: Remote end closed connection without response"
46-
in result.stderr.decode("utf-8")
47-
):
48-
pytest.skip("this test uses dbpedia which is down sometimes")
42+
except subprocess.CalledProcessError as process_error:
43+
if (process_error.returncode == 126):
44+
pytest.skip("This test returned 126 indikating to skip it.")
4945
raise

0 commit comments

Comments
 (0)