88import pytest
99
1010from rdflib import DCTERMS
11- from rdflib .graph import Graph
11+ from rdflib .graph import BNode , Graph , Literal
1212from rdflib .namespace import (
1313 FOAF ,
1414 OWL ,
@@ -264,6 +264,40 @@ def test_contains_method(self):
264264 ref = URIRef ("http://www.w3.org/2002/07/owl#real" )
265265 assert ref in OWL , "OWL does not include owl:real"
266266
267+ def test_expand_curie (self ) -> None :
268+ g = Graph ()
269+
270+ assert g .namespace_manager .expand_curie ("rdf:type" ) == URIRef (
271+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
272+ )
273+
274+ assert g .namespace_manager .expand_curie ("rdf:type" ) == RDF .type
275+
276+ g .bind ("ex" , Namespace ("urn:example:" ))
277+
278+ assert g .namespace_manager .expand_curie ("ex:tarek" ) == URIRef (
279+ "urn:example:tarek"
280+ )
281+
282+ def test_expand_curie_exception_messages (self ) -> None :
283+ g = Graph ()
284+
285+ with pytest .raises (TypeError ) as e :
286+ assert g .namespace_manager .expand_curie (URIRef ("urn:example" )) == None
287+ assert str (e .value ) == "Argument must be a string, not URIRef."
288+
289+ with pytest .raises (TypeError ) as e :
290+ assert g .namespace_manager .expand_curie (Literal ("rdf:type" )) == None
291+ assert str (e .value ) == "Argument must be a string, not Literal."
292+
293+ with pytest .raises (TypeError ) as e :
294+ assert g .namespace_manager .expand_curie (BNode ()) == None
295+ assert str (e .value ) == "Argument must be a string, not BNode."
296+
297+ with pytest .raises (TypeError ) as e :
298+ assert g .namespace_manager .expand_curie (Graph ()) == None
299+ assert str (e .value ) == "Argument must be a string, not Graph."
300+
267301 @pytest .mark .parametrize (
268302 ["curie" , "expected_result" ],
269303 [
@@ -273,18 +307,20 @@ def test_contains_method(self):
273307 ("ex:a:b" , URIRef (f"urn:example:a:b" )),
274308 ("ex:a:b:c" , URIRef (f"urn:example:a:b:c" )),
275309 ("ex" , ValueError ),
276- ("em:tarek" , None ),
277- ("em:" , None ),
310+ ("em:tarek" , ValueError ),
311+ ("em:" , ValueError ),
278312 ("em" , ValueError ),
279313 (":" , ValueError ),
280314 (":type" , ValueError ),
281315 ("í" , ValueError ),
282- (" :" , None ),
316+ (" :" , ValueError ),
283317 ("" , ValueError ),
284318 ("\n " , ValueError ),
285319 (None , TypeError ),
286320 (3 , TypeError ),
287321 (URIRef ("urn:example:" ), TypeError ),
322+ (BNode (), TypeError ),
323+ (Literal ("rdf:type" ), TypeError ),
288324 ],
289325 )
290326 def test_expand_curie (
0 commit comments