o
    Rh                     @   sZ   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 dZdS )    )	lru_cacheN)RegistryResource
exceptions)DRAFT202012)to_cached_resourcec                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestToCachedResourcec                    sp   ddi}t |g t  fdd}t|d}t|}|d}|j|ks)J |d}|j|ju s6J d S )N$schema,https://json-schema.org/draft/2020-12/schemac                          S Npopuristack b/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/referencing/tests/test_retrieval.pyretrieve      zITestToCachedResource.test_it_caches_retrieved_resources.<locals>.retriever   urn:example:schemajsondumpsr   r   r   from_contentsget_or_retrievevalueselfcontentsr   registryexpectedgotagainr   r   r   "test_it_caches_retrieved_resources   s   



z7TestToCachedResource.test_it_caches_retrieved_resourcesc                    s   ddi}t |d d d g tdd d fdd}t|d	}t|}|d
}|j|ks2J |d
}|j|ju s?J d S )Nr	   r
   c                 S   s   t | d d d S )Nr'   )r   loads)sr   r   r   <lambda>#   s    z9TestToCachedResource.test_custom_loader.<locals>.<lambda>)r(   c                    r   r   r   r   r   r   r   r   #   r   z9TestToCachedResource.test_custom_loader.<locals>.retriever   r   r   r   r   r   r   test_custom_loader   s   



z'TestToCachedResource.test_custom_loaderc                    sr   i }t |g ttjd fdd}t|d}t|}|d}|j|ks*J |d}|j|ju s7J d S )N)r   c                    r   r   r   r   r   r   r   r   6   r   z@TestToCachedResource.test_custom_from_contents.<locals>.retriever   r   )r   r   r   r   create_resourcer   r   r   r   r   r   r   test_custom_from_contents2   s   




z.TestToCachedResource.test_custom_from_contentsc                    sx  ddi}t |ddt |ddt |ddd dd	   D }ttdd
d fdd}t|d}|d}|j|d ks@J |dj|ju sKJ |dj|ju sVJ |d}|j|d ksdJ |dj|ju soJ |dj|ju szJ |d}|j|d ksJ |dj|ju sJ |dj|ju sJ tt	j
 |d W d    d S 1 sw   Y  d S )Nr	   r
      )foo      )urn:example:1urn:example:2urn:example:3c                 S   s   i | ]
\}}|t |qS r   )r   r   ).0r   r!   r   r   r   
<dictcomp>M   s    
z:TestToCachedResource.test_custom_cache.<locals>.<dictcomp>)maxsize)cachec                    s   t  | S r   )r   r   r   r   mappingr   r   r   R   s   z8TestToCachedResource.test_custom_cache.<locals>.retriever   r2   r3   r4   )dictitemsr   r   r   r   r   pytestraisesr   Unretrievable)r    schema	resourcesr   r"   r$   r   r9   r   test_custom_cacheE   s4   






"z&TestToCachedResource.test_custom_cacheN)__name__
__module____qualname__r&   r+   r-   rB   r   r   r   r   r      s
    r   )	functoolsr   r   r=   referencingr   r   r   referencing.jsonschemar   referencing.retrievalr   r   r   r   r   r   <module>   s    