
    `d                     p    d Z ddlmZ ddlmZmZ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FormatErrorValidationError)Draft4ValidatorzBoom!zBang!c                 $    | dk(  rt         t        )Nbang)BANGBOOMthings    >/usr/lib/python3/dist-packages/jsonschema/tests/test_format.pyboomr      s    

J    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)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        t        j
                  d      t               | j                  t        j                  t        |t        df             y Nr   r   )r   )dictr   r   
addCleanuppop
cls_checksr   assertEqual)r   originals     r   !test_it_can_register_cls_checkersz3TestFormatChecker.test_it_can_register_cls_checkers   sf    ../..22F;(  (.""r
+	
r   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                    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        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formatr	   )r   r+   typer   r   r   r   checkassertIs	exceptioncause	__cause__r
   )r   r   cms      r   !test_it_catches_registered_errorsz3TestFormatChecker.test_it_catches_registered_errors.   s    /1vd4j1$7{+ 	6rMM2fM5	6 	bll(($/bll,,d3 tDz* 	:MM6&M9	: 	:	6 	6	: 	:s   
C5D5C>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   r.   r3   )format_checkerr   )r   r+   
ValueErrorr   r   r   r   validater6   r7   r8   r   r9   )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&	' 	bll(($/bll,,d3		' 	'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ipv4r1   )r   r   r   r5   r   s     r   'test_format_checkers_come_with_defaultsz9TestFormatChecker.test_format_checkers_come_with_defaultsG   sB    
  /{+ 	AMM=M@	A 	A 	A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>R       r   barc                      yrH   r   r   s    r   rI   z-TestFormatChecker.test_repr.<locals>.<lambda>S   rJ   r   bazc                      yrH   r   r   s    r   rI   z-TestFormatChecker.test_repr.<locals>.<lambda>T   rJ   r   z.<FormatChecker checkers=['bar', 'baz', 'foo']>)r   r+   r'   reprr   s     r   	test_reprzTestFormatChecker.test_reprP   s`    +u01u01u01M<	
r   c                 
   	 ddl m} t               }| j                  |j	                  dd             | j                  |j	                  dd             | j                  |j	                  dd             y # t        $ r Y y w xY w)Nr   )is_duration   durationP4Ytest)jsonschema._formatrR   r   
assertTrueconformsr   ImportError)r   rR   r   s      r   test_duration_formatz&TestFormatChecker.test_duration_formatZ   su    	C6 $oGOOG,,Q
;<OOG,,UJ?@W--fjAB  		s   A6 6	BBc                     t               }| j                  |j                  dd             | j                  |j                  dd             | j                  |j                  dd             y )NrS   uuidz$6e6659ec-4503-4428-9f03-2e2ea4d6c278rV   )r   rX   rY   r   r   s     r   test_uuid_formatz"TestFormatChecker.test_uuid_formate   s\    /((F34CVL	
 	))&&9:r   N)__name__
__module____qualname__r   r    r)   r,   r;   rA   rD   rP   r[   r^   r   r   r   r   r      s6    +.

:	4A
	C;r   r   N)__doc__unittestr   
jsonschemar   r   r   jsonschema.validatorsr   r>   r   ZeroDivisionErrorr
   r   r   r   r   r   <module>rg      s?     B B 1'!W; W;r   