
    g                     `    d dl mZ d dlZd dlZd dlmZmZmZ d dlm	Z	 d dl
mZ  G d d      Zy)    )	lru_cacheN)RegistryResource
exceptions)DRAFT202012)to_cached_resourcec                   $    e Zd Zd Zd Zd Zd Zy)TestToCachedResourcec                 :   ddi}t        j                  |      gt               fd       }t        |      }t	        j
                  |      }|j                  d      }|j                  |k(  sJ |j                  d      }|j                  |j                  u sJ y )N$schema,https://json-schema.org/draft/2020-12/schemac                 $    j                         S Npopuristacks    U/var/www/openai/venv/lib/python3.12/site-packages/referencing/tests/test_retrieval.pyretrievezITestToCachedResource.test_it_caches_retrieved_resources.<locals>.retrieve       99;    r   urn:example:schemajsondumpsr   r   r   from_contentsget_or_retrievevalueselfcontentsr   registryexpectedgotagainr   s          @r   "test_it_caches_retrieved_resourcesz7TestToCachedResource.test_it_caches_retrieved_resources   s    MNH%&			 
	 X.))(3&&';<yyH$$$ (()=>{{cii'''r   c                 L   ddi}t        j                  |      d d d   gt        d       fd       }t        |      }t	        j
                  |      }|j                  d      }|j                  |k(  sJ |j                  d      }|j                  |j                  u sJ y )	Nr   r   c                 8    t        j                  | d d d         S )Nr*   )r   loads)ss    r   <lambda>z9TestToCachedResource.test_custom_loader.<locals>.<lambda>#   s    DJJq2w,?r   )r,   c                 $    j                         S r   r   r   s    r   r   z9TestToCachedResource.test_custom_loader.<locals>.retrieve#   r   r   r   r   r   r!   s          @r   test_custom_loaderz'TestToCachedResource.test_custom_loader   s    MNH%dd+,	"?	@	 
A	 X.))(3&&';<yyH$$$ (()=>{{cii'''r   c                 V   i }t        j                  |      gt        t        j                        fd       }t        |      }t        j                  |      }|j                  d      }|j                  |k(  sJ |j                  d      }|j                  |j                  u sJ y )N)r   c                 $    j                         S r   r   r   s    r   r   z@TestToCachedResource.test_custom_from_contents.<locals>.retrieve6   r   r   r   r   )r   r   r   r   create_resourcer   r   r    r!   s          @r   test_custom_from_contentsz.TestToCachedResource.test_custom_from_contents2   s    H%&	+*E*E	F	 
G	 X...x8&&';<yyH$$$ (()=>{{cii'''r   c                    ddi}t        |d      t        |d      t        |d      dj                         D ci c]  \  }}|t        j                  |       }}}t	        t        d      	      fd
       }t        |      }|j                  d      }|j                  |d   k(  sJ |j                  d      j                  |j                  u sJ |j                  d      j                  |j                  u sJ |j                  d      }|j                  |d   k(  sJ |j                  d      j                  |j                  u sJ |j                  d      j                  |j                  u sJ |j                  d      }|j                  |d   k(  sJ |j                  d      j                  |j                  u sJ |j                  d      j                  |j                  u sJ t        j                  t        j                        5  |j                  d       d d d        y c c}}w # 1 sw Y   y xY w)Nr   r      )foo      )urn:example:1urn:example:2urn:example:3)maxsize)cachec                 L    t        j                  j                  |             S r   )r   r   r   )r   mappings    r   r   z8TestToCachedResource.test_custom_cache.<locals>.retrieveR   s    ::gkk#.//r   r   r:   r;   r<   )dictitemsr   r   r   r   r   r   r    pytestraisesr   Unretrievable)	r"   schemar   r#   	resourcesr   r$   r&   r@   s	           @r   test_custom_cachez&TestToCachedResource.test_custom_cacheE   s   KL!&a0!&a0!&a0
 ")
!0X ''11!0 	 

 
)A"6	7	0 
8	0 X.&&7yyIo6666''8>>#))KKK''8>>#))KKK&&7yyIo6666''8>>#))KKK''8>>#))KKK &&7yyIo6666''8>>#))KKK''8>>#))KKK ]]:334$$_5 549
8 54s     H0H66H?N)__name__
__module____qualname__r(   r0   r4   rH    r   r   r
   r
      s    (&(&(&%6r   r
   )	functoolsr   r   rC   referencingr   r   r   referencing.jsonschemar   referencing.retrievalr   r
   rL   r   r   <module>rQ      s&       6 6 . 4_6 _6r   