
    gt                     x    d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	  e
d      Z ed      Zd Z G d	 d
e      Zy)zH
Tests for the parts of jsonschema related to the :kw:`format` keyword.
    )TestCase)FormatCheckerValidationError)FormatError)Draft4ValidatorzBoom!zBang!c                 $    | dk(  rt         t        )Nbang)BANGBOOMthings    Q/var/www/openai/venv/lib/python3.12/site-packages/jsonschema/tests/test_format.pyboomr      s    

J    c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestFormatCheckerc                 R    t        d      }| j                  |j                         y )N formats)r   assertFalsecheckersselfcheckers     r   test_it_can_validate_no_formatsz1TestFormatChecker.test_it_can_validate_no_formats   s     +))*r   c                 r    | j                  t              5  t        dg       d d d        y # 1 sw Y   y xY w)Nzo noesr   )assertRaisesKeyErrorr   )r   s    r   .test_it_raises_a_key_error_for_unknown_formatsz@TestFormatChecker.test_it_raises_a_key_error_for_unknown_formats   s&    x(8*- )((s   -6c                 ~   t        t        j                        }| j                  t        j                  j                  d       | j                  t              5   t        j                  d      t               d d d        | j                  t        j                  t        |t        df             y # 1 sw Y   ;xY wNr   r   )r   )
dictr   r   
addCleanuppopassertWarnsDeprecationWarning
cls_checksr   assertEqual)r   originals     r   !test_it_can_register_cls_checkersz3TestFormatChecker.test_it_can_register_cls_checkers   s    ../..22F;01,M$$V,T2 2""r
+	
 21s    B33B<c                     t               } |j                  d      t               | j                  |j                  t        t         j                  t        df             y r"   )r   checksr   r)   r   r#   r   s     r   test_it_can_register_checkersz/TestFormatChecker.test_it_can_register_checkers(   sG    /vt$''tRj9	
r   c                 d   t               } |j                  dt        t                    t               | j                  t              5 }|j                  dd       d d d        | j                  j                  j                  t               | j                  |j                  j                  t               | j                  t        |j                        d       | j                  t        t                    5  |j                  dd       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   raises   instanceformatz12 is not a 'boom'r	   )r   r-   typer   r   r   r   checkassertIs	exceptioncause	__cause__r)   strr
   )r   r   cms      r   !test_it_catches_registered_errorsz3TestFormatChecker.test_it_catches_registered_errors0   s    /1vd4j1$7{+rMM2fM5 , 	bll(($/bll,,d3R\\*,@A tDz*MM6&M9 +* ,+ +*s   
D=D&D#&D/c                    t               } |j                  dt              t               t	        ddi|      }| j                  t              5 }|j                  d       d d d        | j                  j                  j                  t               | j                  |j                  j                  t               y # 1 sw Y   ^xY w)Nr   r0   r5   )format_checkerr   )r   r-   
ValueErrorr   r   r   r   validater8   r9   r:   r   r;   )r   r   	validatorr=   s       r   7test_format_error_causes_become_validation_error_causeszITestFormatChecker.test_format_error_causes_become_validation_error_causes?   s    /1vj1$7#Xv$6wO	/2v& 0 	bll(($/bll,,d3	 0/s   B??Cc                     t               }| j                  t              5  |j                  dd       d d d        y # 1 sw Y   y xY w)Nznot-an-ipv4ipv4r3   )r   r   r   r7   r   s     r   'test_format_checkers_come_with_defaultsz9TestFormatChecker.test_format_checkers_come_with_defaultsJ   s5    
  /{+MM=M@ ,++s	   =Ac                     t        d      } |j                  d      d         |j                  d      d         |j                  d      d        | j                  t        |      d	       y )
Nr   r   fooc                      yNTr   r   s    r   <lambda>z-TestFormatChecker.test_repr.<locals>.<lambda>U       Dr   barc                      yrK   r   r   s    r   rL   z-TestFormatChecker.test_repr.<locals>.<lambda>V   rM   r   bazc                      yrK   r   r   s    r   rL   z-TestFormatChecker.test_repr.<locals>.<lambda>W   rM   r   z.<FormatChecker checkers=['bar', 'baz', 'foo']>)r   r-   r)   reprr   s     r   	test_reprzTestFormatChecker.test_reprS   s`    +u01u01u01M<	
r   N)__name__
__module____qualname__r   r    r+   r.   r>   rD   rG   rS   r   r   r   r   r      s+    +.

:	4A
r   r   N)__doc__unittestr   
jsonschemar   r   jsonschema.exceptionsr   jsonschema.validatorsr   rA   r   ZeroDivisionErrorr
   r   r   r   r   r   <module>r]      s?     5 - 1'!F
 F
r   