
    sgޓ                     (   S SK Jr  S SKrS SKJrJrJrJrJr  S SK	J
r
  \" SS S S S	 S
9rS r " S S5      r " S S5      r " S S5      r " S S5      r " S S5      r\R$                  R'                  S\\\\\R(                  /5      S 5       rg)    )HashTrieMapN)AnchorRegistryResourceSpecification
exceptions)DRAFT202012zid-and-childrenc                 $    U R                  S5      $ )NIDgetcontentss    =/usr/lib/python3/dist-packages/referencing/tests/test_core.py<lambda>r   	   s    8<<-    c                 &    U R                  S/ 5      $ )Nchildrenr   r   s    r   r   r   
   s    X\\*b%Ar   c                     UR                  S0 5      R                  5        VVs/ s H  u  p#[        UU R                  US9S9PM     snn$ s  snnf )Nanchorsr   nameresource)r   itemsr   create_resource)specificationr   r   eachs       r   r   r      sW    
 #,,y"5;;=0
 >JD	 	"22D2A	
 >0 0s   #Ac                     [        U 5      S-  (       d.  [        S U S S S2    5       5      (       a  UR                  U5      $ U$ )N   c              3   *   #    U  H	  oS :H  v   M     g7f)r   N ).0r   s     r   	<genexpr><lambda>.<locals>.<genexpr>   s     =}t
"}s   )lenallin_subresourcesegmentsresolversubresources      r   r   r      sF    8}q =x!}=== 	, 	 	r   r   id_ofsubresources_of
anchors_inmaybe_in_subresourcec                     [        S5      e)zI
A retriever suitable for use in tests which expect it never to be used.
z2This retrieve function expects to never be called!)RuntimeErroruris    r   blow_upr5      s     K
LLr   c                   .   \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S  r"S! r#S" r$S# r%S$ r&S% r'S& r(S' r)S( r*S) r+S* r,S+ r-S, r.S- r/S. r0S/ r1S0 r2S1r3g2)3TestRegistry"   c                 t    [         R                  " SS0S9nSn[        5       R                  X!S9nX2   UL d   eg)zA
Adding a resource to the registry then allows re-retrieving it.
foobarr   urn:exampler4   r   N)r   opaquer   with_resourceselfr   r4   registrys       r   test_with_resourceTestRegistry.test_with_resource#   s@    
 ??UEN;:+++G}(((r   c                     [         R                  " 0 S9n[        SS0[        S9n[        5       R	                  SU4SU4/5      nU[        5       R                  SUS9R                  SUS9:X  d   eg)	zD
Adding multiple resources to the registry is like adding each one.
r   r:   r;   r   r   http://example.com/1http://example.com/foo/barr=   N)r   r>   ID_AND_CHILDRENr   with_resourcesr?   rA   onetworB   s       r   test_with_resources TestRegistry.test_with_resources-   s    
 oor*oN:,,'--s3
 8:33& 4 
 -,  

 	
 
r   c                     Sn[         R                  USS.5      nU[        5       -  nU[        5       R                  X5      :X  d   eg )Nzurn:example:resource   r   r:   )rI   r   r   r?   rA   r4   r   rB   s       r   test_matmul_resource!TestRegistry.test_matmul_resourceB   sC    $"22#b3IJhj(8:33CBBBBr   c                     Sn[         R                  USS.5      nSn[         R                  USS.5      nX$/[        5       -  nU[        5       R                  X4X44/5      :X  d   eg )Nzurn:example:onerQ   rR   zurn:example:two)rI   r   r   rJ   )rA   one_urirL   two_urirM   rB   s         r   test_matmul_many_resources'TestRegistry.test_matmul_many_resourcesH   sq    #--WR.HI#--WR.HI:
*8:44^g^,
 
 	
 
r   c                    [         R                  " SS0S9n[        R                  " [        R
                  5       nU[        5       -    S S S 5        WR                  [        R
                  " US9:X  d   eg ! , (       d  f       N3= f)Nr:   r;   r   )r   )r   r>   pytestraisesr   NoInternalIDr   value)rA   r   es      r   test_matmul_resource_without_id,TestRegistry.test_matmul_resource_without_idT   s]    ??UEN;]]:223qxz! 4ww*118DDDD 43s   A66
Bc                 v    SnSS0n[        5       R                  X4/5      n[        U[        S9nX1   U:X  d   eg )Nr<   $schema,https://json-schema.org/draft/2020-12/schemarF   )r   with_contentsr   r	   )rA   r4   schemarB   expecteds        r   #test_with_contents_from_json_schema0TestRegistry.test_with_contents_from_json_schemaZ   sD    KL:++c]O<V;G}(((r   c                     Sn[        5       R                  USS04/[        R                  S9nX!   [        R
                  " SS05      :X  d   eg )Nr<   r:   r;   default_specification)r   rf   r   OPAQUEr   r>   )rA   r4   rB   s      r   ,test_with_contents_and_default_specification9TestRegistry.test_with_contents_and_default_specificationb   sU    :++E5>"#"/"6"6 , 
 } ????r   c                     Sn[        5       R                  [        U5       Vs/ s H  n[        U5      SS04PM     sn[        R
                  S9n[        U5      U:X  d   eg s  snf )N   r:   r;   rl   )r   rf   rangestrr   rn   r%   )rA   totalirB   s       r   test_lenTestRegistry.test_lenj   sc    :++/4U|<|!c!fuen%|<"/"6"6 , 
 8}%%% =s   A"c                 &    [        5       (       a   eg N)r   rA   s    r   test_bool_emptyTestRegistry.test_bool_emptyr   s    ::~:r   c                     [        5       R                  [        S5       Vs/ s H  n[        U5      SS04PM     sn[        R
                  S9nU(       d   eg s  snf )N   r:   r;   rl   )r   rf   rs   rt   r   rn   rA   rv   rB   s      r   test_bool_not_empty TestRegistry.test_bool_not_emptyu   sS    :++/4Qx8x!c!fuen%x8"/"6"6 , 
 x 9s   Ac                    [        5       R                  [        S5       Vs/ s H  n[        U5      SS04PM     sn[        R
                  S9n[        U5      [        S5       Vs1 s H  n[        U5      iM     sn:X  d   eg s  snf s  snf )N   r:   r;   rl   )r   rf   rs   rt   r   rn   setr   s      r   	test_iterTestRegistry.test_iter|   sz    :++/4Qx8x!c!fuen%x8"/"6"6 , 
 8}q :AQ :::: 9 !;s   B%Bc                 ~    [         R                  " SS05      nSn[        X!05      R                  5       nX2   UL d   eg Nr:   r;   r<   )r   r>   r   crawlr@   s       r   'test_crawl_still_has_top_level_resource4TestRegistry.test_crawl_still_has_top_level_resource   s>    ??E5>2SO,224}(((r   c                 ,   Sn[         R                  SUSS./S.5      nU[        5       -  n[        R                  " [
        5         X1     S S S 5        [         R                  USS.5      nUR                  5       U   U:X  d   eg ! , (       d  f       N@= f)N	urn:childurn:rootrQ   rR   r   r   )rI   r   r   r\   r]   LookupErrorr   )rA   child_idrootrB   rh   s        r   test_crawl_finds_a_subresource+TestRegistry.test_crawl_finds_a_subresource   s    ..8B,G+HI
 (*$]];' ( #22(23NO~~)X555	 ('s   B
Bc                    [         R                  SSS0S.5      nU[        5       -  nUR                  5       R	                  UR                  5       S5      R                  [        S[         R                  S5      S9:X  d   eg )Nurn:barr:   rQ   r   r   r   )rI   r   r   r   anchoridr_   r   rA   r   rB   s      r    test_crawl_finds_anchors_with_id-TestRegistry.test_crawl_finds_anchors_with_id   sw    "22%5
 hj(~~&&x{{}e<BBf$44R8G
 
 	
 
r   c                     [         R                  SSS005      n[        5       R                  SU5      nUR	                  5       R                  SS5      R                  [        S[         R                  S5      S9:X  d   eg )Nr   r:   rQ   r   r   )rI   r   r   r?   r   r   r_   r   r   s      r   test_crawl_finds_anchors_no_id+TestRegistry.test_crawl_finds_anchors_no_id   st    "22Ir{3KL:++JA~~&&z59??6$44R8D
 
 	
 
r   c                     [         R                  " SS05      nSn[        5       R                  X!5      nUR	                  U5      SS0:X  d   eg r   )r   r>   r   r?   r   r@   s       r   test_contentsTestRegistry.test_contents   sH    ??E5>2:++C:  %%777r   c                     Sn[         R                  SUS-   05      nU[        5       -  nX1   X1S-      s=:X  a  U:X  d   e   eg Nhttp://example.com/r   #)rI   r   r   rS   s       r   #test_getitem_strips_empty_fragments0TestRegistry.test_getitem_strips_empty_fragments   sN    #"22D#)3DEhj(}s 3?x?????r   c                     Sn[         R                  SUS-   05      nU[        5       -  nUR                  U5      UR                  US-   5      s=:X  a  SUS-   0:X  d    e   eg r   )rI   r   r   r   rS   s       r   $test_contents_strips_empty_fragments1TestRegistry.test_contents_strips_empty_fragments   sv    #"22D#)3DEhj(c"  s+!cCi !	
!	
!r   c                     [        5       n[        R                  " [        R                  5       nUR                  S5        S S S 5        WR                  [        R                  " SS9:X  d   eg ! , (       d  f       N3= f)Nr<   ref)r   r\   r]   r   NoSuchResourcer   r_   rA   rB   r`   s      r   "test_contents_nonexistent_resource/TestRegistry.test_contents_nonexistent_resource   sV    :]]:445m, 6ww*33FFFF 65s   A..
A<c                 (   [         R                  SSS005      n[        5       R                  SU5      nUR	                  SS5      nUR
                  [        S[         R                  S5      S9:X  d   eUR                  UR                  5       :X  d   eg )Nr   r:   r;   r<   r   )	rI   r   r   r?   r   r_   r   rB   r   )rA   r   rB   	retrieveds       r   test_crawled_anchor TestRegistry.test_crawled_anchor   s    "22Iu~3NO:++M8DOOM59	&$44U;#
 
 	
 
 !!X^^%5555r   c                     [        5       n[        R                  " [        R                  5       nUR                  SS5        S S S 5        WR                  [        R                  " SS9:X  d   eg ! , (       d  f       N3= f)Nr<   r:   r   )r   r\   r]   r   r   r   r_   r   s      r   #test_anchor_in_nonexistent_resource0TestRegistry.test_anchor_in_nonexistent_resource   sV    :]]:445OOM51 6ww*33FFFF 65s   A//
A=c                     [         R                  " 0 S9n[        R                  SS05      n[	        UUS.5      nU[	        5       R                  SU4SU4/5      R                  5       :X  d   eg )Nr   r:   r;   )rG   rH   rG   rH   )r   r>   rI   r   r   rJ   r   rK   s       r   	test_initTestRegistry.test_init   sz    oor*--uen=(+.1
 z^+S1137 UW
	
r   c                    [         R                  " 0 S9n[        R                  SS05      n[	        SU05      R                  SU5      nUR                  5       [	        5       R                  SU4SU4/5      R                  5       :X  d   eg)zm
Passing a `dict` to `Registry` gets converted to a `HashTrieMap`.

So continuing to use the registry works.
r   r:   r;   rG   rH   N)r   r>   rI   r   r   r?   r   rJ   rK   s       r   test_dict_conversion!TestRegistry.test_dict_conversion   s     oor*--uen=#S)

-4c
: 	 NNz^+S1137 UW
	
r   c                     [        5       n[        R                  " [        R                  5       nUS     S S S 5        WR
                  [        R                  " SS9:X  d   eg ! , (       d  f       N3= f)Nzurn:bigboomr   )r   r\   r]   r   r   r_   r   s      r   test_no_such_resource"TestRegistry.test_no_such_resource  sP    :]]:445]# 6ww*33FFFF 65s   A""
A0c                 2   [         R                  " 0 S9n[        R                  SS05      n[        R                  SS05      n[        R                  SSS005      n[	        SU05      n[	        5       R                  S	U5      n[	        UUS
.5      n[	        5       R                  SU5      R                  5       nUR                  XgU5      [	        SU4SU4SU4/[        S[        S[        R                  S5      S905      S9R                  S	U5      :X  d   eg )Nr   r:   r;   bazquuxr   rQ   rG   rH   rG   http://example.com/bazhttp://example.com/foo/quuxr   )r   r:   r   )r   )
r   r>   rI   r   r   r?   r   combiner   r   )	rA   rL   rM   threefourfirstsecondthirdfourths	            r   test_combineTestRegistry.test_combine  s,   oor*--uen=//@..	E2;/GH0#67))*FL(+*/
 J]- UW 	 }}VF3x'-)51.5
  :F"!0!@!@!D=8
 -4c
:; 	; ;r   c                 J    [        SS05      nUR                  U5      UL d   eg)z
Combining a registry with itself short-circuits.

This is a performance optimization -- otherwise we do lots more work
(in jsonschema this seems to correspond to making the test suite take
 *3x* longer).
urn:foor;   N)r   r   rA   rB   s     r   test_combine_selfTestRegistry.test_combine_self.  s,     Y./)X555r   c                    [         R                  " 0 S9n[        R                  SS05      n[        R                  SS05      n[	        5       R                  SU5      n[	        5       R                  SU5      n[	        UUS.5      n[	        SU4SU4S	U4/5      nUR                  XV5      nX:w  d   eUR                  5       U:X  d   eg )
Nr   r:   r;   r   r   rG   rH   r   r   )r   r>   rI   r   r   r?   r   r   )	rA   rL   rM   r   r   r   r   rh   combineds	            r   %test_combine_with_uncrawled_resources2TestRegistry.test_combine_with_uncrawled_resources:  s    oor*--uen=//@
(()?E))*FL(+*/
 '--s3)51
 ==/###~~8+++r   c                     [         R                  " 0 S9n[        R                  SS05      n[        R                  SS05      nS n[	        5       R                  SU5      n[	        US9R                  S	U5      n[	        5       R                  S
U5      nUR                  Xg5      [	        US9R                  SU4S	U4S
U4/5      :X  d   eUR                  XW5      [	        US9R                  SU4S	U4S
U4/5      :X  d   eg )Nr   r:   r;   r   r   c                     g rz   r!   r3   s    r   retrieve@TestRegistry.test_combine_with_single_retrieve.<locals>.retrieveW      r   rG   r   http://example.com/2http://example.com/3r   r>   rI   r   r   r?   r   rJ   rA   rL   rM   r   r   r   r   r   s           r   !test_combine_with_single_retrieve.TestRegistry.test_combine_with_single_retrieveR  s"   oor*--uen=//@	 
(()?E

-.
4 	 
(()?G}}V+x0

.'-'-'/

 	
 
 ~~e+x0

.'-'-'/

 	
 
r   c                    [         R                  " 0 S9n[        R                  SS05      n[        R                  SS05      nS n[	        US9R                  SU5      n[	        US9R                  S	U5      n[	        US9R                  S
U5      nUR                  Xg5      [	        US9R                  SU4S	U4S
U4/5      :X  d   eUR                  XW5      [	        US9R                  SU4S	U4S
U4/5      :X  d   eg )Nr   r:   r;   r   r   c                     g rz   r!   r3   s    r   r   @TestRegistry.test_combine_with_common_retrieve.<locals>.retrievex  r   r   r   rG   r   r   r   r   s           r   !test_combine_with_common_retrieve.TestRegistry.test_combine_with_common_retrieves  s2   oor*--uen=//@	 (+99"
 

-.
4 	 (+99"

 }}V+x0

.'-'-'/

 	
 
 ~~e+x0

.'-'-'/

 	
 
r   c                    [         R                  " 0 S9n[        R                  SS05      n[        R                  SS05      nS nS n[	        US9R                  S	U5      n[	        5       R                  S
U5      n[	        US9R                  SU5      n[        R                  " [        SS9   UR                  Xx5        S S S 5        g ! , (       d  f       g = f)Nr   r:   r;   r   r   c                     g rz   r!   r3   s    r   foo_retrieveDTestRegistry.test_combine_conflicting_retrieve.<locals>.foo_retrieve  r   r   c                     g rz   r!   r3   s    r   bar_retrieveDTestRegistry.test_combine_conflicting_retrieve.<locals>.bar_retrieve  r   r   r   rG   r   r   zconflict.*retrievmatch)
r   r>   rI   r   r   r?   r\   r]   	Exceptionr   )	rA   rL   rM   r   r   r   r   r   r   s	            r   !test_combine_conflicting_retrieve.TestRegistry.test_combine_conflicting_retrieve  s    oor*--uen=//@		 ,/=="
 ))*@#F,/=="

 ]]9,?@MM&( A@@s   .C		
Cc                     [         R                  " 0 S9n[        R                  SS05      n[	        XS.5      nUR                  S5      [	        SU05      :X  d   eg )Nr   r:   r;   )r   r   r   r   )r   r>   rI   r   r   removerK   s       r   test_removeTestRegistry.test_remove  sR    oor*--uen=<=y)Xy#6F-GGGGr   c                     [         R                  " 0 S9n[        R                  SS05      n[	        5       R                  SU4SU4/5      nUR                  S5      [	        5       R                  SU5      :X  d   eg )Nr   r:   r;   r   r   )r   r>   rI   r   r   rJ   r   r?   rK   s       r   test_remove_uncrawled"TestRegistry.test_remove_uncrawled  sz    oor*--uen=:,,	3/0
 y)XZ-E-E.
 
 	
 
r   c                 2   [         R                  " 0 S9n[        R                  SSS005      n[	        5       R                  SU4SU4/5      R                  5       nUR                  S5      [	        5       R                  SU5      R                  5       :X  d   eg )Nr   r   r:   r;   r   r   )	r   r>   rI   r   r   rJ   r   r   r?   rK   s       r   test_remove_with_anchors%TestRegistry.test_remove_with_anchors  s    oor*--y5%..IJJ^S!Is#34 UW 	 OOI&z] UW	
r   c                     [         R                  " [        R                  5       n[	        5       R                  S5        S S S 5        WR                  [        R                  " SS9:X  d   eg ! , (       d  f       N3= f)Nzurn:doesNotExistr   )r\   r]   r   r   r   r   r_   )rA   r`   s     r   test_remove_nonexistent_uri(TestRegistry.test_remove_nonexistent_uri  sS    ]]:445J01 6ww*338JKKKK 65s   A,,
A:c                    ^ [         R                  " SS05      m[        U4S jS9nUR                  S5      R                  T:X  d   eg )Nr:   r;   c                    > T$ rz   r!   r4   r:   s    r   r   ,TestRegistry.test_retrieve.<locals>.<lambda>  s    r   r   r<   )r   r>   r   get_or_retriever_   )rA   rB   r:   s     @r   test_retrieveTestRegistry.test_retrieve  s>    oouen-_5''6<<CCCr   c                 4  ^ [         R                  " SS05      mU4S jn[        US9nUR                  S5      R                  T:X  d   e[
        R                  " [        R                  5         UR                  S5        S S S 5        g ! , (       d  f       g = f)Nr:   r;   c                 *   > U S:X  a  T$ [        S5      e)Nurn:succeedzOh no!)r   r  s    r   r   @TestRegistry.test_retrieve_arbitrary_exception.<locals>.retrieve  s    m#
H%%r   r   r  urn:uhoh)	r   r>   r   r
  r_   r\   r]   r   UnretrievablerA   r   rB   r:   s      @r   !test_retrieve_arbitrary_exception.TestRegistry.test_retrieve_arbitrary_exception  sq    oouen-	&
 X.''6<<CCC]]:334$$Z0 544   .B		
Bc                 4  ^ [         R                  " SS05      mU4S jn[        US9nUR                  S5      R                  T:X  d   e[
        R                  " [        R                  5         UR                  S5        S S S 5        g ! , (       d  f       g = f)Nr:   r;   c                 <   > U S:X  a  T$ [         R                  " U S9e)Nr  r   )r   r   r  s    r   r   =TestRegistry.test_retrieve_no_such_resource.<locals>.retrieve  s!    m#
++44r   r   r  r  )	r   r>   r   r
  r_   r\   r]   r   r   r  s      @r   test_retrieve_no_such_resource+TestRegistry.test_retrieve_no_such_resource  sq    oouen-	5
 X.''6<<CCC]]:445$$Z0 655r  c                     S n[        US9n[        R                  " [        R                  5         UR                  S5        S S S 5        g ! , (       d  f       g = f)Nc                 .    [         R                  " 0 5      $ rz   )r   from_contentsr3   s    r   r   KTestRegistry.test_retrieve_cannot_determine_specification.<locals>.retrieve  s    ))"--r   r   r  )r   r\   r]   r   CannotDetermineSpecificationr
  )rA   r   rB   s      r   ,test_retrieve_cannot_determine_specification9TestRegistry.test_retrieve_cannot_determine_specification  s@    	. X.]]:BBC$$Z0 DCCs   A
Ac                     [         R                  " SS05      n[        SU0[        S9nUS   U:X  d   eUR	                  S5      R
                  U:X  d   eg )Nr:   r;   r<   r   )r   r>   r   r5   r
  r_   )rA   r:   rB   s      r   (test_retrieve_already_available_resource5TestRegistry.test_retrieve_already_available_resource  sW    oouen-]C07C&#---''6<<CCCr   c                     [         R                  SSS.5      n[         R                  SUR                  /05      n[        [        S9R                  SU5      nUR                  5       S   U:X  d   eg )Nr   rQ   rR   r   r   r   )rI   r   r   r   r5   r?   r   )rA   childr   rB   s       r   -test_retrieve_first_checks_crawlable_resource:TestRegistry.test_retrieve_first_checks_crawlable_resource	  sd    //{20NO..
U^^<L/MNW-;;JM~~,555r   c                     [         R                  " 0 S9n[        SU05      nUR                  SS9nUR	                  S5      R
                  0 :X  d   eg )Nr   http://example.com)base_urir   r   r>   r   r*   lookupr   )rA   rL   rB   r*   s       r   test_resolverTestRegistry.test_resolver  sQ    oor*1378$$.B$Cs#,,222r   c                    [         R                  SS05      n[        5       R                  U5      nUR	                  S5      R
                  UR
                  :X  d   eUR	                  S5      R
                  UR
                  :X  d   eg )Nr   r+  r   )rI   r   r   resolver_with_rootr.  r   rA   r   r*   s      r   "test_resolver_with_root_identified/TestRegistry.test_resolver_with_root_identified  sm    ..6J/KL:00634==NNNs#,,===r   c                     [         R                  " 0 S9n[        5       R                  U5      nUR	                  S5      R
                  UR
                  :X  d   eg )Nr   r   )r   r>   r   r2  r.  r   r3  s      r   $test_resolver_with_root_unidentified1TestRegistry.test_resolver_with_root_unidentified  sC    +:006s#,,===r   c                     [         R                  " 0 S9n[        R                  SS05      n[	        5       R                  SU4SU4/5      n[        U5      S:X  d   e[        UR                  5       5      S:X  d   eg )Nr   r:   r;   rG   rH   z"<Registry (2 uncrawled resources)>z<Registry (2 resources)>)r   r>   rI   r   r   rJ   reprr   rK   s       r   	test_reprTestRegistry.test_repr   s{    oor*--uen=:,,'--s3
 H~!EEEEHNN$%)CCCCr   c                     [         R                  " 0 S9n[        R                  SS05      n[	        SU05      R                  5       R                  SUS9n[        U5      S:X  d   eg )Nr   r:   r;   rG   rH   r=   z%<Registry (2 resources, 1 uncrawled)>)r   r>   rI   r   r   r   r?   r:  rK   s       r   test_repr_mixed_crawled$TestRegistry.test_repr_mixed_crawled,  sf    oor*--uen='- UW];c]J 	 H~!HHHHr   c                 z    [        5       R                  S[        R                  " 0 S9S9n[	        U5      S:X  d   eg )NrG   r   r=   z!<Registry (1 uncrawled resource)>)r   r?   r   r>   r:  r   s     r   test_repr_one_resource#TestRegistry.test_repr_one_resource8  s=    :++&__b1 , 
 H~!DDDDr   c                 6    [        [        5       5      S:X  d   eg )Nz<Registry (0 resources)>)r:  r   r{   s    r   test_repr_emptyTestRegistry.test_repr_empty?  s    HJ#====r   r!   N)4__name__
__module____qualname____firstlineno__rC   rN   rT   rY   ra   ri   ro   rw   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r!  r$  r(  r/  r4  r7  r;  r>  rA  rD  __static_attributes__r!   r   r   r7   r7   "   s    )
*C

E)@&;)
6	

8@
G6G
*
0G$;L
6,0
B%
N)0H	

(L
D
111D63>>

D
IE>r   r7   c                   n    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rSrg)TestResourceiC  c                 `    SS0n[         R                  " U5      nU[        U[        S9:X  d   eg )Nrd   re   rF   )r   r  r	   rA   rg   r   s      r   #test_from_contents_from_json_schema0TestResource.test_from_contents_from_json_schemaD  s2    KL))&18V;OOOOr   c                     [         R                  " [        R                  5         [        R
                  " SS05        SSS5        g! , (       d  f       g= f)z
Creating a resource with no discernible way to see what
specification it belongs to (e.g. no ``$schema`` keyword for JSON
Schema) raises an error.
r:   r;   N)r\   r]   r   r   r   r  r{   s    r   2test_from_contents_with_no_discernible_information?TestResource.test_from_contents_with_no_discernible_informationI  s5     ]]:BBC""E5>2 DCC   A
Ac                     [         R                  " SS0[        R                  S9nU[         R                  " SS0S9:X  d   eg Nr:   r;   rl   r   r   r  r   rn   r>   rA   r   s     r   >test_from_contents_with_no_discernible_information_and_defaultKTestResource.test_from_contents_with_no_discernible_information_and_defaultS  ?    ))EN"/"6"6
 8??UENCCCCr   c                 z    SS0n[         R                  " U[        R                  S9nU[        U[        S9:X  d   eg )Nrd   re   rl   rF   )r   r  r   rn   r	   rN  s      r   #test_from_contents_unneeded_default0TestResource.test_from_contents_unneeded_defaultZ  sJ    KL))"/"6"6
 8%
 
 	
 
r   c                 ^    [         R                  " S[        S9nU[        S[        S9:X  d   eg )NTrl   rF   )r   r  rI   rX  s     r   test_non_mapping_from_contents+TestResource.test_non_mapping_from_contentse  s9    ))"1
 8)
 
 	
 
r   c                     [         R                  " SS0[        R                  S9nU[         R                  " SS0S9:X  d   eg rV  rW  rX  s     r    test_from_contents_with_fallback-TestResource.test_from_contents_with_fallbacko  r[  r   c                 j    [        SS S S S S9n[        SS0US	9nUR                  5       S
:X  d   eg )N c                     gNurn:fixedIDr!   r   s    r   r   ATestResource.test_id_delegates_to_specification.<locals>.<lambda>y      =r   c                     / $ rz   r!   r   s    r   r   rj  z      Rr   c                     / $ rz   r!   r   r   s     r   r   rj  {      rr   c                     U$ rz   r!   r(   s      r   r   rj  }      r   r,   r:   r   rF   ri  )r   r   r   rA   r   r   s      r   "test_id_delegates_to_specification/TestResource.test_id_delegates_to_specificationv  sG    %0/9@
 U^'
 {{}---r   c                 h    Sn[         R                  SUS-   05      nUR                  5       U:X  d   eg r   )rI   r   r   )rA   r4   r   s      r   test_id_strips_empty_fragment*TestResource.test_id_strips_empty_fragment  s4    #..cCi/@AwwyCr   c                     [         R                  S0 S/05      n[        UR                  5       5      0 S4 Vs/ s H  n[         R                  U5      PM     sn:X  d   eg s  snf )Nr   rQ   )rI   r   listsubresources)rA   r   r   s      r   ,test_subresources_delegates_to_specification9TestResource.test_subresources_delegates_to_specification  sf    "22JR3IJH))+,?A2h1
>FdO++D1h1
 
 	
 
 1
s   A c                     SS0n[         R                  SU/05      n[        UR                  5       5      [        R                  " U5      /:X  d   eg )Nrd   re   r   )rI   r   rz  r{  r	   rN  s      r   -test_subresource_with_different_specification:TestResource.test_subresource_with_different_specification  sW    KL"22J3IJH))+,''/1
 
 	
 
r   c           	          [         R                  S0 SSS.05      n[        UR                  5       5      [	        S[         R                  0 5      S9[	        S[         R                  S5      S9[	        S[         R                  S5      S9/:X  d   eg )	Nr      rf  )r:   r;   r   r:   r   r;   r   )rI   r   rz  r   r   rX  s     r   'test_anchors_delegates_to_specification4TestResource.test_anchors_delegates_to_specification  s    "221R89
 H$$&'(G(G(KL(G(G(JK(G(G(KL,
 
 	
 
r   c                     [         R                  " SS0S9n[        5       R                  5       nUR	                  SUS9R
                  S:X  d   eg )Nr:   r   r   z/foor*   r   r>   r   r*   pointerr   rA   r   r*   s      r   test_pointer_to_mapping$TestResource.test_pointer_to_mapping  sH    ??UEN;:&&(:CCuLLLr   c                     [         R                  " SSS/00S9n[        5       R                  5       nUR	                  SUS9R
                  S:X  d   eg )Nr:   r;   r   r   z
/foo/bar/0r  r  r  s      r   test_pointer_to_array"TestResource.test_pointer_to_array  sO    ??UUQCL,AB:&&(x@IIQNNNr   c                     SS0n[         R                  " US9n[        5       R                  5       nUR	                  SUS9R
                  U:X  d   eg )Nr:   r   r   rf  r  r  )rA   r   r   r*   s       r   test_root_pointerTestResource.test_root_pointer  sM    5>??H5:&&(X6??8KKKr   c                 p    SS0n[         R                  " U5      [        U[        R                  S9:X  d   eg )Nr:   r;   rF   )r   r>   r   rn   )rA   r   s     r   test_opaqueTestResource.test_opaque  s9    5>x(H'..-
 
 	
 
r   r!   N)rF  rG  rH  rI  rO  rR  rY  r]  r`  rc  rt  rw  r|  r  r  r  r  r  r  rJ  r!   r   r   rL  rL  C  sS    P
3D	

D.  



M
O
L
r   rL  c                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rSrg)TestResolveri  c                     [         R                  " SS0S9n[        SU05      R                  5       nUR	                  S5      nUR
                  UR
                  :X  d   eg )Nr:   r   r   rG   r-  )rA   r   r*   resolveds       r   test_lookup_exact_uri"TestResolver.test_lookup_exact_uri  sV    ??UEN;3X>?HHJ??#9:  H$5$5555r   c                     [         R                  SSSS./S.5      nU[        5       -  nUR                  5       R	                  S5      nUR
                  SSS.:X  d   eg )Nr   zhttp://example.com/arQ   rR   r   rI   r   r   r*   r.  r   rA   r   rB   r  s       r   test_lookup_subresource$TestResolver.test_lookup_subresource  si    ..+1"=
 (*$$$&--.DE  +A"$MMMMr   c                     [         R                  SSS0S.5      nU[        5       -  nUR                  5       R	                  S5      nUR
                  S:X  d   eg )Nr   r:   rQ   r   zhttp://example.com/#foor  r  s       r   test_lookup_anchor_with_id'TestResolver.test_lookup_anchor_with_id  s]    ..+!2;
 (*$$$&--.GH  B&&&r   c                     [         R                  SSS005      n[        5       R                  SU5      R	                  5       nUR                  S5      nUR                  S:X  d   eg )Nr   r:   rQ   r<   zurn:example#foo)rI   r   r   r?   r*   r.  r   )rA   r   r*   r  s       r   test_lookup_anchor_without_id*TestResolver.test_lookup_anchor_without_id  s[    ..	E2;/GH:++M4@IIK??#45  B&&&r   c                    [        5       R                  5       nSn[        R                  " [        R
                  5       nUR                  U5        S S S 5        WR                  [        R
                  " US9:X  d   eg ! , (       d  f       N3= f)Nz!http://example.com/does/not/existr   )r   r*   r\   r]   r   Unresolvabler.  r_   )rA   r*   r   r`   s       r   test_lookup_unknown_reference*TestResolver.test_lookup_unknown_reference  sb    :&&(1]]:223qOOC  4ww*11c:::: 43s   A>>
Bc                    [         R                  " S0 05      n[        SU05      R                  5       nSn[        R
                  " [        R                  5       nUR                  U5        S S S 5        WR                  [        R                  " SUS9:X  d   e[        UR                  5      S:X  d   eg ! , (       d  f       NO= f)Nr:   rG   zhttp://example.com/1#/foo/barz/foo/barr   r   z,'/foo/bar' does not exist within {'foo': {}})r   r>   r   r*   r\   r]   r   r  r.  r_   PointerToNowherert   rA   r   r*   r   r`   s        r    test_lookup_non_existent_pointer-TestResolver.test_lookup_non_existent_pointer  s    ??E2;/3X>?HHJ-]]:223qOOC  4ww*55
 
 	
 
 177|MMMM 43s   B55
Cc                 V   [         R                  " / SQ5      n[        SU05      R                  5       nSn[        R
                  " [        R                  5       nUR                  U5        S S S 5        WR                  [        R                  " SUS9:X  d   eg ! , (       d  f       N4= f)N)r  r      r   rG   zhttp://example.com/1#/10z/10r  )r   r>   r   r*   r\   r]   r   r  r.  r_   r  r  s        r   /test_lookup_non_existent_pointer_to_array_index<TestResolver.test_lookup_non_existent_pointer_to_array_index  s    ??<03X>?HHJ(]]:223qOOC  4ww*55
 
 	
 
 43s   B
B(c                     [        5       R                  [        R                  " S0 05      5      nUR	                  S5      R
                  0 :X  d   eg )Nrf  #/)r   r2  r   r>   r.  r   )rA   r*   s     r   #test_lookup_pointer_to_empty_string0TestResolver.test_lookup_pointer_to_empty_string  s>    :00"b1JKt$--333r   c                 L   [         R                  " S0 05      n[        5       R                  U5      n[        R
                  " [        R                  SS9 nUR                  S5        S S S 5        WR                  [        R                  " SUS9:X  d   eg ! , (       d  f       N4= f)Nr:   z+^'/' does not exist within {'foo': {}}.*'#'r   r  /r  )r   r>   r   r2  r\   r]   r   r  r.  r_   r  )rA   r   r*   r`   s       r   0test_lookup_non_existent_pointer_to_empty_string=TestResolver.test_lookup_non_existent_pointer_to_empty_string  s    ??E2;/:00:]]##?
 OOD!	

 ww*55
 
 	
 

 
s   B
B#c                     [         R                  S0 05      n[        5       R                  SU5      R	                  5       nUR                  S5      nUR                  UR                  :X  d   eSn[        R                  " [        R                  5       nUR                  U5        S S S 5        S[        WR                  5      ;   d   eUR                  [        R                  " SUSS9:X  d   eg ! , (       d  f       NP= f)Nr   r<   zurn:example#noSuchAnchorz'noSuchAnchor' does not existnoSuchAnchor)r   r   r   )rI   r   r   r?   r*   r.  r   r\   r]   r   r  rt   r_   NoSuchAnchor)rA   r   r*   r  r   r`   s         r   test_lookup_non_existent_anchor,TestResolver.test_lookup_non_existent_anchor  s    ..	2?:++M4@IIK??=1  DMM111(]]:223qOOC  4.#agg,>>>ww*11!
 
 	
 
 43s   C//
C=c                    [        5       R                  [        R                  SSS0S.5      5      nUR	                  S5      nUR
                  S:X  d   e[        R                  " [        R                  5       nUR	                  S5        S S S 5        S[        WR                  5      ;   d   eg ! , (       d  f       N*= f)Nr   r;   rQ   rR   z	#/foo/barz#foo/barz '#/foo/bar')r   r2  rI   r   r.  r   r\   r]   r   InvalidAnchorrt   r_   )rA   r*   validr`   s       r   *test_lookup_invalid_JSON_pointerish_anchor7TestResolver.test_lookup_invalid_JSON_pointerish_anchor  s    :00++/!2;
 ,~~###]]:334OOJ' 5QWW--- 54s   9B//
B=c                    ^ [         R                  " SS0S9m[        U4S jS9R                  5       nUR	                  S5      nUR
                  TR
                  :X  d   eg )Nr:   r   r   c                    > T$ rz   r!   r=   s    r   r   =TestResolver.test_lookup_retrieved_resource.<locals>.<lambda>1  s    r   r   r   r-  )rA   r*   r  r   s      @r   test_lookup_retrieved_resource+TestResolver.test_lookup_retrieved_resource/  sR    ??UEN;%9:CCE??#89  H$5$5555r   c                 ~   Sn[        [        S9n[        R                  " [        R
                  5         UR                  U5        SSS5        UR                  5       n[        R                  " [        R                  5         UR                  U5        SSS5        g! , (       d  f       N]= f! , (       d  f       g= f)z<
Unretrievable exceptions are also wrapped in Unresolvable.
r   r   N)
r   r5   r\   r]   r   r  r
  r*   r  r.  )rA   r4   rB   r*   s       r   %test_lookup_failed_retrieved_resource2TestResolver.test_lookup_failed_retrieved_resource5  s    
 $W-]]:334$$S) 5 $$&]]:223OOC  43	 54 43s   BB.
B+.
B<c                 :  ^ [         R                  " SS0S9nU/mU4S jn[        US9R                  5       nUR	                  S5      nUR
                  UR
                  :X  d   eUR                  R	                  S5      nUR
                  UR
                  :X  d   eg)zS
A (custom-)retrieved resource is added to the registry returned by
looking it up.
r:   r   r   c                 $   > TR                  5       $ rz   popr4   onces    r   r   KTestResolver.test_repeated_lookup_from_retrieved_resource.<locals>.retrieveL      88:r   r   r   Nr-  rA   r   r   r*   r  r  s        @r   ,test_repeated_lookup_from_retrieved_resource9TestResolver.test_repeated_lookup_from_retrieved_resourceD  s    
 ??UEN;z	 X.779??#89  H$5$5555$$++,AB  H$5$5555r   c                 :  ^ [         R                  " SS0S9nU/mU4S jn[        US9R                  5       nUR	                  S5      nUR
                  UR
                  :X  d   eUR                  R	                  S5      nUR
                  UR
                  :X  d   eg )Nr:   r   r   c                 $   > TR                  5       $ rz   r  r  s    r   r   RTestResolver.test_repeated_anchor_lookup_from_retrieved_resource.<locals>.retrieveZ  r  r   r   r   r   r-  r  s        @r   3test_repeated_anchor_lookup_from_retrieved_resource@TestResolver.test_repeated_anchor_lookup_from_retrieved_resourceV  s    ??UEN;z	 X.779??#89  H$5$5555$$++C0  H$5$5555r   c                 N   [         R                  SSSS0/S./S.5      nU[        5       -  nUR                  5       nUR	                  S5      nUR
                  UR
                  :X  d   e[        R                  " [        R                  5         UR                  R	                  S5        S S S 5        UR                  R                  [         R                  UR
                  S   S   5      5      nUR	                  S5      nUR
                  SS0:X  d   eg ! , (       d  f       Nr= f)Nr   child/r   
grandchildr   r   r   )rI   r   r   r*   r.  r   r\   r]   r   r  r'   )rA   r   rB   r*   r   subr   s          r   test_in_subresource TestResolver.test_in_subresourceg  s    ..+ '&*L%9$:

 (*$$$& 56~~...]]:223NN!!,/ 4 nn++++ENN:,Fq,IJ
 L)4"6666 43s   D
D$c                    [         R                  SSSS0/S./S.5      nU[        5       -  nUR                  5       nUR	                  S5      nUR
                  UR
                  :X  d   e[        R                  " [        R                  5         UR                  R	                  S5        S S S 5        UR                  R	                  S5      nUR                  R	                  S5      nUR
                  SS0:X  d   eg ! , (       d  f       NY= f)Nr   r  r   r  r   #/children/0)
rI   r   r   r*   r.  r   r\   r]   r   r  )rA   r   rB   r*   r   r   r   s          r   test_in_pointer_subresource(TestResolver.test_in_pointer_subresource  s    ..+ '&*L%9$:

 (*$$$& 56~~...]]:223NN!!,/ 4 &&~6&&|4~~$!5555 43s   C==
Dc                    [         R                  SSSS0/S./S.5      n[         R                  SSS0/S.5      nX/[        5       -  nUR                  5       nUR	                  S5      nUR                  R	                  S5      nUR                  R	                  S5      nUR                  R	                  S5      n[        UR                  R                  5       5      S	UR                  R                  4S
UR                  R                  4SUR                  R                  4/:X  d   e[        UR                  R                  5       5      S
UR                  R                  4SUR                  R                  4/:X  d   e[        UR                  R                  5       5      SUR                  R                  4/:X  d   e[        UR                  R                  5       5      / :X  d   eg )Nr   r  r   r  r   zhttp://example.com/twoz
two-child/r  z#http://example.com/child/grandchildzhttp://example.com/child/)rI   r   r   r*   r.  rz  dynamic_scope	_registry)	rA   rL   rM   rB   r*   r   r   r   r   s	            r   test_dynamic_scopeTestResolver.test_dynamic_scope  s   --+ '&*L%9$:

 --."L12
 :
*$$& 56&&~6&&|4&&'?@FOO11342FOO4M4MN(&//*C*CD"FOO$=$=>9
 
 	
 

 ENN0023(%..*B*BC"ENN$<$<=8
 
 	
 
 FOO1134"FOO$=$=>9
 
 	
 
 ENN0023r999r   r!   N)rF  rG  rH  rI  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rJ  r!   r   r   r  r    s^    6N	'';
N	
4

 ."6!6$6"7662%:r   r  c                   P    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rSrg)TestSpecificationi  c                     [        SS S S S S9nUR                  SS0S	9nU[        SS0US
9:X  d   eUR                  5       S:X  d   eg )Nrf  c                     grh  r!   r   s    r   r   8TestSpecification.test_create_resource.<locals>.<lambda>  rk  r   c                     / $ rz   r!   r   s    r   r   r    rm  r   c                     / $ rz   r!   ro  s     r   r   r    rp  r   c                     U$ rz   r!   r(   s      r   r   r    rr  r   r,   r:   r   r   rF   ri  )r   r   r   r   rs  s      r   test_create_resource&TestSpecification.test_create_resource  sm    %0/9@
 !005%.0I8U^'
 
 	
 
 {{}---r   c                 P    SS0n[         R                  " U5      nU[        :X  d   eg Nrd   re   )r   detectr	   rA   rg   r   s      r   test_detect_from_json_schema.TestSpecification.test_detect_from_json_schema  s+    KL%,,V4+++r   c                     [         R                  " [        R                  5         [        R
                  " SS05        S S S 5        g ! , (       d  f       g = fNr:   r;   r\   r]   r   r   r   r  r{   s    r   +test_detect_with_no_discernible_information=TestSpecification.test_detect_with_no_discernible_information  s3    ]]:BBC  %0 DCCrT  c                     [         R                  " [        R                  5         [        R
                  " SS05        S S S 5        g ! , (       d  f       g = f)Nrd   %   r  r{   s    r   test_detect_with_non_URI_schema1TestSpecification.test_detect_with_non_URI_schema  s3    ]]:BBC  )R1 DCCrT  c                 p    [         R                  R                  SS05      nU[         R                  L d   eg r  r   rn   r  rA   r   s     r   7test_detect_with_no_discernible_information_and_defaultITestSpecification.test_detect_with_no_discernible_information_and_default  0    %,,33UENC 4 4444r   c                 b    SS0n[         R                  R                  U5      nU[        :X  d   eg r  )r   rn   r  r	   r  s      r   test_detect_unneeded_default.TestSpecification.test_detect_unneeded_default  s1    KL%,,33F;+++r   c                     [         R                  " [        R                  5         [        R
                  " S5        S S S 5        g ! , (       d  f       g = fNTr  r{   s    r   test_non_mapping_detect)TestSpecification.test_non_mapping_detect  s/    ]]:BBC  & DCCs   A
Ac                 D    [         R                  S5      nU[         L d   eg r  )rI   r  r  s     r   $test_non_mapping_detect_with_default6TestSpecification.test_non_mapping_detect_with_default  s     '..t4///r   c                 p    [         R                  R                  SS05      nU[         R                  L d   eg r  r  r  s     r   test_detect_with_fallback+TestSpecification.test_detect_with_fallback  r  r   c                 .    [        [        5      S:X  d   eg )Nz&<Specification name='id-and-children'>)r:  rI   r{   s    r   r;  TestSpecification.test_repr  s    !%MM	
Mr   r!   N)rF  rG  rH  rI  r  r  r   r  r	  r  r  r  r  r;  rJ  r!   r   r   r  r    s4    .",
125,
'05
r   r  c                       \ rS rSrSS0SSS\" 5       /r\R                  R                  S\5      S 5       r	\R                  R                  S\5      S 5       r
\R                  R                  S\5      S	 5       rS
rg)TestOpaqueSpecificationi  r:   r;   Tr  thingc                 H    [         R                  R                  U5      b   eg)z
An arbitrary thing has no ID.
N)r   rn   r-   rA   r  s     r   
test_no_id"TestOpaqueSpecification.test_no_id   s!     ##))%0888r   c                 `    [        [        R                  R                  U5      5      / :X  d   eg)z)
An arbitrary thing has no subresources.
N)rz  r   rn   r.   r  s     r   test_no_subresources,TestOpaqueSpecification.test_no_subresources  s(     M((88?@BFFFr   c                 `    [        [        R                  R                  U5      5      / :X  d   eg)z$
An arbitrary thing has no anchors.
N)rz  r   rn   r/   r  s     r   test_no_anchors'TestOpaqueSpecification.test_no_anchors  s(     M((33E:;rAAAr   r!   N)rF  rG  rH  rI  objectTHINGSr\   markparametrizer   r#  r&  rJ  r!   r   r   r  r    s    endBvx8F[[Wf-9 .9 [[Wf-G .G [[Wf-B .Br   r  clsc                     [         R                  " [        SS9    " S SU 5      nS S S 5        g ! , (       d  f       g = f)Nz(?i)subclassingr   c                       \ rS rSrSrg)"test_nonsubclassable.<locals>.Boomi   r!   N)rF  rG  rH  rI  rJ  r!   r   r   Boomr/     s    r   r0  )r\   r]   r   )r,  r0  s     r   test_nonsubclassabler1    s+    
 
y(9	:	3 	 
;	:	:s   /
=)rpdsr   r\   referencingr   r   r   r   r   referencing.jsonschemar	   rI   r5   r7   rL  r  r  r  r*  r+  r  r1  r!   r   r   <module>r5     s      M M .	
-A(M^> ^>Bt
 t
nF: F:R7
 7
tB B8 	Xx
0K0KL	r   