Skip to content

Commit

Permalink
remaining namespace pollution issue, fixes #34.
Browse files Browse the repository at this point in the history
Added tests for 34
  • Loading branch information
cmungall committed Aug 8, 2023
1 parent 03dd50f commit 3100872
Show file tree
Hide file tree
Showing 9 changed files with 5,774 additions and 5,703 deletions.
2 changes: 1 addition & 1 deletion funowl/writers/FunctionalWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, tab: Optional[str] = None, g: Optional[Graph] = None) -> None
"""
self.tab = FunctionalWriter.DEFAULT_TAB if tab is None else tab
if g is None:
self.g = Graph()
self.g = Graph(bind_namespaces="core")
self.g.bind('owl', OWL)
else:
self.g = g
Expand Down
328 changes: 164 additions & 164 deletions tests/data/pizza_out.ttl

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions tests/test_base/test_prefixdeclarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@ def test_prefix(self):
with self.assertRaises(TypeError):
Prefix('http:', RDFS)

def test_prefix_append(self):
"""
Test that prefixes can be appended correctly.
Note that rdflib introduces namespace pollution by default,
this checks we instantiate rdf graphs in a way that avoids this.
"""
pds = PrefixDeclarations()
pds.append(Prefix("schema", "http://schema.org/"))
self.assertEqualOntology('''Prefix( xml: = <http://www.w3.org/XML/1998/namespace> )
Prefix( rdf: = <http://www.w3.org/1999/02/22-rdf-syntax-ns#> )
Prefix( rdfs: = <http://www.w3.org/2000/01/rdf-schema#> )
Prefix( xsd: = <http://www.w3.org/2001/XMLSchema#> )
Prefix( owl: = <http://www.w3.org/2002/07/owl#> )
Prefix( schema: = <http://schema.org/> )''', str(pds.to_functional(self.w.reset())))
pds = PrefixDeclarations()
pds.append(Prefix("schema", "https://schema.org/"))
self.assertEqualOntology('''Prefix( xml: = <http://www.w3.org/XML/1998/namespace> )
Prefix( rdf: = <http://www.w3.org/1999/02/22-rdf-syntax-ns#> )
Prefix( rdfs: = <http://www.w3.org/2000/01/rdf-schema#> )
Prefix( xsd: = <http://www.w3.org/2001/XMLSchema#> )
Prefix( owl: = <http://www.w3.org/2002/07/owl#> )
Prefix( schema: = <https://schema.org/> )''', str(pds.to_functional(self.w.reset())))
pds = PrefixDeclarations()
pds.append(Prefix("sdo", "http://schema.org/"))
self.assertEqualOntology('''Prefix( xml: = <http://www.w3.org/XML/1998/namespace> )
Prefix( rdf: = <http://www.w3.org/1999/02/22-rdf-syntax-ns#> )
Prefix( rdfs: = <http://www.w3.org/2000/01/rdf-schema#> )
Prefix( xsd: = <http://www.w3.org/2001/XMLSchema#> )
Prefix( owl: = <http://www.w3.org/2002/07/owl#> )
Prefix( sdo: = <http://schema.org/> )''', str(pds.to_functional(self.w.reset())))



@unittest.skipIf(RDFLIB_PREFIXES_ARE_BROKEN, PREFIXES_BROKEN_MESSAGE)
def test_default_prefix(self):
""" Test that None is the correct default prefix """
Expand Down

0 comments on commit 3100872

Please sign in to comment.