diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d7a67f52..57c1ea20 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,21 +24,10 @@ jobs: run: | pip install -U pip pip install '.[dev]' - - name: Mypy - run: | - mypy --show-error-context --show-error-codes - - name: Test [wrapper] - if: ${{ always() }} - run: | - python -m unittest test/test_wrapper.py -v + - uses: pre-commit/action@v2.0.3 - name: Test [all] run: | - python -m unittest -v |& tee log.txt - grep '^FAIL:' log.txt > fails.txt - # if all failures is not raised in `test.test_wrapper`: - if [ "$(grep 'test.test_wrapper' fails.txt | wc -l)" -ne "$(wc -l < fails.txt)" ]; then + pytest |& tee log.txt + if tail -1 log.txt | grep -q ' failed'; then exit 1 - else - echo 'All of the above failures are maybe false errors.' - echo 'See: https://github.com/RDFLib/sparqlwrapper/issues/192' fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..cf485877 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,78 @@ +repos: + - repo: https://github.com/asottile/pyupgrade + rev: v2.31.1 + hooks: + - id: pyupgrade + args: [--py37-plus] + + - repo: https://github.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + exclude: | + (?x)^( + \.git/.*| + __pycache__/.*| + docs/.*| + build/.*| + dist/.*| + test/.* + )$ + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.9.0 + hooks: + - id: python-check-blanket-noqa + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: check-merge-conflict + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/psf/black + rev: 22.1.0 + hooks: + - id: black + exclude: | + (?x)^( + \.git/.*| + __pycache__/.*| + docs/.*| + build/.*| + dist/.* + )$ + + + - repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort + exclude: | + (?x)^( + \.git/.*| + __pycache__/.*| + docs/.*| + build/.*| + dist/.* + )$ + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.940 + hooks: + - id: mypy + args: ['--no-warn-unused-ignores'] + additional_dependencies: ['rdflib', 'types-setuptools', 'pandas-stubs'] + exclude: | + (?x)^( + \.git/.*| + test/.*| + __pycache__/.*| + docs/.*| + test/.*| + build/.*| + scripts/.*| + dist/.* + )$ diff --git a/LICENSE.txt b/LICENSE.txt index a03b80c0..70ef2f1c 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -SPARQL Python Wrapper is released under the W3C® SOFTWARE NOTICE AND LICENSE. +SPARQL Python Wrapper is released under the W3C® SOFTWARE NOTICE AND LICENSE. This work (and included software, documentation such as READMEs, or other related items) is being provided by the copyright holders under the following license. By obtaining, using and/or copying this work, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions. @@ -15,4 +15,3 @@ COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQ The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the software without specific, written prior permission. Title to copyright in this software and any associated documentation will at all times remain with copyright holders. See also http://www.w3.org/Consortium/Legal/copyright-software for further details - diff --git a/MANIFEST.in b/MANIFEST.in index f66da93b..2ce6c356 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,8 +2,6 @@ include *.md exclude Makefile include test/*.py include scripts/*.py -include requirements.txt -include requirements.development.txt include LICENSE.txt include ChangeLog.txt graft docs/build/html diff --git a/Makefile b/Makefile index cb9a6157..70bf7336 100644 --- a/Makefile +++ b/Makefile @@ -12,4 +12,3 @@ clean: $(MAKE) -C ${DOCDIR} clean rm -rf build find . -name "*.pyc" -delete - diff --git a/README.rst b/README.rst index 06321061..ed7f8b0d 100644 --- a/README.rst +++ b/README.rst @@ -35,13 +35,13 @@ You can install SPARQLWrapper from GitHub:: You can install SPARQLWrapper from Debian:: $ sudo apt-get install python-sparqlwrapper - + .. note:: Be aware that there could be a gap between the latest version of SPARQLWrapper and the version available as Debian package. -Also, the source code of the package can be downloaded +Also, the source code of the package can be downloaded in ``.zip`` and ``.tar.gz`` formats from `GitHub SPARQLWrapper releases `_. Documentation is included in the distribution. @@ -125,9 +125,9 @@ This query gets a boolean response from DBPedia's SPARQL endpoint: sparql = SPARQLWrapper("http://dbpedia.org/sparql") sparql.setQuery(""" - ASK WHERE { + ASK WHERE { rdfs:label "Asturias"@es - } + } """) sparql.setReturnFormat(XML) results = sparql.query().convert() @@ -307,7 +307,7 @@ Return formats The expected return formats differs per query type (``SELECT``, ``ASK``, ``CONSTRUCT``, ``DESCRIBE``...). -.. note:: From the `SPARQL specification `_, +.. note:: From the `SPARQL specification `_, *The response body of a successful query operation with a 2XX response is either:* * ``SELECT`` and ``ASK``: a SPARQL Results Document in XML, JSON, or CSV/TSV format. @@ -430,12 +430,12 @@ in the return value). This features becomes particularly useful when the ``OPTIO GET or POST ^^^^^^^^^^^ -By default, all SPARQL services are invoked using HTTP **GET** verb. However, +By default, all SPARQL services are invoked using HTTP **GET** verb. However, **POST** might be useful if the size of the query extends a reasonable size; this can be set in the query instance. Note that some combinations may not work yet with all SPARQL processors -(e.g., there are implementations where **POST + JSON return** does not work). +(e.g., there are implementations where **POST + JSON return** does not work). Hopefully, this problem will eventually disappear. diff --git a/SPARQLWrapper/KeyCaseInsensitiveDict.py b/SPARQLWrapper/KeyCaseInsensitiveDict.py index ff7f59f6..724db2d0 100644 --- a/SPARQLWrapper/KeyCaseInsensitiveDict.py +++ b/SPARQLWrapper/KeyCaseInsensitiveDict.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ A simple implementation of a key case-insensitive dictionary. .. @@ -18,12 +16,13 @@ _V = TypeVar("_V") + class KeyCaseInsensitiveDict(Dict[str, _V]): """ A simple implementation of a key case-insensitive dictionary """ - def __init__(self, d: Mapping[str, _V]={}) -> None: + def __init__(self, d: Mapping[str, _V] = {}) -> None: """ :param dict d: The source dictionary. """ diff --git a/SPARQLWrapper/SPARQLExceptions.py b/SPARQLWrapper/SPARQLExceptions.py index 65cc25c1..4bf32c42 100644 --- a/SPARQLWrapper/SPARQLExceptions.py +++ b/SPARQLWrapper/SPARQLExceptions.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ SPARQL Wrapper exceptions @@ -35,15 +33,15 @@ def __init__(self, response: Optional[bytes] = None): :param string response: The server response """ if response: - formatted_msg = "%s: %s. \n\nResponse:\n%r" % ( + formatted_msg = "{}: {}. \n\nResponse:\n{!r}".format( self.__class__.__name__, self.msg, response, ) else: - formatted_msg = "%s: %s." % (self.__class__.__name__, self.msg) + formatted_msg = f"{self.__class__.__name__}: {self.msg}." - super(SPARQLWrapperException, self).__init__(formatted_msg) + super().__init__(formatted_msg) class EndPointInternalError(SPARQLWrapperException): diff --git a/SPARQLWrapper/SmartWrapper.py b/SPARQLWrapper/SmartWrapper.py index e88c1554..ec62b5f9 100644 --- a/SPARQLWrapper/SmartWrapper.py +++ b/SPARQLWrapper/SmartWrapper.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ .. @@ -28,7 +26,7 @@ ###################################################################################### -class Value(object): +class Value: """ Class encapsulating a single binding for a variable. @@ -68,23 +66,23 @@ def __init__(self, variable: str, binding: Dict[str, str]) -> None: self.datatype = None try: self.lang = binding["xml:lang"] - except: + except Exception: # no lang is set pass try: self.datatype = binding["datatype"] - except: + except Exception: pass def __repr__(self) -> str: cls = self.__class__.__name__ - return "%s(%s:%r)" % (cls, self.type, self.value) + return f"{cls}({self.type}:{self.value!r})" ###################################################################################### -class Bindings(object): +class Bindings: """ Class encapsulating one query result, based on the JSON return format. It decodes the return values to make it a bit more usable for a standard usage. The class consumes the @@ -121,7 +119,7 @@ def __init__(self, retval: QueryResult): self.variables: Optional[List[str]] = None try: self.variables = self.fullResult["head"]["vars"] - except: + except Exception: pass self.bindings: List[Dict[str, Value]] = [] @@ -136,13 +134,13 @@ def __init__(self, retval: QueryResult): # there is a real binding for this key newBind[key] = Value(key, b[key]) self.bindings.append(newBind) - except: + except Exception: pass self.askResult = False try: self.askResult = self.fullResult["boolean"] - except: + except Exception: pass def getValues(self, key: str) -> Optional[List[Value]]: @@ -156,7 +154,7 @@ def getValues(self, key: str) -> Optional[List[Value]]: """ try: return [b[key] for b in self[key]] - except: + except Exception: return [] def __contains__(self, key: Union[str, List[str], Tuple[str]]) -> bool: @@ -310,9 +308,7 @@ def __init__(self, baseURI: str, defaultGraph: Optional[str] = None): :param defaultGraph: URI for the default graph. Default is ``None``, can be set via an explicit call, too. :type defaultGraph: string """ - super(SPARQLWrapper2, self).__init__( - baseURI, returnFormat=JSON, defaultGraph=defaultGraph - ) + super().__init__(baseURI, returnFormat=JSON, defaultGraph=defaultGraph) def setReturnFormat(self, format: Optional[str]) -> None: """ @@ -343,7 +339,7 @@ def query(self) -> Union[Bindings, QueryResult]: # type: ignore[override] :return: query result :rtype: :class:`Bindings` instance """ - res = super(SPARQLWrapper2, self).query() + res = super().query() if self.queryType == SELECT: return Bindings(res) @@ -363,4 +359,4 @@ def queryAndConvert( # type: ignore[override] if self.queryType == SELECT: return self.query() else: - return super(SPARQLWrapper2, self).queryAndConvert() + return super().queryAndConvert() diff --git a/SPARQLWrapper/Wrapper.py b/SPARQLWrapper/Wrapper.py index 977380a9..74bc3438 100644 --- a/SPARQLWrapper/Wrapper.py +++ b/SPARQLWrapper/Wrapper.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ .. .. seealso:: `SPARQL Specification `_ @@ -30,10 +28,20 @@ import urllib.request import warnings from http.client import HTTPResponse -from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple, Union, cast +from typing import ( + TYPE_CHECKING, + Any, + Dict, + Iterator, + List, + Optional, + Tuple, + Union, + cast, +) from urllib.request import ( - urlopen as urlopener, -) # don't change the name: tests override it + urlopen as urlopener, # don't change the name: tests override it +) from xml.dom.minidom import Document, parse from SPARQLWrapper import __agent__ @@ -41,8 +49,6 @@ if TYPE_CHECKING: from rdflib import Graph - - from .KeyCaseInsensitiveDict import KeyCaseInsensitiveDict from .SPARQLExceptions import ( EndPointInternalError, @@ -186,7 +192,7 @@ ####################################################################################################### -class SPARQLWrapper(object): +class SPARQLWrapper: """ Wrapper around an online access to a SPARQL Web entry point. @@ -567,7 +573,7 @@ def setHTTPAuth(self, auth: str) -> None: self.http_auth = auth.upper() else: valid_types = ", ".join(_allowedAuth) - raise ValueError("Value should be one of {0}".format(valid_types)) + raise ValueError(f"Value should be one of {valid_types}") def setQuery(self, query: Union[str, bytes]) -> None: """ @@ -876,7 +882,7 @@ def _createRequest(self) -> urllib.request.Request: request.add_header("Accept", self._getAcceptHeader()) if self.user and self.passwd: if self.http_auth == BASIC: - credentials = "%s:%s" % (self.user, self.passwd) + credentials = f"{self.user}:{self.passwd}" request.add_header( "Authorization", "Basic %s" @@ -892,7 +898,7 @@ def _createRequest(self) -> urllib.request.Request: else: valid_types = ", ".join(_allowedAuth) raise NotImplementedError( - "Expecting one of: {0}, but received: {1}".format( + "Expecting one of: {}, but received: {}".format( valid_types, self.http_auth ) ) @@ -976,15 +982,15 @@ def __str__(self) -> str: :rtype: string """ fullname = self.__module__ + "." + self.__class__.__name__ - items = ('"%s" : %r' % (k, v) for k, v in sorted(self.__dict__.items())) + items = (f'"{k}" : {v!r}' for k, v in sorted(self.__dict__.items())) str_dict_items = "{%s}" % (",\n".join(items)) - return "<%s object at 0x%016X>\n%s" % (fullname, id(self), str_dict_items) + return f"<{fullname} object at 0x{id(self):016X}>\n{str_dict_items}" ####################################################################################################### -class QueryResult(object): +class QueryResult: """ Wrapper around an a query result. Users should not create instances of this class, it is generated by a :func:`SPARQLWrapper.query` call. The results can be @@ -1083,6 +1089,7 @@ def _convertRDF(self) -> "Graph": :rtype: :class:`rdflib.graph.Graph` """ from rdflib import ConjunctiveGraph + retval = ConjunctiveGraph() retval.parse(self.response, format="xml") # type: ignore[no-untyped-call] return retval @@ -1361,7 +1368,7 @@ def __str__(self) -> str: '%s",\n\t"code" : "%s",\n\t"headers" : %s}' % (str_url, str_code, str_headers) ) - return "<%s object at 0x%016X>\n{%s,\n%s}" % ( + return "<{} object at 0x{:016X}>\n{{{},\n{}}}".format( fullname, id(self), str_requestedFormat, diff --git a/SPARQLWrapper/__init__.py b/SPARQLWrapper/__init__.py index 885978bb..90b6b94c 100644 --- a/SPARQLWrapper/__init__.py +++ b/SPARQLWrapper/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf8 -*- - """ **SPARQLWrapper** is a simple Python wrapper around a `SPARQL `_ service to @@ -8,16 +6,14 @@ format. """ - __version__ = "2.0.1a0" """The version of SPARQLWrapper""" __agent__: str = f"sparqlwrapper {__version__} (rdflib.github.io/sparqlwrapper)" - -from .SmartWrapper import SPARQLWrapper2 -from .sparql_dataframe import get_sparql_dataframe -from .Wrapper import ( +from .SmartWrapper import SPARQLWrapper2 # noqa: E402 +from .sparql_dataframe import get_sparql_dataframe # noqa: E402 +from .Wrapper import ( # noqa: E402 ASK, BASIC, CONSTRUCT, diff --git a/SPARQLWrapper/main.py b/SPARQLWrapper/main.py index 3802b8bf..abefce16 100644 --- a/SPARQLWrapper/main.py +++ b/SPARQLWrapper/main.py @@ -96,7 +96,7 @@ def parse_args(test: Optional[List[str]] = None) -> argparse.Namespace: ) parser.add_argument("-q", "--quiet", action="store_true", help="supress warnings") parser.add_argument( - "-V", "--version", action="version", version="%(prog)s {}".format(__version__) + "-V", "--version", action="version", version=f"%(prog)s {__version__}" ) if test is None: return parser.parse_args() @@ -117,7 +117,7 @@ def main(test: Optional[List[str]] = None) -> None: elif args.file == "-": q = sys.stdin.read() else: - q = open(args.file, "r").read() + q = open(args.file).read() sparql = SPARQLWrapper( args.endpoint, diff --git a/SPARQLWrapper/sparql_dataframe.py b/SPARQLWrapper/sparql_dataframe.py index e8707f55..bb4cc2d5 100644 --- a/SPARQLWrapper/sparql_dataframe.py +++ b/SPARQLWrapper/sparql_dataframe.py @@ -2,7 +2,7 @@ Query a SPARQL endpoint and return results as a Pandas dataframe. """ import io -from typing import TYPE_CHECKING, Any, Dict, List, Union +from typing import TYPE_CHECKING, Dict, List, Union from SPARQLWrapper.SmartWrapper import Bindings, SPARQLWrapper2, Value from SPARQLWrapper.Wrapper import CSV, SELECT, SPARQLWrapper @@ -39,10 +39,9 @@ def get_sparql_typed_dict( endpoint: str, query: Union[str, bytes] ) -> List[Dict[str, Value]]: """modified from: https://github.com/lawlesst/sparql-dataframe""" - # pandas inside to avoid requiring it - import pandas as pd # rdflib in here because there is some meta stuff in the setup.py and Travis fails because rdflib is installed later import rdflib.term + sparql = SPARQLWrapper2(endpoint) sparql.setQuery(query) if sparql.queryType != SELECT: diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 55e95069..77ce5818 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -1,3 +1,2 @@ .. include:: ../../ChangeLog.txt - diff --git a/docs/source/conf.py b/docs/source/conf.py index 1ac6dcaf..c3b07328 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # @@ -14,26 +13,27 @@ # import os import sys -sys.path.insert(0, os.path.abspath('../..')) -sys.path.insert(0, os.path.abspath('../../SPARQLWrapper')) # from https://stackoverflow.com/questions/10324393/sphinx-build-fail-autodoc-cant-import-find-module - -from SPARQLWrapper import __version__ +sys.path.insert(0, os.path.abspath("../..")) +sys.path.insert( + 0, os.path.abspath("../../SPARQLWrapper") +) # from https://stackoverflow.com/questions/10324393/sphinx-build-fail-autodoc-cant-import-find-module +from SPARQLWrapper import __version__ # -- Project information ----------------------------------------------------- -project = 'SPARQLWrapper' -copyright = '2019, `W3C® SOFTWARE NOTICE AND LICENSE `_' -author = 'Ivan Herman' -author = 'Sergio Fernández' -author = 'Carlos Tejo Alonso' -author = 'Alexey Zakhlestin' +project = "SPARQLWrapper" +copyright = "2019, `W3C® SOFTWARE NOTICE AND LICENSE `_" +author = "Ivan Herman" +author = "Sergio Fernández" +author = "Carlos Tejo Alonso" +author = "Alexey Zakhlestin" # The short X.Y version version = __version__ # The full version, including alpha/beta/rc tags -#release = u'1.8.5.dev0' +# release = u'1.8.5.dev0' # -- General configuration --------------------------------------------------- @@ -46,27 +46,27 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.viewcode', - 'sphinx.ext.githubpages', + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.doctest", + "sphinx.ext.intersphinx", + "sphinx.ext.todo", + "sphinx.ext.coverage", + "sphinx.ext.viewcode", + "sphinx.ext.githubpages", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -83,17 +83,17 @@ # The name of the Pygments (syntax highlighting) style to use. pygments_style = None -autodoc_member_order = 'bysource' +autodoc_member_order = "bysource" autodoc_default_options = { - 'members': None, - 'private-members': None, - 'show-inheritance': None, - 'special-members': '__init__' + "members": None, + "private-members": None, + "show-inheritance": None, + "special-members": "__init__", } -autoclass_content = 'class' -#autosummary_generate = True +autoclass_content = "class" +# autosummary_generate = True html_logo = "SPARQLWrapper-250.png" @@ -102,7 +102,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -110,17 +110,17 @@ # html_theme_options = { # Toc options - 'collapse_navigation': False, - 'sticky_navigation': True, - 'navigation_depth': 4, - 'includehidden': True, - 'titles_only': False + "collapse_navigation": False, + "sticky_navigation": True, + "navigation_depth": 4, + "includehidden": True, + "titles_only": False, } # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] +# html_static_path = ['_static'] # Custom sidebar templates, must be a dictionary that maps document names # to template names. @@ -141,7 +141,7 @@ # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. -htmlhelp_basename = 'SPARQLWrapperdoc' +htmlhelp_basename = "SPARQLWrapperdoc" html_show_copyright = False html_show_sphinx = False @@ -152,15 +152,12 @@ # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # # 'preamble': '', - # Latex figure (float) alignment # # 'figure_align': 'htbp', @@ -170,8 +167,13 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'SPARQLWrapper.tex', 'SPARQLWrapper Documentation', - 'CHANGE\\_AUTHORS', 'manual'), + ( + master_doc, + "SPARQLWrapper.tex", + "SPARQLWrapper Documentation", + "CHANGE\\_AUTHORS", + "manual", + ), ] @@ -179,10 +181,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, 'sparqlwrapper', 'SPARQLWrapper Documentation', - [author], 1) -] +man_pages = [(master_doc, "sparqlwrapper", "SPARQLWrapper Documentation", [author], 1)] # -- Options for Texinfo output ---------------------------------------------- @@ -191,9 +190,15 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'SPARQLWrapper', 'SPARQLWrapper Documentation', - author, 'SPARQLWrapper', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "SPARQLWrapper", + "SPARQLWrapper Documentation", + author, + "SPARQLWrapper", + "One line description of project.", + "Miscellaneous", + ), ] @@ -212,7 +217,7 @@ # epub_uid = '' # A list of files that should not be packed into the epub file. -epub_exclude_files = ['search.html'] +epub_exclude_files = ["search.html"] # -- Extension configuration ------------------------------------------------- @@ -221,7 +226,7 @@ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { -'https://docs.python.org/2/': None, + "https://docs.python.org/2/": None, } # -- Options for todo extension ---------------------------------------------- diff --git a/docs/source/index.rst b/docs/source/index.rst index d5147212..c220511c 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -15,7 +15,7 @@ format. :caption: Basic steps main - + .. toctree:: :hidden: :caption: Python Package @@ -35,4 +35,4 @@ Indices and tables .. |Build Status| image:: https://secure.travis-ci.org/RDFLib/sparqlwrapper.svg?branch=master :target: https://travis-ci.org/RDFLib/sparqlwrapper .. |PyPi version| image:: https://badge.fury.io/py/SPARQLWrapper.svg - :target: https://pypi.python.org/pypi/SPARQLWrapper \ No newline at end of file + :target: https://pypi.python.org/pypi/SPARQLWrapper diff --git a/docs/source/main.rst b/docs/source/main.rst index 57072757..4d2c74b3 100644 --- a/docs/source/main.rst +++ b/docs/source/main.rst @@ -1,3 +1,2 @@ .. include:: ../../README.rst - diff --git a/docs/source/modules.rst b/docs/source/modules.rst index 4942e285..ee7dd031 100644 --- a/docs/source/modules.rst +++ b/docs/source/modules.rst @@ -7,4 +7,3 @@ SPARQLWrapper package SPARQLWrapper.SmartWrapper SPARQLWrapper.SPARQLExceptions SPARQLWrapper.KeyCaseInsensitiveDict - diff --git a/requirements.development.txt b/requirements.development.txt deleted file mode 100644 index 5d7fdf2a..00000000 --- a/requirements.development.txt +++ /dev/null @@ -1,6 +0,0 @@ -setuptools>=3.7.1 -mypy>=0.931 -pandas-stubs>=1.2.0.48 --r requirements.optional.txt --r requirements.txt --r docs/requirements.docs.txt diff --git a/requirements.optional.txt b/requirements.optional.txt deleted file mode 100644 index 8ce10cad..00000000 --- a/requirements.optional.txt +++ /dev/null @@ -1,3 +0,0 @@ -# To use sparql_dataframe: -pandas>=1.3.5 --r requirements.txt diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a23dc0ff..00000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -rdflib>=6.1.1 diff --git a/scripts/example-ask.py b/scripts/example-ask.py index 89f9ed04..59f27dcf 100644 --- a/scripts/example-ask.py +++ b/scripts/example-ask.py @@ -1,35 +1,36 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -from SPARQLWrapper import SPARQLWrapper, JSON, XML, CSV, TSV +from SPARQLWrapper import CSV, JSON, TSV, XML, SPARQLWrapper sparql = SPARQLWrapper("http://dbpedia.org/sparql") -sparql.setQuery(""" - ASK WHERE { +sparql.setQuery( + """ + ASK WHERE { rdfs:label "Asturias"@es - } -""") + } +""" +) # JSON example -print('\n\n*** JSON Example') +print("\n\n*** JSON Example") sparql.setReturnFormat(JSON) results = sparql.query().convert() print(results) # XML example -print('\n\n*** XML Example') +print("\n\n*** XML Example") sparql.setReturnFormat(XML) results = sparql.query().convert() print(results.toxml()) # CSV example -print('\n\n*** CSV Example') +print("\n\n*** CSV Example") sparql.setReturnFormat(CSV) results = sparql.query().convert() print(results) # TSV example -print('\n\n*** TSV Example') +print("\n\n*** TSV Example") sparql.setReturnFormat(TSV) results = sparql.query().convert() print(results) diff --git a/scripts/example-construct.py b/scripts/example-construct.py index ea88555a..1c2d8e0c 100644 --- a/scripts/example-construct.py +++ b/scripts/example-construct.py @@ -1,51 +1,53 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -from SPARQLWrapper import SPARQLWrapper, XML, N3, TURTLE, JSONLD from rdflib import Graph +from SPARQLWrapper import JSONLD, N3, TURTLE, XML, SPARQLWrapper + sparql = SPARQLWrapper("http://dbpedia.org/sparql") -sparql.setQuery(""" +sparql.setQuery( + """ PREFIX dbo: PREFIX schema: - + CONSTRUCT { ?lang a schema:Language ; - schema:alternateName ?iso6391Code . + schema:alternateName ?iso6391Code . } WHERE { ?lang a dbo:Language ; dbo:iso6391Code ?iso6391Code . - + FILTER (STRLEN(?iso6391Code)=2) # to filter out non-valid values } -""") +""" +) # RDF/XML example -print('\n\n*** RDF/XML Example') +print("\n\n*** RDF/XML Example") sparql.setReturnFormat(XML) results = sparql.query().convert() -print(results.serialize(format='xml')) +print(results.serialize(format="xml")) # N3 example -print('\n\n*** N3 Example') +print("\n\n*** N3 Example") sparql.setReturnFormat(N3) results = sparql.query().convert() g = Graph() g.parse(data=results, format="n3") -print(g.serialize(format='n3')) +print(g.serialize(format="n3")) # Turtle example -print('\n\n*** TURTLE Example') +print("\n\n*** TURTLE Example") sparql.setReturnFormat(TURTLE) results = sparql.query().convert() g = Graph() g.parse(data=results, format="turtle") -print(g.serialize(format='turtle')) +print(g.serialize(format="turtle")) # JSONLD example -print('\n\n*** JSONLD Example') +print("\n\n*** JSONLD Example") sparql.setReturnFormat(JSONLD) results = sparql.query().convert() -print(results.serialize(format='json-ld')) +print(results.serialize(format="json-ld")) diff --git a/scripts/example-dbpedia.py b/scripts/example-dbpedia.py index 4bbfa071..111c473f 100644 --- a/scripts/example-dbpedia.py +++ b/scripts/example-dbpedia.py @@ -1,22 +1,24 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -from SPARQLWrapper import SPARQLWrapper, JSON +from SPARQLWrapper import JSON, SPARQLWrapper sparql = SPARQLWrapper("http://dbpedia.org/sparql") -sparql.setQuery(""" +sparql.setQuery( + """ PREFIX rdfs: SELECT ?label WHERE { rdfs:label ?label } -""") +""" +) sparql.setReturnFormat(JSON) results = sparql.query() results.print_results() print() -sparql.setQuery(""" +sparql.setQuery( + """ PREFIX rdfs: PREFIX dbp: SELECT ?cheese ?label @@ -25,7 +27,8 @@ dbp:region ; rdfs:label ?label . } -""") +""" +) sparql.setReturnFormat(JSON) results = sparql.query() results.print_results() diff --git a/scripts/example-delete.py b/scripts/example-delete.py index cd6a661f..282f6cc8 100644 --- a/scripts/example-delete.py +++ b/scripts/example-delete.py @@ -1,4 +1,4 @@ -from SPARQLWrapper import SPARQLWrapper, POST, DIGEST +from SPARQLWrapper import DIGEST, POST, SPARQLWrapper sparql = SPARQLWrapper("https://example.org/sparql-auth") @@ -6,11 +6,13 @@ sparql.setCredentials("login", "password") sparql.setMethod(POST) -sparql.setQuery(""" +sparql.setQuery( + """ WITH DELETE { rdfs:label "Asturies"@ast } -""") +""" +) results = sparql.query() -print(results.response.read()) \ No newline at end of file +print(results.response.read()) diff --git a/scripts/example-describe.py b/scripts/example-describe.py index a5cdce4c..e56ebac6 100644 --- a/scripts/example-describe.py +++ b/scripts/example-describe.py @@ -1,36 +1,39 @@ -from SPARQLWrapper import SPARQLWrapper, RDFXML, N3, TURTLE, JSONLD from rdflib import Graph +from SPARQLWrapper import JSONLD, N3, RDFXML, TURTLE, SPARQLWrapper + sparql = SPARQLWrapper("http://dbpedia.org/sparql") -sparql.setQuery(""" +sparql.setQuery( + """ DESCRIBE -""") +""" +) # RDF/XML example -print('\n\n*** RDF/XML Example') +print("\n\n*** RDF/XML Example") sparql.setReturnFormat(RDFXML) results = sparql.query().convert() -print(results.serialize(format='xml')) +print(results.serialize(format="xml")) # N3 example -print('\n\n*** N3 Example') +print("\n\n*** N3 Example") sparql.setReturnFormat(N3) results = sparql.query().convert() g = Graph() g.parse(data=results, format="n3") -print(g.serialize(format='n3')) +print(g.serialize(format="n3")) # Turtle example -print('\n\n*** TURTLE Example') +print("\n\n*** TURTLE Example") sparql.setReturnFormat(TURTLE) results = sparql.query().convert() g = Graph() g.parse(data=results, format="turtle") -print(g.serialize(format='turtle')) +print(g.serialize(format="turtle")) # JSONLD example -print('\n\n*** JSONLD Example') +print("\n\n*** JSONLD Example") sparql.setReturnFormat(JSONLD) results = sparql.query().convert() -print(results.serialize(format='json-ld')) +print(results.serialize(format="json-ld")) diff --git a/scripts/example-federated.py b/scripts/example-federated.py index dfcb5108..27edebfa 100644 --- a/scripts/example-federated.py +++ b/scripts/example-federated.py @@ -1,7 +1,6 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -from SPARQLWrapper import SPARQLWrapper, JSON +from SPARQLWrapper import JSON, SPARQLWrapper sparql = SPARQLWrapper("http://agrovoc.uniroma2.it:3030/agrovoc/sparql") @@ -16,10 +15,10 @@ skos:inScheme . FILTER (lang(?label) = 'en') - SERVICE { - ?conceptGEMET skos:prefLabel ?label ; + SERVICE { + ?conceptGEMET skos:prefLabel ?label ; skos:inScheme . - } + } } """ sparql.setQuery(query) diff --git a/scripts/example-insert-using-rdflib.py b/scripts/example-insert-using-rdflib.py index 241ac1c9..de6cf31e 100644 --- a/scripts/example-insert-using-rdflib.py +++ b/scripts/example-insert-using-rdflib.py @@ -1,23 +1,26 @@ -from rdflib import Graph, URIRef, Literal +from rdflib import Graph, Literal, URIRef from rdflib.namespace import RDFS +from SPARQLWrapper import DIGEST, POST, SPARQLWrapper + g = Graph() asturias = URIRef("http://dbpedia.org/resource/Asturias") -g.add( (asturias, RDFS.label, Literal('Asturies', lang="ast") ) ) -g.add( (asturias, RDFS.label, Literal('Asturias', lang="es") ) ) -g.add( (asturias, RDFS.label, Literal('Asturien', lang="de") ) ) +g.add((asturias, RDFS.label, Literal("Asturies", lang="ast"))) +g.add((asturias, RDFS.label, Literal("Asturias", lang="es"))) +g.add((asturias, RDFS.label, Literal("Asturien", lang="de"))) ############################################################################### triples = "" -for subject,predicate,obj in g: +for subject, predicate, obj in g: triples = triples + subject.n3() + " " + predicate.n3() + " " + obj.n3() + " . \n" -query = """WITH -INSERT {"""+ triples + """}""" +query = ( + """WITH +INSERT {""" + + triples + + """}""" +) ############################################################################### - -from SPARQLWrapper import SPARQLWrapper, POST, DIGEST - sparql = SPARQLWrapper("https://example.org/sparql-auth") sparql.setHTTPAuth(DIGEST) sparql.setCredentials("login", "password") diff --git a/scripts/example-insert.py b/scripts/example-insert.py index fa5fb58f..feebda89 100644 --- a/scripts/example-insert.py +++ b/scripts/example-insert.py @@ -1,4 +1,4 @@ -from SPARQLWrapper import SPARQLWrapper, POST, DIGEST +from SPARQLWrapper import DIGEST, POST, SPARQLWrapper sparql = SPARQLWrapper("https://example.org/sparql-auth") @@ -6,11 +6,13 @@ sparql.setCredentials("login", "password") sparql.setMethod(POST) -sparql.setQuery(""" +sparql.setQuery( + """ WITH INSERT { rdfs:label "Asturies"@ast } -""") +""" +) results = sparql.query() print(results.response.read()) diff --git a/scripts/example-optional.py b/scripts/example-optional.py index d613915a..f9e0c6b1 100644 --- a/scripts/example-optional.py +++ b/scripts/example-optional.py @@ -1,21 +1,22 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -from SPARQLWrapper import SPARQLWrapper, JSON +from SPARQLWrapper import JSON, SPARQLWrapper sparql = SPARQLWrapper("http://dbpedia.org/sparql") -sparql.setQuery(""" +sparql.setQuery( + """ PREFIX rdfs: SELECT ?person ?party - WHERE { ?person + WHERE { ?person OPTIONAL { ?person ?party } } -""") +""" +) # JSON example -print('\n\n*** JSON Example') +print("\n\n*** JSON Example") sparql.setReturnFormat(JSON) results = sparql.query().convert() for result in results["results"]["bindings"]: diff --git a/scripts/example.py b/scripts/example.py index c0a5ddea..4fa0dbfb 100644 --- a/scripts/example.py +++ b/scripts/example.py @@ -1,48 +1,49 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -from SPARQLWrapper import SPARQLWrapper, JSON, XML, N3, RDF, CSV, TSV +from SPARQLWrapper import CSV, JSON, N3, RDF, TSV, XML, SPARQLWrapper sparql = SPARQLWrapper("http://dbpedia.org/sparql") -sparql.setQuery(""" +sparql.setQuery( + """ PREFIX rdfs: SELECT ?label WHERE { rdfs:label ?label } -""") +""" +) # JSON example -print('\n\n*** JSON Example') +print("\n\n*** JSON Example") sparql.setReturnFormat(JSON) results = sparql.query().convert() for result in results["results"]["bindings"]: print(result["label"]["value"]) # XML example -print('\n\n*** XML Example') +print("\n\n*** XML Example") sparql.setReturnFormat(XML) results = sparql.query().convert() print(results.toxml()) # N3 example -print('\n\n*** N3 Example') +print("\n\n*** N3 Example") sparql.setReturnFormat(N3) results = sparql.query().convert() print(results) # RDF example -print('\n\n*** RDF Example') +print("\n\n*** RDF Example") sparql.setReturnFormat(RDF) results = sparql.query().convert() print(results.serialize()) # CSV example -print('\n\n*** CSV Example') +print("\n\n*** CSV Example") sparql.setReturnFormat(CSV) results = sparql.query().convert() print(results) # TSV example -print('\n\n*** TSV Example') +print("\n\n*** TSV Example") sparql.setReturnFormat(TSV) results = sparql.query().convert() print(results) diff --git a/scripts/sparql.py b/scripts/sparql.py index 36c943aa..6ad17ff3 100755 --- a/scripts/sparql.py +++ b/scripts/sparql.py @@ -1,13 +1,14 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import getopt +import sys + from SPARQLWrapper import SPARQLWrapper2 localSparqler = "http://localhost:2020/sparql" localVirtuoso = "http://localhost:8890/sparql" + def main(server, query, sponge=False): sparql = SPARQLWrapper2(server) if sponge: @@ -26,19 +27,18 @@ def main(server, query, sponge=False): try: val = b[v] if val.lang: - str = "%s: %s@%s" % (v, val.value, val.lang) + str = f"{v}: {val.value}@{val.lang}" elif val.datatype: - str = "%s: %s^^%s" % (v, val.value, val.datatype) + str = f"{v}: {val.value}^^{val.datatype}" else: - str = "%s: %s" % (v, val.value) + str = f"{v}: {val.value}" except KeyError: # no binding to that one... str = "%s: <>" % v - print(str.encode('utf-8')) + print(str.encode("utf-8")) print() - # ------------------------------------------------------------------------------------------------------------- server = localSparqler query = "" @@ -50,11 +50,14 @@ def main(server, query, sponge=False): -p: issue an extra sponge for virtuoso file: sparql query file """ + + def usage(): print(usagetxt % sys.argv[0]) sys.exit(1) -if __name__ == '__main__': + +if __name__ == "__main__": if len(sys.argv) == 1: usage() try: @@ -73,11 +76,11 @@ def usage(): elif o == "-p": sponge = True if query == "" and len(args) > 0: - inp = file(args[0]) + inp = open(args[0]) query = "" - for l in inp: - query += l - except: + for line in inp: + query += line + except Exception: usage() if query == "": usage() diff --git a/setup.cfg b/setup.cfg index 2da06390..b6c42551 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,16 +46,20 @@ SPARQLWrapper = py.typed [options.extras_require] dev = setuptools>=3.7.1 - mypy>=0.931 + types-setuptools>=57.4.10 + mypy>=0.941 pandas>=1.3.5 pandas-stubs>=1.2.0.48 - + isort>=5.10.1 + pytest>=7.1.0 + flake8-black>=0.3.2 + pre-commit>=2.17.0 pandas = pandas>=1.3.5 keepalive = keepalive>=0.5 docs = - sphinx < 5 + sphinx<5 sphinx-rtd-theme [options.entry_points] @@ -71,3 +75,13 @@ pretty = True warn_unused_configs = True warn_unused_ignores = True warn_unreachable = True + +[tool:black] +line-length = 120 + +[tool:isort] +profile = black + +[flake8] +max-line-length = 120 +exclude = .git,__pycache__,docs/source/conf.py,test,build,dist diff --git a/test/test_agrovoc-allegrograph_on_hold.py b/test/test_agrovoc-allegrograph_on_hold.py index 85373aee..7987d0db 100644 --- a/test/test_agrovoc-allegrograph_on_hold.py +++ b/test/test_agrovoc-allegrograph_on_hold.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -113,7 +112,7 @@ WHERE { res:Budapest prop:latitude ?lat; prop:longitude ?long. - } + } """ queryManyPrefixes = """ @@ -161,7 +160,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . @@ -210,7 +209,7 @@ def __generic( #### SELECT #### ################ - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testSelectByGETinXML(self): result = self.__generic(selectQuery, XML, GET) ct = result.info()["content-type"] @@ -271,7 +270,7 @@ def testSelectByPOSTinJSON(self): self.assertEqual(type(results), dict) # asking for an unexpected return format for SELECT queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testSelectByGETinN3(self): result = self.__generic(selectQuery, N3, GET) ct = result.info()["content-type"] @@ -282,7 +281,7 @@ def testSelectByGETinN3(self): # self.assertEqual(type(results), dict) # asking for an unexpected return format for SELECT queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testSelectByPOSTinN3(self): result = self.__generic(selectQuery, N3, POST) ct = result.info()["content-type"] @@ -293,7 +292,7 @@ def testSelectByPOSTinN3(self): # self.assertEqual(type(results), dict) # asking for an unexpected return format for SELECT queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testSelectByGETinJSONLD(self): result = self.__generic(selectQuery, JSONLD, GET) ct = result.info()["content-type"] @@ -304,7 +303,7 @@ def testSelectByGETinJSONLD(self): # self.assertEqual(type(results), dict) # asking for an unexpected return format for SELECT queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testSelectByPOSTinJSONLD(self): result = self.__generic(selectQuery, JSONLD, POST) ct = result.info()["content-type"] @@ -414,7 +413,7 @@ def testAskByPOSTinJSON(self): self.assertEqual(type(results), dict) # asking for an unexpected return format for ASK queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testAskByGETinN3(self): result = self.__generic(askQuery, N3, GET) ct = result.info()["content-type"] @@ -425,7 +424,7 @@ def testAskByGETinN3(self): # self.assertEqual(type(results), dict) # asking for an unexpected return format for ASK queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testAskByPOSTinN3(self): result = self.__generic(askQuery, N3, POST) ct = result.info()["content-type"] @@ -436,7 +435,7 @@ def testAskByPOSTinN3(self): # self.assertEqual(type(results), dict) # asking for an unexpected return format for ASK queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testAskByGETinJSONLD(self): result = self.__generic(askQuery, JSONLD, GET) ct = result.info()["content-type"] @@ -542,7 +541,7 @@ def testConstructByPOSTinJSONLD(self): self.assertEqual(type(results), ConjunctiveGraph) # asking for an unexpected return format for CONSTRUCT queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testConstructByGETinJSON(self): result = self.__generic(constructQuery, JSON, GET) ct = result.info()["content-type"] @@ -552,7 +551,7 @@ def testConstructByGETinJSON(self): # self.assertEqual(type(results), bytes) # asking for an unexpected return format for CONSTRUCT queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testConstructByPOSTinJSON(self): result = self.__generic(constructQuery, JSON, POST) ct = result.info()["content-type"] @@ -562,7 +561,7 @@ def testConstructByPOSTinJSON(self): # self.assertEqual(type(results), bytes) # asking for an unexpected return format for CONSTRUCT queryType. For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testConstructByGETinCSV(self): result = self.__generic(constructQuery, CSV, GET, onlyConneg=True) ct = result.info()["content-type"] @@ -576,7 +575,7 @@ def testConstructByGETinCSV(self): # asking for an unexpected return format for CONSTRUCT queryType. # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testConstructByPOSTinCSV(self): result = self.__generic(constructQuery, CSV, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -672,7 +671,7 @@ def testDescribeByPOSTinJSONLD(self): self.assertEqual(type(results), ConjunctiveGraph) # asking for an unexpected return format for DESCRIBE queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testDescribeByGETinJSON(self): result = self.__generic(describeQuery, JSON, GET) ct = result.info()["content-type"] @@ -682,7 +681,7 @@ def testDescribeByGETinJSON(self): # self.assertEqual(type(results), bytes) # asking for an unexpected return format for DESCRIBE queryType - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testDescribeByPOSTinJSON(self): result = self.__generic(describeQuery, JSON, POST) ct = result.info()["content-type"] @@ -693,7 +692,7 @@ def testDescribeByPOSTinJSON(self): # asking for an unexpected return format for DESCRIBE queryType. # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testDescribeByGETinCSV(self): result = self.__generic(describeQuery, CSV, GET, onlyConneg=True) ct = result.info()["content-type"] @@ -707,7 +706,7 @@ def testDescribeByGETinCSV(self): # asking for an unexpected return format for DESCRIBE queryType. # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # returned type has changed + @unittest.expectedFailure # returned type has changed def testDescribeByPOSTinCSV(self): result = self.__generic(describeQuery, CSV, POST, onlyConneg=True) ct = result.info()["content-type"] diff --git a/test/test_allegrograph__v4_14_1__mmi.py b/test/test_allegrograph__v4_14_1__mmi.py index 05b0d1c2..dc9307c2 100644 --- a/test/test_allegrograph__v4_14_1__mmi.py +++ b/test/test_allegrograph__v4_14_1__mmi.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -72,12 +71,12 @@ PREFIX rdfs: PREFIX skos: PREFIX ioosCat: - PREFIX ioosPlat: + PREFIX ioosPlat: """ selectQuery = """ - SELECT ?p - WHERE { ?p a ioosCat:Category } + SELECT ?p + WHERE { ?p a ioosCat:Category } ORDER BY ?p """ @@ -87,7 +86,7 @@ ?platform a ioosPlat:Platform . ?platform ioosPlat:Definition ?definition . ?cat skos:narrowMatch ?platform . - } + } ORDER BY ?cat ?platform """ askQuery = """ @@ -116,7 +115,7 @@ WHERE { res:Budapest prop:latitude ?lat; prop:longitude ?long. - } + } """ queryManyPrefixes = """ @@ -160,7 +159,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_blazegraph__wikidata.py b/test/test_blazegraph__wikidata.py index cec1e2d5..ed57f32c 100644 --- a/test/test_blazegraph__wikidata.py +++ b/test/test_blazegraph__wikidata.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -72,7 +71,7 @@ PREFIX rdf: PREFIX rdfs: PREFIX skos: - PREFIX entity: + PREFIX entity: """ selectQuery = """ @@ -97,7 +96,7 @@ } WHERE { rdfs:label ?label . - FILTER langMatches( lang(?label), "es" ) + FILTER langMatches( lang(?label), "es" ) } """ @@ -113,14 +112,14 @@ WHERE { res:Budapest prop:latitude ?lat; prop:longitude ?long. - } + } """ queryDuplicatedPrefix = """ PREFIX rdf: PREFIX rdf: PREFIX rdfs: PREFIX skos: - PREFIX entity: + PREFIX entity: SELECT ?predicate ?object WHERE { entity:Q3934 ?predicate ?object . @@ -169,7 +168,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_cli.py b/test/test_cli.py index 4f47c5a4..4e1d496b 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import io @@ -19,8 +18,8 @@ sys.path.insert(0, _top_level_path) # end of hack -from SPARQLWrapper.main import main, parse_args from SPARQLWrapper import POST +from SPARQLWrapper.main import main, parse_args endpoint = "http://ja.dbpedia.org/sparql" testfile = os.path.join(os.path.dirname(__file__), "test.rq") @@ -246,7 +245,16 @@ def testQueryWithFileN3(self): ) def testQueryRDF(self): - main(["-Q", "DESCRIBE ", "-e", endpoint, "-F", "rdf"]) + main( + [ + "-Q", + "DESCRIBE ", + "-e", + endpoint, + "-F", + "rdf", + ] + ) self.assertEqual( sys.stdout.getvalue(), diff --git a/test/test_fuseki2__v3_6_0__agrovoc.py b/test/test_fuseki2__v3_6_0__agrovoc.py index b1dc079a..7be18233 100644 --- a/test/test_fuseki2__v3_6_0__agrovoc.py +++ b/test/test_fuseki2__v3_6_0__agrovoc.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -113,7 +112,7 @@ WHERE { res:Budapest prop:latitude ?lat; prop:longitude ?long. - } + } """ queryManyPrefixes = """ @@ -161,7 +160,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_fuseki2__v3_8_0__stw.py b/test/test_fuseki2__v3_8_0__stw.py index 59abeb72..28c48e93 100644 --- a/test/test_fuseki2__v3_8_0__stw.py +++ b/test/test_fuseki2__v3_8_0__stw.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -114,7 +113,7 @@ WHERE { res:Budapest prop:latitude ?lat; prop:longitude ?long. - } + } """ queryManyPrefixes = """ @@ -162,7 +161,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_graphdbEnterprise__v8_9_0__rs.py b/test/test_graphdbEnterprise__v8_9_0__rs.py index c9e31f9a..89239d58 100644 --- a/test/test_graphdbEnterprise__v8_9_0__rs.py +++ b/test/test_graphdbEnterprise__v8_9_0__rs.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -173,7 +172,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_lov-fuseki_on_hold.py b/test/test_lov-fuseki_on_hold.py index 822be9a6..312f0b79 100644 --- a/test/test_lov-fuseki_on_hold.py +++ b/test/test_lov-fuseki_on_hold.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -116,7 +115,7 @@ WHERE { res:Budapest prop:latitude ?lat; prop:longitude ?long. - } + } """ queryManyPrefixes = """ @@ -164,7 +163,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_rdf4j__geosciml.py b/test/test_rdf4j__geosciml.py index 4e1609c0..9808ecb9 100644 --- a/test/test_rdf4j__geosciml.py +++ b/test/test_rdf4j__geosciml.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -170,7 +169,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_stardog__lindas.py b/test/test_stardog__lindas.py index 9507c417..99c24b76 100644 --- a/test/test_stardog__lindas.py +++ b/test/test_stardog__lindas.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -174,7 +173,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_store__v1_1_4.py b/test/test_store__v1_1_4.py index 7fd7b9d6..5cfb18c7 100644 --- a/test/test_store__v1_1_4.py +++ b/test/test_store__v1_1_4.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -159,7 +158,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . @@ -208,7 +207,7 @@ def __generic( #### SELECT #### ################ - @unittest.expectedFailure # HTTP Error 502: Bad Gateway + @unittest.expectedFailure # HTTP Error 502: Bad Gateway def testSelectByGETinXML(self): result = self.__generic(selectQuery, XML, GET) ct = result.info()["content-type"] @@ -225,7 +224,7 @@ def testSelectByGETinXML_Conneg(self): self.assertEqual(results.__class__.__module__, "xml.dom.minidom") self.assertEqual(results.__class__.__name__, "Document") - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinXML(self): result = self.__generic(selectQuery, XML, POST) ct = result.info()["content-type"] @@ -234,7 +233,7 @@ def testSelectByPOSTinXML(self): self.assertEqual(results.__class__.__module__, "xml.dom.minidom") self.assertEqual(results.__class__.__name__, "Document") - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinXML_Conneg(self): result = self.__generic(selectQuery, XML, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -257,7 +256,7 @@ def testSelectByGETinCSV_Conneg(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinCSV(self): result = self.__generic(selectQueryCSV_TSV, CSV, POST) ct = result.info()["content-type"] @@ -265,7 +264,7 @@ def testSelectByPOSTinCSV(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinCSV_Conneg(self): result = self.__generic(selectQueryCSV_TSV, CSV, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -290,7 +289,7 @@ def testSelectByGETinTSV_Conneg(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinTSV(self): result = self.__generic(selectQueryCSV_TSV, TSV, POST) ct = result.info()["content-type"] @@ -298,7 +297,7 @@ def testSelectByPOSTinTSV(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinTSV_Conneg(self): result = self.__generic(selectQueryCSV_TSV, TSV, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -320,7 +319,7 @@ def testSelectByGETinJSON_Conneg(self): results = result.convert() self.assertEqual(type(results), dict) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinJSON(self): result = self.__generic(selectQuery, JSON, POST) ct = result.info()["content-type"] @@ -328,7 +327,7 @@ def testSelectByPOSTinJSON(self): results = result.convert() self.assertEqual(type(results), dict) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinJSON_Conneg(self): result = self.__generic(selectQuery, JSON, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -364,7 +363,7 @@ def testSelectByGETinN3_Unexpected_Conneg(self): # Asking for an unexpected return format for SELECT queryType (n3 is not supported, and it is not a valid alias). # Set by default None (and sending */*). # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinN3_Unexpected(self): result = self.__generic(selectQuery, N3, POST) ct = result.info()["content-type"] @@ -376,7 +375,7 @@ def testSelectByPOSTinN3_Unexpected(self): # Asking for an unexpected return format for SELECT queryType (n3 is not supported, and it is not a valid alias). # Set by default None (and sending */*). # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinN3_Unexpected_Conneg(self): result = self.__generic(selectQuery, N3, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -410,7 +409,7 @@ def testSelectByGETinJSONLD_Unexpected_Conneg(self): # Asking for an unexpected return format for SELECT queryType (json-ld is not supported, it is not a valid alias). # Set by default None (and sending */*). # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinJSONLD_Unexpected(self): result = self.__generic(selectQuery, JSONLD, POST) ct = result.info()["content-type"] @@ -422,7 +421,7 @@ def testSelectByPOSTinJSONLD_Unexpected(self): # Asking for an unexpected return format for SELECT queryType (json-ld is not supported, it is not a valid alias). # Set by default None (and sending */*). # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinJSONLD_Unexpected_Conneg(self): result = self.__generic(selectQuery, JSONLD, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -433,7 +432,7 @@ def testSelectByPOSTinJSONLD_Unexpected_Conneg(self): # Asking for an unknown return format for SELECT queryType (XML is sent) # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 502: Bad Gateway + @unittest.expectedFailure # HTTP Error 502: Bad Gateway def testSelectByGETinUnknow(self): result = self.__generic(selectQuery, "foo", GET) ct = result.info()["content-type"] @@ -454,7 +453,7 @@ def testSelectByGETinUnknow_Conneg(self): # Asking for an unknown return format for SELECT queryType (XML is sent) # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinUnknow(self): result = self.__generic(selectQuery, "bar", POST) ct = result.info()["content-type"] @@ -465,7 +464,7 @@ def testSelectByPOSTinUnknow(self): # Asking for an unknown return format for SELECT queryType (XML is sent) # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testSelectByPOSTinUnknow_Conneg(self): result = self.__generic(selectQuery, "bar", POST, onlyConneg=True) ct = result.info()["content-type"] @@ -481,7 +480,7 @@ def testSelectByPOSTinUnknow_Conneg(self): #### ASK #### ############# - @unittest.expectedFailure # HTTP Error 502: Bad Gateway + @unittest.expectedFailure # HTTP Error 502: Bad Gateway def testAskByGETinXML(self): result = self.__generic(askQuery, XML, GET) ct = result.info()["content-type"] @@ -498,7 +497,7 @@ def testAskByGETinXML_Conneg(self): self.assertEqual(results.__class__.__module__, "xml.dom.minidom") self.assertEqual(results.__class__.__name__, "Document") - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinXML(self): result = self.__generic(askQuery, XML, POST) ct = result.info()["content-type"] @@ -507,7 +506,7 @@ def testAskByPOSTinXML(self): self.assertEqual(results.__class__.__module__, "xml.dom.minidom") self.assertEqual(results.__class__.__name__, "Document") - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinXML_Conneg(self): result = self.__generic(askQuery, XML, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -530,7 +529,7 @@ def testAskByGETinCSV_Conneg(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinCSV(self): result = self.__generic(askQuery, CSV, POST) ct = result.info()["content-type"] @@ -538,7 +537,7 @@ def testAskByPOSTinCSV(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinCSV_Conneg(self): result = self.__generic(askQuery, CSV, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -563,7 +562,7 @@ def testAskByGETinTSV_Conneg(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinTSV(self): result = self.__generic(askQuery, TSV, POST) ct = result.info()["content-type"] @@ -571,7 +570,7 @@ def testAskByPOSTinTSV(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinTSV_Conneg(self): result = self.__generic(askQuery, TSV, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -593,7 +592,7 @@ def testAskByGETinJSON_Conneg(self): results = result.convert() self.assertEqual(type(results), dict) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinJSON(self): result = self.__generic(askQuery, JSON, POST) ct = result.info()["content-type"] @@ -601,7 +600,7 @@ def testAskByPOSTinJSON(self): results = result.convert() self.assertEqual(type(results), dict) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinJSON_Conneg(self): result = self.__generic(askQuery, JSON, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -634,7 +633,7 @@ def testAskByGETinN3_Unexpected_Conneg(self): # Asking for an unexpected return format for ASK queryType (json-ld is not supported, it is not a valid alias). # Set by default None (and sending */*). # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinN3_Unexpected(self): result = self.__generic(askQuery, N3, POST) ct = result.info()["content-type"] @@ -646,7 +645,7 @@ def testAskByPOSTinN3_Unexpected(self): # Asking for an unexpected return format for ASK queryType (n3 is not supported, it is not a valid alias). # Set by default None (and sending */*). # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinN3_Unexpected_Conneg(self): result = self.__generic(askQuery, N3, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -680,7 +679,7 @@ def testAskByGETinJSONLD_Unexpected_Conneg(self): # Asking for an unexpected return format for ASK queryType (json-ld is not supported, it is not a valid alias). # Set by default None (and sending */*). # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinJSONLD_Unexpected(self): result = self.__generic(askQuery, JSONLD, POST) ct = result.info()["content-type"] @@ -692,7 +691,7 @@ def testAskByPOSTinJSONLD_Unexpected(self): # Asking for an unexpected return format for ASK queryType (json-ld is not supported, it is not a valid alias). # Set by default None (and sending */*). # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinJSONLD_Unexpected_Conneg(self): result = self.__generic(askQuery, JSONLD, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -703,7 +702,7 @@ def testAskByPOSTinJSONLD_Unexpected_Conneg(self): # asking for an unknown return format for ASK queryType (XML is sent) # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 502: Bad Gateway + @unittest.expectedFailure # HTTP Error 502: Bad Gateway def testAskByGETinUnknow(self): result = self.__generic(askQuery, "foo", GET) ct = result.info()["content-type"] @@ -724,7 +723,7 @@ def testAskByGETinUnknow_Conneg(self): # Asking for an unknown return format for ASK queryType (XML is sent) # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinUnknow(self): result = self.__generic(askQuery, "bar", POST) ct = result.info()["content-type"] @@ -735,7 +734,7 @@ def testAskByPOSTinUnknow(self): # Asking for an unknown return format for ASK queryType (XML is sent) # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testAskByPOSTinUnknow_Conneg(self): result = self.__generic(askQuery, "bar", POST, onlyConneg=True) ct = result.info()["content-type"] @@ -751,7 +750,7 @@ def testAskByPOSTinUnknow_Conneg(self): #### CONSTRUCT #### ################### - @unittest.expectedFailure # HTTP Error 502: Bad Gateway + @unittest.expectedFailure # HTTP Error 502: Bad Gateway def testConstructByGETinXML(self): result = self.__generic(constructQuery, XML, GET) ct = result.info()["content-type"] @@ -766,7 +765,7 @@ def testConstructByGETinXML_Conneg(self): results = result.convert() self.assertEqual(type(results), ConjunctiveGraph) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinXML(self): result = self.__generic(constructQuery, XML, POST) ct = result.info()["content-type"] @@ -774,7 +773,7 @@ def testConstructByPOSTinXML(self): results = result.convert() self.assertEqual(type(results), ConjunctiveGraph) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinXML_Conneg(self): result = self.__generic(constructQuery, XML, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -800,7 +799,7 @@ def testConstructByGETinRDFXML_Conneg(self): results = result.convert() self.assertEqual(type(results), ConjunctiveGraph) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinRDFXML(self): result = self.__generic(constructQuery, RDFXML, POST) ct = result.info()["content-type"] @@ -809,7 +808,7 @@ def testConstructByPOSTinRDFXML(self): self.assertEqual(type(results), ConjunctiveGraph) # rdf+xml is not a valid alias - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinRDFXML_Conneg(self): result = self.__generic(constructQuery, RDFXML, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -839,7 +838,7 @@ def testConstructByGETinTURTLE_Conneg(self): # turtle is not a valid alias ('text' is the one used) # But it returns text/turtle - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinTURTLE(self): result = self.__generic(constructQuery, TURTLE, POST) ct = result.info()["content-type"] @@ -849,7 +848,7 @@ def testConstructByPOSTinTURTLE(self): # turtle is not a valid alias ('text' is the one used) # Working with Content Negotiation - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinTURTLE_Conneg(self): result = self.__generic(constructQuery, TURTLE, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -875,7 +874,7 @@ def testConstructByGETinN3_Conneg(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinN3(self): result = self.__generic(constructQuery, N3, POST) ct = result.info()["content-type"] @@ -884,7 +883,7 @@ def testConstructByPOSTinN3(self): self.assertEqual(type(results), bytes) # Returns text/turtle - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinN3_Conneg(self): result = self.__generic(constructQuery, N3, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -947,7 +946,7 @@ def testConstructByGETinCSV_Unexpected_Conneg(self): # Asking for an unexpected return format for CONSTRUCT queryType. # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinCSV_Unexpected(self): result = self.__generic(constructQuery, CSV, POST) ct = result.info()["content-type"] @@ -957,7 +956,7 @@ def testConstructByPOSTinCSV_Unexpected(self): # Asking for an unexpected return format for CONSTRUCT queryType. # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinCSV_Unexpected_Conneg(self): result = self.__generic(constructQuery, CSV, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -986,7 +985,7 @@ def testConstructByGETinJSON_Unexpected_Conneg(self): # Asking for an unexpected return format for CONSTRUCT queryType. # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinJSON_Unexpected(self): result = self.__generic(constructQuery, JSON, POST) ct = result.info()["content-type"] @@ -996,7 +995,7 @@ def testConstructByPOSTinJSON_Unexpected(self): # Asking for an unexpected return format for CONSTRUCT queryType. # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinJSON_Unexpected_Conneg(self): result = self.__generic(constructQuery, JSON, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -1006,7 +1005,7 @@ def testConstructByPOSTinJSON_Unexpected_Conneg(self): # Asking for an unknown return format for CONSTRUCT queryType (XML is sent) # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 502: Bad Gateway + @unittest.expectedFailure # HTTP Error 502: Bad Gateway def testConstructByGETinUnknow(self): result = self.__generic(constructQuery, "foo", GET) ct = result.info()["content-type"] @@ -1025,7 +1024,7 @@ def testConstructByGETinUnknow_Conneg(self): # Asking for an unknown return format for CONSTRUCT queryType (XML is sent) # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinUnknow(self): result = self.__generic(constructQuery, "bar", POST) ct = result.info()["content-type"] @@ -1035,7 +1034,7 @@ def testConstructByPOSTinUnknow(self): # Asking for an unknown return format for CONSTRUCT queryType (XML is sent) # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testConstructByPOSTinUnknow_Conneg(self): result = self.__generic(constructQuery, "bar", POST, onlyConneg=True) ct = result.info()["content-type"] @@ -1050,7 +1049,7 @@ def testConstructByPOSTinUnknow_Conneg(self): #### DESCRIBE #### ################## - @unittest.expectedFailure # HTTP Error 502: Bad Gateway + @unittest.expectedFailure # HTTP Error 502: Bad Gateway def testDescribeByGETinXML(self): result = self.__generic(describeQuery, XML, GET) ct = result.info()["content-type"] @@ -1065,7 +1064,7 @@ def testDescribeByGETinXML_Conneg(self): results = result.convert() self.assertEqual(type(results), ConjunctiveGraph) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinXML(self): result = self.__generic(describeQuery, XML, POST) ct = result.info()["content-type"] @@ -1073,7 +1072,7 @@ def testDescribeByPOSTinXML(self): results = result.convert() self.assertEqual(type(results), ConjunctiveGraph) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinXML_Conneg(self): result = self.__generic(describeQuery, XML, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -1101,7 +1100,7 @@ def testDescribeByGETinRDFXML_Conneg(self): self.assertEqual(type(results), ConjunctiveGraph) # rdf+xml is not a valid alias - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinRDFXML(self): result = self.__generic(describeQuery, RDFXML, POST) ct = result.info()["content-type"] @@ -1110,7 +1109,7 @@ def testDescribeByPOSTinRDFXML(self): self.assertEqual(type(results), ConjunctiveGraph) # rdf+xml is not a valid alias - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinRDFXML_Conneg(self): result = self.__generic(describeQuery, RDFXML, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -1141,7 +1140,7 @@ def testDescribeByGETinTURTLE_Conneg(self): self.assertEqual(type(results), bytes) # turtle is not a valid alias ('text' is the one used) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinTURTLE(self): result = self.__generic(describeQuery, TURTLE, POST) ct = result.info()["content-type"] @@ -1150,7 +1149,7 @@ def testDescribeByPOSTinTURTLE(self): self.assertEqual(type(results), bytes) # turtle is not a valid alias ('text' is the one used) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinTURTLE_Conneg(self): result = self.__generic(describeQuery, TURTLE, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -1179,7 +1178,7 @@ def testDescribeByGETinN3_Conneg(self): results = result.convert() self.assertEqual(type(results), bytes) - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinN3(self): result = self.__generic(describeQuery, N3, POST) ct = result.info()["content-type"] @@ -1188,7 +1187,7 @@ def testDescribeByPOSTinN3(self): self.assertEqual(type(results), bytes) # Returns text/turtle - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinN3_Conneg(self): result = self.__generic(describeQuery, N3, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -1251,7 +1250,7 @@ def testDescribeByGETinCSV_Unexpected_Conneg(self): # Asking for an unexpected return format for DESCRIBE queryType. # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinCSV_Unexpected(self): result = self.__generic(describeQuery, CSV, POST) ct = result.info()["content-type"] @@ -1261,7 +1260,7 @@ def testDescribeByPOSTinCSV_Unexpected(self): # Asking for an unexpected return format for DESCRIBE queryType. # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinCSV_Unexpected_Conneg(self): result = self.__generic(describeQuery, CSV, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -1292,7 +1291,7 @@ def testDescribeByGETinJSON_Unexpected_Conneg(self): # Asking for an unexpected return format for DESCRIBE queryType. # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinJSON_Unexpected(self): result = self.__generic(describeQuery, JSON, POST) ct = result.info()["content-type"] @@ -1302,7 +1301,7 @@ def testDescribeByPOSTinJSON_Unexpected(self): # Asking for an unexpected return format for DESCRIBE queryType. # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinJSON_Unexpected_Conneg(self): result = self.__generic(describeQuery, JSON, POST, onlyConneg=True) ct = result.info()["content-type"] @@ -1312,7 +1311,7 @@ def testDescribeByPOSTinJSON_Unexpected_Conneg(self): # Asking for an unknown return format for DESCRIBE queryType (XML is sent) # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 502: Bad Gateway + @unittest.expectedFailure # HTTP Error 502: Bad Gateway def testDescribeByGETinUnknow(self): result = self.__generic(describeQuery, "foo", GET) ct = result.info()["content-type"] @@ -1331,7 +1330,7 @@ def testDescribeByGETinUnknow_Conneg(self): # Asking for an unknown return format for DESCRIBE queryType (XML is sent) # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinUnknow(self): result = self.__generic(describeQuery, "bar", POST) ct = result.info()["content-type"] @@ -1341,7 +1340,7 @@ def testDescribeByPOSTinUnknow(self): # Asking for an unknown return format for DESCRIBE queryType (XML is sent) # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) is application/rdf+xml - @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error + @unittest.expectedFailure # HTTP Error 500: SPARQL protocol error def testDescribeByPOSTinUnknow_Conneg(self): result = self.__generic(describeQuery, "bar", POST, onlyConneg=True) ct = result.info()["content-type"] diff --git a/test/test_virtuoso__v7_20_3230__dbpedia.py b/test/test_virtuoso__v7_20_3230__dbpedia.py index 1a864603..95732df3 100644 --- a/test/test_virtuoso__v7_20_3230__dbpedia.py +++ b/test/test_virtuoso__v7_20_3230__dbpedia.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -161,7 +160,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_virtuoso__v8_03_3313__dbpedia.py b/test/test_virtuoso__v8_03_3313__dbpedia.py index 1d4d9f18..90692462 100644 --- a/test/test_virtuoso__v8_03_3313__dbpedia.py +++ b/test/test_virtuoso__v8_03_3313__dbpedia.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import os @@ -161,7 +160,7 @@ } """ -queryWithCommaInCurie_2 = """ +queryWithCommaInCurie_2 = r""" PREFIX dbpedia: SELECT ?article ?title WHERE { ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . diff --git a/test/test_wrapper.py b/test/test_wrapper.py index a8ccccd6..1b9e82bc 100644 --- a/test/test_wrapper.py +++ b/test/test_wrapper.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect import logging @@ -66,7 +65,7 @@ ) -class FakeResult(object): +class FakeResult: def __init__(self, request): self.request = request @@ -588,7 +587,7 @@ def testQueryEncoding(self): def testQueryAndConvert(self): _oldQueryResult = _victim.QueryResult - class FakeQueryResult(object): + class FakeQueryResult: def __init__(self, result): pass @@ -629,11 +628,11 @@ def testHashInPrefixComplex(self): PREFIX rdf: PREFIX rdfs: PREFIX weather: -PREFIX dbo: -PREFIX dbr: -PREFIX dbp: -PREFIX xml: -PREFIX xsd: +PREFIX dbo: +PREFIX dbr: +PREFIX dbp: +PREFIX xml: +PREFIX xsd: SELECT DISTINCT ?location ?cityid ?timezone ?label WHERE { @@ -795,7 +794,7 @@ def testConstructor(self): self.assertEqual("format", qr.requestedFormat) def testProxyingToResponse(self): - class FakeResponse(object): + class FakeResponse: def __init__(self): self.geturl_called = False self.info_called = False @@ -833,7 +832,7 @@ def __next__(self): ) def testConvert(self): - class FakeResponse(object): + class FakeResponse: def __init__(self, content_type): self.content_type = content_type @@ -902,7 +901,7 @@ def testPrint_results(self): print_results() is only allowed for JSON return format. """ - class FakeResponse(object): + class FakeResponse: def __init__(self, content_type): self.content_type = content_type