@@ -242,6 +242,102 @@ def test_combine_with_uncrawled_resources(self):
242
242
assert combined != expected
243
243
assert combined .crawl () == expected
244
244
245
+ def test_combine_with_single_retrieve (self ):
246
+ one = Resource .opaque (contents = {})
247
+ two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
248
+ three = ID_AND_CHILDREN .create_resource ({"baz" : "quux" })
249
+
250
+ def retrieve (uri ):
251
+ pass
252
+
253
+ first = Registry ().with_resource ("http://example.com/1" , one )
254
+ second = Registry (
255
+ retrieve = retrieve ,
256
+ ).with_resource ("http://example.com/2" , two )
257
+ third = Registry ().with_resource ("http://example.com/3" , three )
258
+
259
+ assert first .combine (second , third ) == Registry (
260
+ retrieve = retrieve ,
261
+ ).with_resources (
262
+ [
263
+ ("http://example.com/1" , one ),
264
+ ("http://example.com/2" , two ),
265
+ ("http://example.com/3" , three ),
266
+ ],
267
+ )
268
+ assert second .combine (first , third ) == Registry (
269
+ retrieve = retrieve ,
270
+ ).with_resources (
271
+ [
272
+ ("http://example.com/1" , one ),
273
+ ("http://example.com/2" , two ),
274
+ ("http://example.com/3" , three ),
275
+ ],
276
+ )
277
+
278
+ def test_combine_with_common_retrieve (self ):
279
+ one = Resource .opaque (contents = {})
280
+ two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
281
+ three = ID_AND_CHILDREN .create_resource ({"baz" : "quux" })
282
+
283
+ def retrieve (uri ):
284
+ pass
285
+
286
+ first = Registry (retrieve = retrieve ).with_resource (
287
+ "http://example.com/1" ,
288
+ one ,
289
+ )
290
+ second = Registry (
291
+ retrieve = retrieve ,
292
+ ).with_resource ("http://example.com/2" , two )
293
+ third = Registry (retrieve = retrieve ).with_resource (
294
+ "http://example.com/3" ,
295
+ three ,
296
+ )
297
+
298
+ assert first .combine (second , third ) == Registry (
299
+ retrieve = retrieve ,
300
+ ).with_resources (
301
+ [
302
+ ("http://example.com/1" , one ),
303
+ ("http://example.com/2" , two ),
304
+ ("http://example.com/3" , three ),
305
+ ],
306
+ )
307
+ assert second .combine (first , third ) == Registry (
308
+ retrieve = retrieve ,
309
+ ).with_resources (
310
+ [
311
+ ("http://example.com/1" , one ),
312
+ ("http://example.com/2" , two ),
313
+ ("http://example.com/3" , three ),
314
+ ],
315
+ )
316
+
317
+ def test_combine_conflicting_retrieve (self ):
318
+ one = Resource .opaque (contents = {})
319
+ two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
320
+ three = ID_AND_CHILDREN .create_resource ({"baz" : "quux" })
321
+
322
+ def foo_retrieve (uri ):
323
+ pass
324
+
325
+ def bar_retrieve (uri ):
326
+ pass
327
+
328
+ first = Registry (retrieve = foo_retrieve ).with_resource (
329
+ "http://example.com/1" ,
330
+ one ,
331
+ )
332
+ second = Registry ().with_resource ("http://example.com/2" , two )
333
+ third = Registry (retrieve = bar_retrieve ).with_resource (
334
+ "http://example.com/3" ,
335
+ three ,
336
+ )
337
+
338
+ with pytest .raises (Exception , match = "conflict.*retriev" ): # noqa: B017
339
+ first .combine (second , third )
340
+
245
341
def test_repr (self ):
246
342
one = Resource .opaque (contents = {})
247
343
two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
0 commit comments