Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and aucampia committed May 19, 2022
1 parent 2d6a05d commit ba855c2
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 121 deletions.
6 changes: 3 additions & 3 deletions rdflib/namespace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def __getattr__(cls, name: str):
return cls.__getitem__(name)

def __repr__(cls) -> str:
return f'Namespace({str(cls._NS)!r})'
return f"Namespace({str(cls._NS)!r})"

def __str__(cls) -> str:
return str(cls._NS)
Expand Down Expand Up @@ -275,9 +275,9 @@ def as_jsonld_context(self, pfx: str) -> dict:
terms = {pfx: str(self._NS)}
for key, term in self.__annotations__.items():
if issubclass(term, URIRef):
terms[key] = f'{pfx}:{key}'
terms[key] = f"{pfx}:{key}"

return {'@context': terms}
return {"@context": terms}


class DefinedNamespace(metaclass=DefinedNamespaceMeta):
Expand Down
8 changes: 4 additions & 4 deletions rdflib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ class URLInputSource(InputSource):
links: List[str]

@classmethod
def getallmatchingheaders(cls, message: 'HTTPMessage', name):
def getallmatchingheaders(cls, message: "HTTPMessage", name):
# This is reimplemented here, because the method
# getallmatchingheaders from HTTPMessage is broken since Python 3.0
name = name.lower()
return [val for key, val in message.items() if key.lower() == name]

@classmethod
def get_links(cls, response: 'HTTPResponse'):
def get_links(cls, response: "HTTPResponse"):
linkslines = cls.getallmatchingheaders(response.headers, "Link")
retarray = []
for linksline in linkslines:
Expand All @@ -214,8 +214,8 @@ def get_links(cls, response: 'HTTPResponse'):
return retarray

def get_alternates(self, type_: Optional[str] = None) -> List[str]:
typestr: Optional[str] = f"type=\"{type_}\"" if type_ else None
relstr = "rel=\"alternate\""
typestr: Optional[str] = f'type="{type_}"' if type_ else None
relstr = 'rel="alternate"'
alts = []
for link in self.links:
parts = [p.strip() for p in link.split(";")]
Expand Down
2 changes: 1 addition & 1 deletion rdflib/plugins/sparql/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def sparql_query_text(node):
)
aggr_vars[agg_func.res].append(agg_func.vars)

agg_func_name = agg_func.name.split('_')[1]
agg_func_name = agg_func.name.split("_")[1]
distinct = ""
if agg_func.distinct:
distinct = agg_func.distinct + " "
Expand Down
6 changes: 3 additions & 3 deletions rdflib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ def from_n3(s: str, default=None, backend=None, nsm=None):
return Literal(s == "true")
elif (
s.lower()
.replace('.', '', 1)
.replace('-', '', 1)
.replace('e', '', 1)
.replace(".", "", 1)
.replace("-", "", 1)
.replace("e", "", 1)
.isnumeric()
):
if "e" in s.lower():
Expand Down
4 changes: 2 additions & 2 deletions test/jsonld/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def make_fake_urlinputsource(input_uri, format=None, suite_base=None, options={}
if "httpLink" in options:
source.links.append(options["httpLink"])
if "contentType" in options:
source.content_type = options['contentType']
source.content_type = options["contentType"]
if "redirectTo" in options:
redir = suite_base + options['redirectTo']
redir = suite_base + options["redirectTo"]
local_redirect = redir.replace(
"https://w3c.github.io/json-ld-api/tests/", "./"
)
Expand Down
78 changes: 39 additions & 39 deletions test/test_graph/test_namespace_rebinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_binding_replace():
g.bind("foaf", FOAF1)
g.bind("foaf2", FOAF2)
assert len(list(g.namespaces())) == 2
assert list(g.namespaces()) == [('foaf', foaf1_uri), ("foaf2", foaf2_uri)]
assert list(g.namespaces()) == [("foaf", foaf1_uri), ("foaf2", foaf2_uri)]

# Now you want to "upgrade" to FOAF2=>foaf and try the obvious:
g.bind("foaf", FOAF2)
Expand All @@ -61,7 +61,7 @@ def test_binding_replace():

assert list(g.namespaces()) == [
("foaf", foaf2_uri), # Should be present but has been removed.
('oldfoaf', foaf1_uri),
("oldfoaf", foaf1_uri),
]

# 2. Changing the prefix of an existing namespace=>prefix binding:
Expand All @@ -72,7 +72,7 @@ def test_binding_replace():

# Which, as things stand, results in:

assert list(g.namespaces()) == [("foaf", foaf2_uri), ('foaf1', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf2_uri), ("foaf1", foaf1_uri)]

# In which the attempted change from `oldfoaf` to (the already
# bound-to-a different-namespace `foaf`) was intercepted and
Expand All @@ -82,13 +82,13 @@ def test_binding_replace():
g.bind("oldfoaf", FOAF1, replace=True)

# The bindings are again as desired
assert list(g.namespaces()) == [("foaf", foaf2_uri), ('oldfoaf', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf2_uri), ("oldfoaf", foaf1_uri)]

# Next time through, set override to False
g.bind("foaf", FOAF1, override=False)

# And the bindings will remain as desired
assert list(g.namespaces()) == [("foaf", foaf2_uri), ('oldfoaf', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf2_uri), ("oldfoaf", foaf1_uri)]

# 3. Parsing data with prefix=>namespace bindings
# Let's see the situation regarding namespace bindings
Expand All @@ -108,7 +108,7 @@ def test_binding_replace():
# non-clashing prefix of `foaf1` is rebound to FOAF1 in
# place of the existing `oldfoaf` prefix

assert list(g.namespaces()) == [("foaf", foaf2_uri), ('foaf1', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf2_uri), ("foaf1", foaf1_uri)]

# Yes, namespace bindings in parsed data replace existing
# bindings (i.e. `oldfoaf` was replaced by `foaf1`), just
Expand All @@ -128,7 +128,7 @@ def test_binding_replace():
# by the `foaf2=>FOAF2` binding specified in the N3 source

assert list(g.namespaces()) == [
('foaf1', foaf1_uri),
("foaf1", foaf1_uri),
("foaf2", foaf2_uri),
]

Expand All @@ -146,7 +146,7 @@ def test_binding_replace():
# used

assert list(g.namespaces()) == [
('foaf1', foaf1_uri),
("foaf1", foaf1_uri),
("foaf2", foaf2_uri),
]

Expand All @@ -161,7 +161,7 @@ def test_binding_replace():

assert list(g.namespaces()) == [
("foaf2", foaf2_uri),
('foaf', foaf1_uri),
("foaf", foaf1_uri),
]

# Prefixes are bound to namespaces which in turn have a URIRef
Expand Down Expand Up @@ -191,11 +191,11 @@ def test_prefix_alias_disallowed():

g = Graph(bind_namespaces="none")
g.bind("owl", OWL)
assert ('owl', URIRef('http://www.w3.org/2002/07/owl#')) in list(g.namespaces())
assert ("owl", URIRef("http://www.w3.org/2002/07/owl#")) in list(g.namespaces())

g.bind("wol", OWL, override=False)
assert ('owl', URIRef('http://www.w3.org/2002/07/owl#')) in list(g.namespaces())
assert ('wol', URIRef('http://www.w3.org/2002/07/owl#')) not in list(g.namespaces())
assert ("owl", URIRef("http://www.w3.org/2002/07/owl#")) in list(g.namespaces())
assert ("wol", URIRef("http://www.w3.org/2002/07/owl#")) not in list(g.namespaces())


def test_rebind_prefix_succeeds():
Expand All @@ -204,11 +204,11 @@ def test_rebind_prefix_succeeds():

g = Graph(bind_namespaces="none")
g.bind("owl", OWL)
assert ('owl', URIRef('http://www.w3.org/2002/07/owl#')) in list(g.namespaces())
assert ("owl", URIRef("http://www.w3.org/2002/07/owl#")) in list(g.namespaces())

g.bind("wol", OWL)
assert ('wol', URIRef('http://www.w3.org/2002/07/owl#')) in list(g.namespaces())
assert ('owl', URIRef('http://www.w3.org/2002/07/owl#')) not in list(g.namespaces())
assert ("wol", URIRef("http://www.w3.org/2002/07/owl#")) in list(g.namespaces())
assert ("owl", URIRef("http://www.w3.org/2002/07/owl#")) not in list(g.namespaces())


def test_parse_rebinds_prefix():
Expand All @@ -223,14 +223,14 @@ def test_parse_rebinds_prefix():

# Use full set of namespace bindings, including foaf
g = Graph(bind_namespaces="none")
g.bind('foaf', FOAF1)
assert ('foaf', foaf1_uri) in list(g.namespaces())
g.bind("foaf", FOAF1)
assert ("foaf", foaf1_uri) in list(g.namespaces())

g.parse(data=data, format="n3")

# foaf no longer in set of namespace bindings
assert ('foaf', foaf1_uri) not in list(g.namespaces())
assert ('friend-of-a-friend', foaf1_uri) in list(g.namespaces())
assert ("foaf", foaf1_uri) not in list(g.namespaces())
assert ("friend-of-a-friend", foaf1_uri) in list(g.namespaces())


@pytest.mark.xfail(
Expand All @@ -254,7 +254,7 @@ def test_automatic_handling_of_unknown_predicates():

g = Graph(bind_namespaces="none")

g.add((tarek, URIRef('http://xmlns.com/foaf/0.1/name'), Literal("Tarek")))
g.add((tarek, URIRef("http://xmlns.com/foaf/0.1/name"), Literal("Tarek")))

assert len(list(g.namespaces())) > 0

Expand All @@ -263,7 +263,7 @@ def test_automatic_handling_of_unknown_predicates_only_effected_after_serializat

g = Graph(bind_namespaces="none")

g.add((tarek, URIRef('http://xmlns.com/foaf/0.1/name'), Literal("Tarek")))
g.add((tarek, URIRef("http://xmlns.com/foaf/0.1/name"), Literal("Tarek")))

assert "@prefix ns1: <http://xmlns.com/foaf/0.1/> ." in g.serialize(format="n3")

Expand All @@ -282,27 +282,27 @@ def test_multigraph_bindings():

g1 = Graph(store, identifier=context1, bind_namespaces="none")

g1.bind('foaf', FOAF1)
assert list(g1.namespaces()) == [('foaf', foaf1_uri)]
assert list(store.namespaces()) == [('foaf', foaf1_uri)]
g1.bind("foaf", FOAF1)
assert list(g1.namespaces()) == [("foaf", foaf1_uri)]
assert list(store.namespaces()) == [("foaf", foaf1_uri)]

g1.add((tarek, FOAF1.name, Literal("tarek")))

assert list(store.namespaces()) == [('foaf', foaf1_uri)]
assert list(store.namespaces()) == [("foaf", foaf1_uri)]

g2 = Graph(store, identifier=context2, bind_namespaces="none")
g2.parse(data=data, format="n3")

# The parser-caused rebind is in the underlying store and all objects
# that use the store see the changed binding:
assert list(store.namespaces()) == [('friend-of-a-friend', foaf1_uri)]
assert list(g1.namespaces()) == [('friend-of-a-friend', foaf1_uri)]
assert list(store.namespaces()) == [("friend-of-a-friend", foaf1_uri)]
assert list(g1.namespaces()) == [("friend-of-a-friend", foaf1_uri)]

# Including newly-created objects that use the store
cg = ConjunctiveGraph(store=store)

assert ('foaf', foaf1_uri) not in list(cg.namespaces())
assert ('friend-of-a-friend', foaf1_uri) in list(cg.namespaces())
assert ("foaf", foaf1_uri) not in list(cg.namespaces())
assert ("friend-of-a-friend", foaf1_uri) in list(cg.namespaces())

assert len(list(g1.namespaces())) == 6
assert len(list(g2.namespaces())) == 6
Expand All @@ -324,24 +324,24 @@ def test_multigraph_bindings():

# Add foaf2 binding if not already bound
cg.bind("foaf2", FOAF2, override=False)
assert ('foaf2', foaf2_uri) in list(cg.namespaces())
assert ("foaf2", foaf2_uri) in list(cg.namespaces())

# Impose foaf binding ... if not already bound
cg.bind("foaf", FOAF1, override=False)
assert ('foaf', foaf1_uri) not in list(cg.namespaces())
assert ("foaf", foaf1_uri) not in list(cg.namespaces())


def test_new_namespace_new_prefix():
g = Graph(bind_namespaces="none")
g.bind("foaf", FOAF1)
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf1_uri)]


def test_change_prefix_override_true():
g = Graph(bind_namespaces="none")

g.bind("foaf", FOAF1)
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf1_uri)]

g.bind("oldfoaf", FOAF1)
# Changed
Expand All @@ -352,7 +352,7 @@ def test_change_prefix_override_false():
g = Graph(bind_namespaces="none")

g.bind("foaf", FOAF1)
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf1_uri)]

g.bind("oldfoaf", FOAF1, override=False)
# No change
Expand All @@ -363,7 +363,7 @@ def test_change_namespace_override_true():
g = Graph(bind_namespaces="none")

g.bind("foaf", FOAF1)
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf1_uri)]

g.bind("foaf", FOAF2)
# Different prefix used
Expand All @@ -374,7 +374,7 @@ def test_change_namespace_override_false():
g = Graph(bind_namespaces="none")

g.bind("foaf", FOAF1)
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf1_uri)]

# Different namespace so override is irrelevant in this case
g.bind("foaf", FOAF2, override=False)
Expand All @@ -386,14 +386,14 @@ def test_new_namespace_override_false():
g = Graph(bind_namespaces="none")

g.bind("foaf", FOAF2)
assert list(g.namespaces()) == [('foaf', foaf2_uri)]
assert list(g.namespaces()) == [("foaf", foaf2_uri)]

# Namespace not already bound so override is irrelevant in this case
g.bind("owl", OWL, override=False)
# Given prefix used
assert list(g.namespaces()) == [
("foaf", foaf2_uri),
('owl', URIRef('http://www.w3.org/2002/07/owl#')),
("owl", URIRef("http://www.w3.org/2002/07/owl#")),
]


Expand All @@ -406,7 +406,7 @@ def test_change_namespace_and_prefix():
g = Graph(bind_namespaces="none")

g.bind("foaf", FOAF1)
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
assert list(g.namespaces()) == [("foaf", foaf1_uri)]

g.bind("foaf", FOAF2, replace=True)
assert list(g.namespaces()) == [("foaf", foaf2_uri)]
Expand Down
6 changes: 3 additions & 3 deletions test/test_issues/test_issue1404.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ def test_skolem_de_skolem_roundtrip():
Issue: https://github.com/RDFLib/rdflib/issues/1404
"""

ttl = '''
ttl = """
@prefix wd: <http://www.wikidata.org/entity/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
wd:Q1203 foaf:knows [ a foaf:Person;
foaf:name "Ringo" ].
'''
"""

graph = Graph()
graph.parse(data=ttl, format='turtle')
graph.parse(data=ttl, format="turtle")

query = {
"subject": URIRef("http://www.wikidata.org/entity/Q1203"),
Expand Down
6 changes: 3 additions & 3 deletions test/test_issues/test_issue1808.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test():
for s, p, o in gs:
assert isinstance(s, URIRef) and s.__contains__(rdflib_skolem_genid)

query_with_iri = 'select ?p ?o {{ <{}> ?p ?o }}'.format(s)
query_for_all = 'select ?s ?p ?o { ?s ?p ?o }'
query_with_iri = "select ?p ?o {{ <{}> ?p ?o }}".format(s)
query_for_all = "select ?s ?p ?o { ?s ?p ?o }"

count = 0
for row in gs.query(query_with_iri):
Expand All @@ -31,7 +31,7 @@ def test():
assert count == 1

gp = Graph()
gp.parse(data=gs.serialize(format='turtle'), format='turtle')
gp.parse(data=gs.serialize(format="turtle"), format="turtle")

count = 0
for row in gp.query(query_with_iri):
Expand Down
Loading

0 comments on commit ba855c2

Please sign in to comment.