@@ -338,6 +338,48 @@ def bar_retrieve(uri):
338338 with pytest .raises (Exception , match = "conflict.*retriev" ): # noqa: B017
339339 first .combine (second , third )
340340
341+ def test_remove (self ):
342+ one = Resource .opaque (contents = {})
343+ two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
344+ registry = Registry ({"urn:foo" : one , "urn:bar" : two })
345+ assert registry .remove ("urn:foo" ) == Registry ({"urn:bar" : two })
346+
347+ def test_remove_uncrawled (self ):
348+ one = Resource .opaque (contents = {})
349+ two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
350+ registry = Registry ().with_resources (
351+ [("urn:foo" , one ), ("urn:bar" , two )],
352+ )
353+ assert registry .remove ("urn:foo" ) == Registry ().with_resource (
354+ "urn:bar" ,
355+ two ,
356+ )
357+
358+ def test_remove_with_anchors (self ):
359+ one = Resource .opaque (contents = {})
360+ two = ID_AND_CHILDREN .create_resource ({"anchors" : {"foo" : "bar" }})
361+ registry = (
362+ Registry ()
363+ .with_resources (
364+ [("urn:foo" , one ), ("urn:bar" , two )],
365+ )
366+ .crawl ()
367+ )
368+ assert (
369+ registry .remove ("urn:bar" )
370+ == Registry ()
371+ .with_resource (
372+ "urn:foo" ,
373+ one ,
374+ )
375+ .crawl ()
376+ )
377+
378+ def test_remove_nonexistent_uri (self ):
379+ with pytest .raises (exceptions .NoSuchResource ) as e :
380+ Registry ().remove ("urn:doesNotExist" )
381+ assert e .value == exceptions .NoSuchResource (ref = "urn:doesNotExist" )
382+
341383 def test_repr (self ):
342384 one = Resource .opaque (contents = {})
343385 two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
0 commit comments