
    gޓ                     .   d dl mZ d dlZd dlmZmZmZmZmZ d dl	m
Z
  edd d d d	 
      Zd Z G d d      Z G d d      Z G d d      Z G d d      Z G d d      Zej$                  j'                  deeeeej(                  g      d        Zy)    )HashTrieMapN)AnchorRegistryResourceSpecification
exceptions)DRAFT202012zid-and-childrenc                 $    | j                  d      S )NIDgetcontentss    P/var/www/openai/venv/lib/python3.12/site-packages/referencing/tests/test_core.py<lambda>r   	   s    8<<-    c                 &    | j                  dg       S )Nchildrenr   r   s    r   r   r   
   s    X\\*b%Ar   c           
          |j                  di       j                         D cg c]"  \  }}t        || j                  |            $ c}}S c c}}w )Nanchorsr   nameresource)r   itemsr   create_resource)specificationr   r   eachs       r   r   r      sY    
 #,,y"5;;=0
 >JD$	 	"22D2A	
 >0 0s   'Ac                 t    t        |       dz  s)t        d | d d d   D              r|j                  |      S |S )N   c              3   &   K   | ]	  }|d k(    yw)r   N ).0r   s     r   	<genexpr>z<lambda>.<locals>.<genexpr>   s     =}t
"}s   )lenallin_subresourcesegmentsresolversubresources      r   r   r      sC    8}q =x!}== 	, 	 	r   r   id_ofsubresources_of
anchors_inmaybe_in_subresourcec                     t        d      )zQ
    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_upr4      s     K
LLr   c                   &   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1y0)1TestRegistryc                     t        j                  ddi      }d}t               j                  ||      }||   |u sJ y)zQ
        Adding a resource to the registry then allows re-retrieving it.
        foobarr   urn:exampler3   r   N)r   opaquer   with_resourceselfr   r3   registrys       r   test_with_resourcezTestRegistry.test_with_resource#   sD    
 ??UEN;:++h+G}(((r   c                     t        j                  i       }t        ddit              }t               j	                  d|fd|fg      }|t               j                  d|      j                  d|      k(  sJ y)	zT
        Adding multiple resources to the registry is like adding each one.
        r   r8   r9   r   r   http://example.com/1http://example.com/foo/barr;   N)r   r<   ID_AND_CHILDRENr   with_resourcesr=   r?   onetwor@   s       r   test_with_resourcesz TestRegistry.test_with_resources-   s    
 oor*oN:,,'--s3
 8:33& 4 
 -,  

 	
 
r   c                     d}t         j                  |dd      }|t               z  }|t               j                  ||      k(  sJ y )Nzurn:example:resource   r   r8   )rF   r   r   r=   r?   r3   r   r@   s       r   test_matmul_resourcez!TestRegistry.test_matmul_resourceB   sE    $"22#b3IJhj(8:33CBBBBr   c                     d}t         j                  |dd      }d}t         j                  |dd      }||gt               z  }|t               j                  ||f||fg      k(  sJ y )Nzurn:example:onerM   rN   zurn:example:two)rF   r   r   rG   )r?   one_urirI   two_urirJ   r@   s         r   test_matmul_many_resourcesz'TestRegistry.test_matmul_many_resourcesH   sw    #--WR.HI#--WR.HI:
*8:44s^gs^,
 
 	
 
r   c                    t        j                  ddi      }t        j                  t        j
                        5 }|t               z   d d d        j                  t	        j
                  |      k(  sJ y # 1 sw Y   /xY w)Nr8   r9   r   )r   )r   r<   pytestraisesr   NoInternalIDr   value)r?   r   es      r   test_matmul_resource_without_idz,TestRegistry.test_matmul_resource_without_idT   s]    ??UEN;]]:223qxz! 4ww*118DDDD 43s   A88Bc                 ~    d}ddi}t               j                  ||fg      }t        |t              }||   |k(  sJ y )Nr:   $schema,https://json-schema.org/draft/2020-12/schemarC   )r   with_contentsr   r	   )r?   r3   schemar@   expecteds        r   #test_with_contents_from_json_schemaz0TestRegistry.test_with_contents_from_json_schemaZ   sH    KL:++c6]O<V;G}(((r   c                     d}t               j                  |ddifgt        j                        }||   t	        j
                  ddi      k(  sJ y )Nr:   r8   r9   default_specification)r   r_   r   OPAQUEr   r<   )r?   r3   r@   s      r   ,test_with_contents_and_default_specificationz9TestRegistry.test_with_contents_and_default_specificationb   sW    :++E5>"#"/"6"6 , 
 } ????r   c                     d}t               j                  t        |      D cg c]  }t        |      ddif c}t        j
                        }t        |      |k(  sJ y c c}w )N   r8   r9   rd   )r   r_   rangestrr   rf   r$   )r?   totalir@   s       r   test_lenzTestRegistry.test_lenj   sc    :++/4U|<|!c!fuen%|<"/"6"6 , 
 8}%%% =s   A!c                     t               rJ y N)r   r?   s    r   test_bool_emptyzTestRegistry.test_bool_emptyr   s    :~:r   c                     t               j                  t        d      D cg c]  }t        |      ddif c}t        j
                        }|sJ y c c}w )N   r8   r9   rd   )r   r_   rj   rk   r   rf   r?   rm   r@   s      r   test_bool_not_emptyz TestRegistry.test_bool_not_emptyu   sS    :++/4Qx8x!c!fuen%x8"/"6"6 , 
 x 9s   Ac                    t               j                  t        d      D cg c]  }t        |      ddif c}t        j
                        }t        |      t        d      D ch c]  }t        |       c}k(  sJ y c c}w c c}w )N   r8   r9   rd   )r   r_   rj   rk   r   rf   setru   s      r   	test_iterzTestRegistry.test_iter|   sz    :++/4Qx8x!c!fuen%x8"/"6"6 , 
 8}q :AQ :::: 9 !;s   A?%Bc                 ~    t        j                  ddi      }d}t        ||i      j                         }||   |u sJ y Nr8   r9   r:   )r   r<   r   crawlr>   s       r   'test_crawl_still_has_top_level_resourcez4TestRegistry.test_crawl_still_has_top_level_resource   sB    ??E5>2S(O,224}(((r   c                     d}t         j                  d|ddgd      }|t               z  }t        j                  t
              5  ||    d d d        t         j                  |dd      }|j                         |   |k(  sJ y # 1 sw Y   :xY w)N	urn:childurn:rootrM   rN   r   r   )rF   r   r   rV   rW   LookupErrorr}   )r?   child_idrootr@   ra   s        r   test_crawl_finds_a_subresourcez+TestRegistry.test_crawl_finds_a_subresource   s    ..8B,G+HI
 (*$]];'X ( #22(23NO~~)X555	 ('s   BBc                    t         j                  dddid      }|t               z  }|j                         j	                  |j                         d      j                  t        dt         j                  d            k(  sJ y )Nurn:barr8   rM   r   r   r   )rF   r   r   r}   anchoridrY   r   r?   r   r@   s      r    test_crawl_finds_anchors_with_idz-TestRegistry.test_crawl_finds_anchors_with_id   sw    "22%5
 hj(~~&&x{{}e<BBf$44R8G
 
 	
 
r   c                    t         j                  dddii      }t               j                  d|      }|j	                         j                  dd      j                  t        dt         j                  d            k(  sJ y )Nr   r8   rM   r   r   )rF   r   r   r=   r}   r   rY   r   r   s      r   test_crawl_finds_anchors_no_idz+TestRegistry.test_crawl_finds_anchors_no_id   st    "22Ir{3KL:++JA~~&&z59??6$44R8D
 
 	
 
r   c                     t        j                  ddi      }d}t               j                  ||      }|j	                  |      ddik(  sJ y r|   )r   r<   r   r=   r   r>   s       r   test_contentszTestRegistry.test_contents   sJ    ??E5>2:++C:  %%777r   c                     d}t         j                  d|dz   i      }|t               z  }||   ||dz      cxk(  r|k(  sJ  J y Nhttp://example.com/r   #)rF   r   r   rO   s       r   #test_getitem_strips_empty_fragmentsz0TestRegistry.test_getitem_strips_empty_fragments   sR    #"22D#)3DEhj(}s 3?x?????r   c                     d}t         j                  d|dz   i      }|t               z  }|j                  |      |j                  |dz         cxk(  rd|dz   ik(  sJ  J y r   )rF   r   r   r   rO   s       r   $test_contents_strips_empty_fragmentsz1TestRegistry.test_contents_strips_empty_fragments   sv    #"22D#)3DEhj(c"  s+!cCi !	
!	
!r   c                     t               }t        j                  t        j                        5 }|j                  d       d d d        j                  t        j                  d      k(  sJ y # 1 sw Y   /xY w)Nr:   ref)r   rV   rW   r   NoSuchResourcer   rY   r?   r@   rZ   s      r   "test_contents_nonexistent_resourcez/TestRegistry.test_contents_nonexistent_resource   sV    :]]:445m, 6ww*33FFFF 65s   A..A7c                 *   t         j                  dddii      }t               j                  d|      }|j	                  dd      }|j
                  t        dt         j                  d            k(  sJ |j                  |j                         k(  sJ y )Nr   r8   r9   r:   r   )	rF   r   r   r=   r   rY   r   r@   r}   )r?   r   r@   	retrieveds       r   test_crawled_anchorz TestRegistry.test_crawled_anchor   s    "22Iu~3NO:++M8DOOM59	&$44U;#
 
 	
 
 !!X^^%5555r   c                     t               }t        j                  t        j                        5 }|j                  dd       d d d        j                  t        j                  d      k(  sJ y # 1 sw Y   /xY w)Nr:   r8   r   )r   rV   rW   r   r   r   rY   r   s      r   #test_anchor_in_nonexistent_resourcez0TestRegistry.test_anchor_in_nonexistent_resource   sV    :]]:445OOM51 6ww*33FFFF 65s   A//A8c                     t        j                  i       }t        j                  ddi      }t	        ||d      }|t	               j                  d|fd|fg      j                         k(  sJ y )Nr   r8   r9   )rD   rE   rD   rE   )r   r<   rF   r   r   rG   r}   rH   s       r   	test_initzTestRegistry.test_init   sz    oor*--uen=(+.1
 z^+S1137 UW
	
r   c                    t        j                  i       }t        j                  ddi      }t	        d|i      j                  d|      }|j                         t	               j                  d|fd|fg      j                         k(  sJ y)z
        Passing a `dict` to `Registry` gets converted to a `HashTrieMap`.

        So continuing to use the registry works.
        r   r8   r9   rD   rE   N)r   r<   rF   r   r   r=   r}   rG   rH   s       r   test_dict_conversionz!TestRegistry.test_dict_conversion   s     oor*--uen=#S)

-4c
: 	 NNz^+S1137 UW
	
r   c                     t               }t        j                  t        j                        5 }|d    d d d        j
                  t        j                  d      k(  sJ y # 1 sw Y   /xY w)Nzurn:bigboomr   )r   rV   rW   r   r   rY   r   s      r   test_no_such_resourcez"TestRegistry.test_no_such_resource  sP    :]]:445]# 6ww*33FFFF 65s   A""A+c                 B   t        j                  i       }t        j                  ddi      }t        j                  ddi      }t        j                  dddii      }t	        d|i      }t	               j                  d	|      }t	        ||d
      }t	               j                  d|      j                         }|j                  |||      t	        d|fd|fd|fgt        dt        dt        j                  d            i            j                  d	|      k(  sJ y )Nr   r8   r9   bazquuxr   rM   rD   rE   rD   http://example.com/bazhttp://example.com/foo/quuxr   )r   r8   r   )r   )
r   r<   rF   r   r   r=   r}   combiner   r   )	r?   rI   rJ   threefourfirstsecondthirdfourths	            r   test_combinezTestRegistry.test_combine  s.   oor*--uen=//@..	E2;/GH0#67))*FL(+*/
 J]- UW 	 }}VUF3x'-)51.5
  :F"!0!@!@!D=8
 -4c
:; 	; ;r   c                 H    t        ddi      }|j                  |      |u sJ y)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:foor9   N)r   r   r?   r@   s     r   test_combine_selfzTestRegistry.test_combine_self.  s,     Y./)X555r   c                    t        j                  i       }t        j                  ddi      }t        j                  ddi      }t	               j                  d|      }t	               j                  d|      }t	        ||d      }t	        d|fd|fd	|fg      }|j                  ||      }||k7  sJ |j                         |k(  sJ y )
Nr   r8   r9   r   r   rD   rE   r   r   )r   r<   rF   r   r   r=   r   r}   )	r?   rI   rJ   r   r   r   r   ra   combineds	            r   %test_combine_with_uncrawled_resourcesz2TestRegistry.test_combine_with_uncrawled_resources:  s    oor*--uen=//@
(()?E))*FL(+*/
 '--s3)51
 ==/8###~~8+++r   c                    t        j                  i       }t        j                  ddi      }t        j                  ddi      }d }t	               j                  d|      }t	        |      j                  d	|      }t	               j                  d
|      }|j                  ||      t	        |      j                  d|fd	|fd
|fg      k(  sJ |j                  ||      t	        |      j                  d|fd	|fd
|fg      k(  sJ y )Nr   r8   r9   r   r   c                      y rp   r!   r2   s    r   retrievez@TestRegistry.test_combine_with_single_retrieve.<locals>.retrieveW      r   rD   r   http://example.com/2http://example.com/3r   r<   rF   r   r   r=   r   rG   r?   rI   rJ   r   r   r   r   r   s           r   !test_combine_with_single_retrievez.TestRegistry.test_combine_with_single_retrieveR  s&   oor*--uen=//@	 
(()?E

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

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

.'-'-'/

 	
 
r   c                    t        j                  i       }t        j                  ddi      }t        j                  ddi      }d }t	        |      j                  d|      }t	        |      j                  d	|      }t	        |      j                  d
|      }|j                  ||      t	        |      j                  d|fd	|fd
|fg      k(  sJ |j                  ||      t	        |      j                  d|fd	|fd
|fg      k(  sJ y )Nr   r8   r9   r   r   c                      y rp   r!   r2   s    r   r   z@TestRegistry.test_combine_with_common_retrieve.<locals>.retrievex  r   r   r   rD   r   r   r   r   s           r   !test_combine_with_common_retrievez.TestRegistry.test_combine_with_common_retrieves  s6   oor*--uen=//@	 (+99"
 

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

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

.'-'-'/

 	
 
r   c                    t        j                  i       }t        j                  ddi      }t        j                  ddi      }d }d }t	        |      j                  d	|      }t	               j                  d
|      }t	        |      j                  d|      }t        j                  t        d      5  |j                  ||       d d d        y # 1 sw Y   y xY w)Nr   r8   r9   r   r   c                      y rp   r!   r2   s    r   foo_retrievezDTestRegistry.test_combine_conflicting_retrieve.<locals>.foo_retrieve  r   r   c                      y rp   r!   r2   s    r   bar_retrievezDTestRegistry.test_combine_conflicting_retrieve.<locals>.bar_retrieve  r   r   r   rD   r   r   zconflict.*retrievmatch)
r   r<   rF   r   r   r=   rV   rW   	Exceptionr   )	r?   rI   rJ   r   r   r   r   r   r   s	            r   !test_combine_conflicting_retrievez.TestRegistry.test_combine_conflicting_retrieve  s    oor*--uen=//@		 ,/=="
 ))*@#F,/=="

 ]]9,?@MM&%( A@@s   8CCc                     t        j                  i       }t        j                  ddi      }t	        ||d      }|j                  d      t	        d|i      k(  sJ y )Nr   r8   r9   )r   r   r   r   )r   r<   rF   r   r   removerH   s       r   test_removezTestRegistry.test_remove  sT    oor*--uen=<=y)Xy#6F-GGGGr   c                     t        j                  i       }t        j                  ddi      }t	               j                  d|fd|fg      }|j                  d      t	               j                  d|      k(  sJ y )Nr   r8   r9   r   r   )r   r<   rF   r   r   rG   r   r=   rH   s       r   test_remove_uncrawledz"TestRegistry.test_remove_uncrawled  sz    oor*--uen=:,,	3/0
 y)XZ-E-E.
 
 	
 
r   c                 4   t        j                  i       }t        j                  dddii      }t	               j                  d|fd|fg      j                         }|j                  d      t	               j                  d|      j                         k(  sJ y )Nr   r   r8   r9   r   r   )	r   r<   rF   r   r   rG   r}   r   r=   rH   s       r   test_remove_with_anchorsz%TestRegistry.test_remove_with_anchors  s    oor*--y5%..IJJ^S!Is#34 UW 	 OOI&z] UW	
r   c                     t        j                  t        j                        5 }t	               j                  d       d d d        j                  t        j                  d      k(  sJ y # 1 sw Y   /xY w)Nzurn:doesNotExistr   )rV   rW   r   r   r   r   rY   )r?   rZ   s     r   test_remove_nonexistent_uriz(TestRegistry.test_remove_nonexistent_uri  sS    ]]:445J01 6ww*338JKKKK 65s   A,,A5c                     t        j                  ddi      t        fd      }|j                  d      j                  k(  sJ y )Nr8   r9   c                     S rp   r!   r3   r8   s    r   r   z,TestRegistry.test_retrieve.<locals>.<lambda>  s    r   r   r:   )r   r<   r   get_or_retrieverY   )r?   r@   r8   s     @r   test_retrievezTestRegistry.test_retrieve  s>    oouen-_5''6<<CCCr   c                 (   t        j                  ddi      fd}t        |      }|j                  d      j                  k(  sJ t        j                  t        j                        5  |j                  d       d d d        y # 1 sw Y   y xY w)Nr8   r9   c                 (    | dk(  rS t        d      )Nurn:succeedzOh no!)r   r   s    r   r   z@TestRegistry.test_retrieve_arbitrary_exception.<locals>.retrieve  s    m#
H%%r   r   r   urn:uhoh)	r   r<   r   r   rY   rV   rW   r   Unretrievabler?   r   r@   r8   s      @r   !test_retrieve_arbitrary_exceptionz.TestRegistry.test_retrieve_arbitrary_exception  sq    oouen-	&
 X.''6<<CCC]]:334$$Z0 544   -BBc                 (   t        j                  ddi      fd}t        |      }|j                  d      j                  k(  sJ t        j                  t        j                        5  |j                  d       d d d        y # 1 sw Y   y xY w)Nr8   r9   c                 >    | dk(  rS t        j                  |       )Nr   r   )r   r   r   s    r   r   z=TestRegistry.test_retrieve_no_such_resource.<locals>.retrieve  s!    m#
++44r   r   r   r   )	r   r<   r   r   rY   rV   rW   r   r   r   s      @r   test_retrieve_no_such_resourcez+TestRegistry.test_retrieve_no_such_resource  sq    oouen-	5
 X.''6<<CCC]]:445$$Z0 655r   c                     d }t        |      }t        j                  t        j                        5  |j                  d       d d d        y # 1 sw Y   y xY w)Nc                 ,    t        j                  i       S rp   )r   from_contentsr2   s    r   r   zKTestRegistry.test_retrieve_cannot_determine_specification.<locals>.retrieve  s    ))"--r   r   r   )r   rV   rW   r   CannotDetermineSpecificationr   )r?   r   r@   s      r   ,test_retrieve_cannot_determine_specificationz9TestRegistry.test_retrieve_cannot_determine_specification  s@    	. X.]]:BBC$$Z0 DCCs   AAc                     t        j                  ddi      }t        d|it              }|d   |k(  sJ |j	                  d      j
                  |k(  sJ y )Nr8   r9   r:   r   )r   r<   r   r4   r   rY   )r?   r8   r@   s      r   (test_retrieve_already_available_resourcez5TestRegistry.test_retrieve_already_available_resource  sW    oouen-]C07C&#---''6<<CCCr   c                     t         j                  ddd      }t         j                  d|j                  gi      }t        t              j                  d|      }|j                         d   |k(  sJ y )Nr   rM   rN   r   r   r   )rF   r   r   r   r4   r=   r}   )r?   childr   r@   s       r   -test_retrieve_first_checks_crawlable_resourcez:TestRegistry.test_retrieve_first_checks_crawlable_resource	  sd    //{20NO..
U^^<L/MNW-;;JM~~,555r   c                     t        j                  i       }t        d|i      }|j                  d      }|j	                  d      j
                  i k(  sJ y )Nr   http://example.com)base_urir   r   r<   r   r)   lookupr   )r?   rI   r@   r)   s       r   test_resolverzTestRegistry.test_resolver  sQ    oor*1378$$.B$Cs#,,222r   c                    t         j                  ddi      }t               j                  |      }|j	                  d      j
                  |j
                  k(  sJ |j	                  d      j
                  |j
                  k(  sJ y )Nr   r   r   )rF   r   r   resolver_with_rootr   r   r?   r   r)   s      r   "test_resolver_with_root_identifiedz/TestRegistry.test_resolver_with_root_identified  sm    ..6J/KL:00634==NNNs#,,===r   c                     t        j                  i       }t               j                  |      }|j	                  d      j
                  |j
                  k(  sJ y )Nr   r   )r   r<   r   r   r   r   r   s      r   $test_resolver_with_root_unidentifiedz1TestRegistry.test_resolver_with_root_unidentified  sC    +:006s#,,===r   c                     t        j                  i       }t        j                  ddi      }t	               j                  d|fd|fg      }t        |      dk(  sJ t        |j                               dk(  sJ y )Nr   r8   r9   rD   rE   z"<Registry (2 uncrawled resources)>z<Registry (2 resources)>)r   r<   rF   r   r   rG   reprr}   rH   s       r   	test_reprzTestRegistry.test_repr   s{    oor*--uen=:,,'--s3
 H~!EEEEHNN$%)CCCCr   c                     t        j                  i       }t        j                  ddi      }t	        d|i      j                         j                  d|      }t        |      dk(  sJ y )Nr   r8   r9   rD   rE   r;   z%<Registry (2 resources, 1 uncrawled)>)r   r<   rF   r   r   r}   r=   r  rH   s       r   test_repr_mixed_crawledz$TestRegistry.test_repr_mixed_crawled,  sf    oor*--uen='- UW];c]J 	 H~!HHHHr   c                     t               j                  dt        j                  i             }t	        |      dk(  sJ y )NrD   r   r;   z!<Registry (1 uncrawled resource)>)r   r=   r   r<   r  r   s     r   test_repr_one_resourcez#TestRegistry.test_repr_one_resource8  s=    :++&__b1 , 
 H~!DDDDr   c                 4    t        t                     dk(  sJ y )Nz<Registry (0 resources)>)r  r   rq   s    r   test_repr_emptyzTestRegistry.test_repr_empty?  s    HJ#====r   N)2__name__
__module____qualname__rA   rK   rP   rT   r[   rb   rg   rn   rr   rv   rz   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  r  r
  r  r!   r   r   r6   r6   "   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   r6   c                   f    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zy)TestResourcec                 b    ddi}t        j                  |      }|t        |t              k(  sJ y )Nr]   r^   rC   )r   r   r	   r?   r`   r   s      r   #test_from_contents_from_json_schemaz0TestResource.test_from_contents_from_json_schemaD  s2    KL))&18V;OOOOr   c                     t        j                  t        j                        5  t	        j
                  ddi       ddd       y# 1 sw Y   yxY w)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.
        r8   r9   N)rV   rW   r   r   r   r   rq   s    r   2test_from_contents_with_no_discernible_informationz?TestResource.test_from_contents_with_no_discernible_informationI  s5     ]]:BBC""E5>2 DCC   AAc                     t        j                  ddit        j                        }|t        j                  ddi      k(  sJ y Nr8   r9   rd   r   r   r   r   rf   r<   r?   r   s     r   >test_from_contents_with_no_discernible_information_and_defaultzKTestResource.test_from_contents_with_no_discernible_information_and_defaultS  ?    ))EN"/"6"6
 8??UENCCCCr   c                     ddi}t        j                  |t        j                        }|t        |t              k(  sJ y )Nr]   r^   rd   rC   )r   r   r   rf   r	   r  s      r   #test_from_contents_unneeded_defaultz0TestResource.test_from_contents_unneeded_defaultZ  sJ    KL))"/"6"6
 8%
 
 	
 
r   c                 f    t        j                  dt              }|t        dt              k(  sJ y )NTrd   rC   )r   r   rF   r  s     r   test_non_mapping_from_contentsz+TestResource.test_non_mapping_from_contentse  s9    ))"1
 8)
 
 	
 
r   c                     t        j                  ddit        j                        }|t        j                  ddi      k(  sJ y r  r  r  s     r    test_from_contents_with_fallbackz-TestResource.test_from_contents_with_fallbacko  r  r   c                 t    t        dd d d d       }t        ddi|	      }|j                         d
k(  sJ y )N c                      yNurn:fixedIDr!   r   s    r   r   zATestResource.test_id_delegates_to_specification.<locals>.<lambda>y      =r   c                     g S rp   r!   r   s    r   r   zATestResource.test_id_delegates_to_specification.<locals>.<lambda>z      Rr   c                     g S rp   r!   r   r   s     r   r   zATestResource.test_id_delegates_to_specification.<locals>.<lambda>{      rr   c                     |S rp   r!   r'   s      r   r   zATestResource.test_id_delegates_to_specification.<locals>.<lambda>}      r   r+   r8   r   rC   r(  )r   r   r   r?   r   r   s      r   "test_id_delegates_to_specificationz/TestResource.test_id_delegates_to_specificationv  sG    %0/9@
 U^'
 {{}---r   c                 f    d}t         j                  d|dz   i      }|j                         |k(  sJ y r   )rF   r   r   )r?   r3   r   s      r   test_id_strips_empty_fragmentz*TestResource.test_id_strips_empty_fragment  s4    #..cCi/@AwwyCr   c                     t         j                  di dgi      }t        |j                               i dfD cg c]  }t         j                  |       c}k(  sJ y c c}w )Nr   rM   )rF   r   listsubresources)r?   r   r   s      r   ,test_subresources_delegates_to_specificationz9TestResource.test_subresources_delegates_to_specification  sf    "22JR3IJH))+,?A2h1
>FdO++D1h1
 
 	
 
 1
s   Ac                     ddi}t         j                  d|gi      }t        |j                               t	        j                  |      gk(  sJ y )Nr]   r^   r   )rF   r   r6  r7  r	   r  s      r   -test_subresource_with_different_specificationz:TestResource.test_subresource_with_different_specification  sW    KL"22J3IJH))+,''/1
 
 	
 
r   c           	      0   t         j                  di dddi      }t        |j                               t	        dt         j                  i             t	        dt         j                  d            t	        dt         j                  d            gk(  sJ y )	Nr      r%  )r8   r9   r   r8   r   r9   r   )rF   r   r6  r   r   r  s     r   'test_anchors_delegates_to_specificationz4TestResource.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                     t        j                  ddi      }t               j                         }|j	                  d|      j
                  dk(  sJ y )Nr8   r   r   z/foor)   r   r<   r   r)   pointerr   r?   r   r)   s      r   test_pointer_to_mappingz$TestResource.test_pointer_to_mapping  sH    ??UEN;:&&(:CCuLLLr   c                     t        j                  dddgii      }t               j                         }|j	                  d|      j
                  dk(  sJ y )Nr8   r9   rt   r   z
/foo/bar/0r?  r@  rB  s      r   test_pointer_to_arrayz"TestResource.test_pointer_to_array  sO    ??UUQCL,AB:&&(x@IIQNNNr   c                     ddi}t        j                  |      }t               j                         }|j	                  d|      j
                  |k(  sJ y )Nr8   r   r   r%  r?  r@  )r?   r   r   r)   s       r   test_root_pointerzTestResource.test_root_pointer  sM    5>??H5:&&(X6??8KKKr   c                 r    ddi}t        j                  |      t        |t        j                        k(  sJ y )Nr8   r9   rC   )r   r<   r   rf   )r?   r   s     r   test_opaquezTestResource.test_opaque  s9    5>x(H'..-
 
 	
 
r   N)r  r  r  r  r  r  r  r!  r#  r2  r4  r8  r:  r=  rC  rE  rG  rI  r!   r   r   r  r  C  sS    P
3D	

D.  



M
O
L
r   r  c                   x    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestResolverc                     t        j                  ddi      }t        d|i      j                         }|j	                  d      }|j
                  |j
                  k(  sJ y )Nr8   r   r   rD   r   )r?   r   r)   resolveds       r   test_lookup_exact_uriz"TestResolver.test_lookup_exact_uri  sV    ??UEN;3X>?HHJ??#9:  H$5$5555r   c                     t         j                  ddddgd      }|t               z  }|j                         j	                  d      }|j
                  dddk(  sJ y )Nr   zhttp://example.com/arM   rN   r   rF   r   r   r)   r   r   r?   r   r@   rM  s       r   test_lookup_subresourcez$TestResolver.test_lookup_subresource  si    ..+1"=
 (*$$$&--.DE  +A"$MMMMr   c                     t         j                  dddid      }|t               z  }|j                         j	                  d      }|j
                  dk(  sJ y )Nr   r8   rM   r   zhttp://example.com/#foorP  rQ  s       r   test_lookup_anchor_with_idz'TestResolver.test_lookup_anchor_with_id  s]    ..+!2;
 (*$$$&--.GH  B&&&r   c                     t         j                  dddii      }t               j                  d|      j	                         }|j                  d      }|j                  dk(  sJ y )Nr   r8   rM   r:   zurn:example#foo)rF   r   r   r=   r)   r   r   )r?   r   r)   rM  s       r   test_lookup_anchor_without_idz*TestResolver.test_lookup_anchor_without_id  s[    ..	E2;/GH:++M4@IIK??#45  B&&&r   c                    t               j                         }d}t        j                  t        j
                        5 }|j                  |       d d d        j                  t	        j
                  |      k(  sJ y # 1 sw Y   /xY w)Nz!http://example.com/does/not/existr   )r   r)   rV   rW   r   Unresolvabler   rY   )r?   r)   r   rZ   s       r   test_lookup_unknown_referencez*TestResolver.test_lookup_unknown_reference  sb    :&&(1]]:223qOOC  4ww*11c:::: 43s   A>>Bc                 ~   t        j                  di i      }t        d|i      j                         }d}t	        j
                  t        j                        5 }|j                  |       d d d        j                  t        j                  d|      k(  sJ t        |j                        dk(  sJ y # 1 sw Y   JxY w)Nr8   rD   zhttp://example.com/1#/foo/barz/foo/barr   r   z,'/foo/bar' does not exist within {'foo': {}})r   r<   r   r)   rV   rW   r   rX  r   rY   PointerToNowhererk   r?   r   r)   r   rZ   s        r    test_lookup_non_existent_pointerz-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   B33B<c                 J   t        j                  g d      }t        d|i      j                         }d}t	        j
                  t        j                        5 }|j                  |       d d d        j                  t        j                  d|      k(  sJ y # 1 sw Y   0xY w)N)r<  r      rx   rD   zhttp://example.com/1#/10z/10r[  )r   r<   r   r)   rV   rW   r   rX  r   rY   r\  r]  s        r   /test_lookup_non_existent_pointer_to_array_indexz<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                     t               j                  t        j                  di i            }|j	                  d      j
                  i k(  sJ y )Nr%  #/)r   r   r   r<   r   r   )r?   r)   s     r   #test_lookup_pointer_to_empty_stringz0TestResolver.test_lookup_pointer_to_empty_string  s>    :00"b1JKt$--333r   c                 F   t        j                  di i      }t               j                  |      }t	        j
                  t        j                  d      5 }|j                  d       d d d        j                  t        j                  d|      k(  sJ y # 1 sw Y   0xY w)Nr8   z+^'/' does not exist within {'foo': {}}.*'#'r   rc  /r[  )r   r<   r   r   rV   rW   r   rX  r   rY   r\  )r?   r   r)   rZ   s       r   0test_lookup_non_existent_pointer_to_empty_stringz=TestResolver.test_lookup_non_existent_pointer_to_empty_string  s    ??E2;/:00:]]##?
 OOD!	

 ww*55
 
 	
 

 
s   BB c                    t         j                  di i      }t               j                  d|      j	                         }|j                  d      }|j                  |j                  k(  sJ d}t        j                  t        j                        5 }|j                  |       d d d        dt        j                        v sJ |j                  t        j                  d|d      k(  sJ y # 1 sw Y   JxY w)Nr   r:   zurn:example#noSuchAnchorz'noSuchAnchor' does not existnoSuchAnchor)r   r   r   )rF   r   r   r=   r)   r   r   rV   rW   r   rX  rk   rY   NoSuchAnchor)r?   r   r)   rM  r   rZ   s         r   test_lookup_non_existent_anchorz,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,,C5c                 n   t               j                  t        j                  dddid            }|j	                  d      }|j
                  dk(  sJ t        j                  t        j                        5 }|j	                  d       d d d        dt        j                        v sJ y # 1 sw Y   #xY w)Nr   r9   rM   rN   z	#/foo/barz#foo/barz '#/foo/bar')r   r   rF   r   r   r   rV   rW   r   InvalidAnchorrk   rY   )r?   r)   validrZ   s       r   *test_lookup_invalid_JSON_pointerish_anchorz7TestResolver.test_lookup_invalid_JSON_pointerish_anchor  s    :00++/!2;
 ,~~###]]:334OOJ' 5QWW--- 54s   7B++B4c                     t        j                  ddi      t        fd      j                         }|j	                  d      }|j
                  j
                  k(  sJ y )Nr8   r   r   c                     S rp   r!   r;   s    r   r   z=TestResolver.test_lookup_retrieved_resource.<locals>.<lambda>1  s    r   r   r   r   )r?   r)   rM  r   s      @r   test_lookup_retrieved_resourcez+TestResolver.test_lookup_retrieved_resource/  sR    ??UEN;%9:CCE??#89  H$5$5555r   c                 l   d}t        t              }t        j                  t        j
                        5  |j                  |       ddd       |j                         }t        j                  t        j                        5  |j                  |       ddd       y# 1 sw Y   WxY w# 1 sw Y   yxY w)zL
        Unretrievable exceptions are also wrapped in Unresolvable.
        r   r   N)
r   r4   rV   rW   r   r   r   r)   rX  r   )r?   r3   r@   r)   s       r   %test_lookup_failed_retrieved_resourcez2TestResolver.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'*B3c                 >   t        j                  ddi      }|gfd}t        |      j                         }|j	                  d      }|j
                  |j
                  k(  sJ |j                  j	                  d      }|j
                  |j
                  k(  sJ y)zk
        A (custom-)retrieved resource is added to the registry returned by
        looking it up.
        r8   r   r   c                 $    j                         S rp   popr3   onces    r   r   zKTestResolver.test_repeated_lookup_from_retrieved_resource.<locals>.retrieveL      88:r   r   r   Nr   r?   r   r   r)   rM  rz  s        @r   ,test_repeated_lookup_from_retrieved_resourcez9TestResolver.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                 >   t        j                  ddi      }|gfd}t        |      j                         }|j	                  d      }|j
                  |j
                  k(  sJ |j                  j	                  d      }|j
                  |j
                  k(  sJ y )Nr8   r   r   c                 $    j                         S rp   rw  ry  s    r   r   zRTestResolver.test_repeated_anchor_lookup_from_retrieved_resource.<locals>.retrieveZ  r{  r   r   r   r   r   r|  s        @r   3test_repeated_anchor_lookup_from_retrieved_resourcez@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                 >   t         j                  ddddigdgd      }|t               z  }|j                         }|j	                  d      }|j
                  |j
                  k(  sJ t        j                  t        j                        5  |j                  j	                  d       d d d        |j                  j                  t         j                  |j
                  d   d               }|j	                  d      }|j
                  ddik(  sJ y # 1 sw Y   lxY w)Nr   child/r   
grandchildr   r   r   )rF   r   r   r)   r   r   rV   rW   r   rX  r&   )r?   r   r@   r)   r   subr   s          r   test_in_subresourcez 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                    t         j                  ddddigdgd      }|t               z  }|j                         }|j	                  d      }|j
                  |j
                  k(  sJ t        j                  t        j                        5  |j                  j	                  d       d d d        |j                  j	                  d      }|j                  j	                  d      }|j
                  ddik(  sJ y # 1 sw Y   SxY w)Nr   r  r   r  r   #/children/0)
rF   r   r   r)   r   r   rV   rW   r   rX  )r?   r   r@   r)   r   r   r   s          r   test_in_pointer_subresourcez(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                    t         j                  ddddigdgd      }t         j                  dddigd      }||gt               z  }|j                         }|j	                  d      }|j                  j	                  d      }|j                  j	                  d      }|j                  j	                  d      }t        |j                  j                               d	|j                  j                  fd
|j                  j                  fd|j                  j                  fgk(  sJ t        |j                  j                               d
|j                  j                  fd|j                  j                  fgk(  sJ t        |j                  j                               d|j                  j                  fgk(  sJ t        |j                  j                               g k(  sJ y )Nr   r  r   r  r   zhttp://example.com/twoz
two-child/r  z#http://example.com/child/grandchildzhttp://example.com/child/)rF   r   r   r)   r   r6  dynamic_scope	_registry)	r?   rI   rJ   r@   r)   r   r   r   r   s	            r   test_dynamic_scopez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   N)r  r  r  rN  rR  rT  rV  rY  r^  ra  rd  rg  rk  ro  rr  rt  r}  r  r  r  r  r!   r   r   rK  rK    s^    6N	'';
N	
4

 ."6!6$6"7662%:r   rK  c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestSpecificationc                     t        dd d d d       }|j                  ddi	      }|t        ddi|
      k(  sJ |j                         dk(  sJ y )Nr%  c                      yr'  r!   r   s    r   r   z8TestSpecification.test_create_resource.<locals>.<lambda>  r)  r   c                     g S rp   r!   r   s    r   r   z8TestSpecification.test_create_resource.<locals>.<lambda>  r+  r   c                     g S rp   r!   r-  s     r   r   z8TestSpecification.test_create_resource.<locals>.<lambda>  r.  r   c                     |S rp   r!   r'   s      r   r   z8TestSpecification.test_create_resource.<locals>.<lambda>  r0  r   r+   r8   r   r   rC   r(  )r   r   r   r   r1  s      r   test_create_resourcez&TestSpecification.test_create_resource  sm    %0/9@
 !005%.0I8U^'
 
 	
 
 {{}---r   c                 L    ddi}t        j                  |      }|t        k(  sJ y Nr]   r^   )r   detectr	   r?   r`   r   s      r   test_detect_from_json_schemaz.TestSpecification.test_detect_from_json_schema  s+    KL%,,V4+++r   c                     t        j                  t        j                        5  t	        j
                  ddi       d d d        y # 1 sw Y   y xY wNr8   r9   rV   rW   r   r   r   r  rq   s    r   +test_detect_with_no_discernible_informationz=TestSpecification.test_detect_with_no_discernible_information  s3    ]]:BBC  %0 DCCr  c                     t        j                  t        j                        5  t	        j
                  ddi       d d d        y # 1 sw Y   y xY w)Nr]   %   r  rq   s    r   test_detect_with_non_URI_schemaz1TestSpecification.test_detect_with_non_URI_schema  s3    ]]:BBC  )R1 DCCr  c                 n    t         j                  j                  ddi      }|t         j                  u sJ y r  r   rf   r  r?   r   s     r   7test_detect_with_no_discernible_information_and_defaultzITestSpecification.test_detect_with_no_discernible_information_and_default  0    %,,33UENC 4 4444r   c                 `    ddi}t         j                  j                  |      }|t        k(  sJ y r  )r   rf   r  r	   r  s      r   test_detect_unneeded_defaultz.TestSpecification.test_detect_unneeded_default  s1    KL%,,33F;+++r   c                     t        j                  t        j                        5  t	        j
                  d       d d d        y # 1 sw Y   y xY wNTr  rq   s    r   test_non_mapping_detectz)TestSpecification.test_non_mapping_detect  s/    ]]:BBC  & DCCs   AAc                 B    t         j                  d      }|t         u sJ y r  )rF   r  r  s     r   $test_non_mapping_detect_with_defaultz6TestSpecification.test_non_mapping_detect_with_default  s     '..t4///r   c                 n    t         j                  j                  ddi      }|t         j                  u sJ y r  r  r  s     r   test_detect_with_fallbackz+TestSpecification.test_detect_with_fallback  r  r   c                 ,    t        t              dk(  sJ y )Nz&<Specification name='id-and-children'>)r  rF   rq   s    r   r  zTestSpecification.test_repr  s    !%MM	
Mr   N)r  r  r  r  r  r  r  r  r  r  r  r  r  r!   r   r   r  r    s4    .",
125,
'05
r   r  c                       e Zd Zddiddd e       gZej                  j                  de      d        Zej                  j                  de      d        Z	ej                  j                  de      d        Z
y	)
TestOpaqueSpecificationr8   r9   Tr  thingc                 F    t         j                  j                  |      J y)z/
        An arbitrary thing has no ID.
        N)r   rf   r,   r?   r  s     r   
test_no_idz"TestOpaqueSpecification.test_no_id   s!     ##))%0888r   c                 ^    t        t        j                  j                  |            g k(  sJ y)z9
        An arbitrary thing has no subresources.
        N)r6  r   rf   r-   r  s     r   test_no_subresourcesz,TestOpaqueSpecification.test_no_subresources  s(     M((88?@BFFFr   c                 ^    t        t        j                  j                  |            g k(  sJ y)z4
        An arbitrary thing has no anchors.
        N)r6  r   rf   r.   r  s     r   test_no_anchorsz'TestOpaqueSpecification.test_no_anchors  s(     M((33E:;rAAAr   N)r  r  r  objectTHINGSrV   markparametrizer  r  r  r!   r   r   r  r    s    endBvx8F[[Wf-9 .9 [[Wf-G .G [[Wf-B .Br   r  clsc                 z    t        j                  t        d      5   G d d|       }d d d        y # 1 sw Y   y xY w)Nz(?i)subclassingr   c                       e Zd Zy)"test_nonsubclassable.<locals>.BoomN)r  r  r  r!   r   r   Boomr     s    r   r  )rV   rW   r   )r  r  s     r   test_nonsubclassabler    s+    
 
y(9	:	3 	 
;	:	:s   1:)rpdsr   rV   referencingr   r   r   r   r   referencing.jsonschemar	   rF   r4   r6   r  rK  r  r  r  r  r\  r  r!   r   r   <module>r     s      M M .	
-A(M^> ^>Bt
 t
nF: F:R7
 7
tB B8 	Xx
0K0KL	r   