B pSe @s\dZddlmZddlmZmZmZddlmZe dZ e dZ ddZ Gd d d eZd S) zP Tests for the parts of jsonschema related to the :validator:`format` property. )TestCase) FormatErrorValidationError FormatChecker)Draft4ValidatorzBoom!zBang!cCs|dkr ttdS)Nbang)BANGBOOM)thingr M/opt/alt/python37/lib/python3.7/site-packages/jsonschema/tests/test_format.pyboomsr c@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)TestFormatCheckercCstdd}||jdS)Nr )formats)rZ assertFalsecheckers)selfcheckerr r r test_it_can_validate_no_formatss z1TestFormatChecker.test_it_can_validate_no_formatsc Cs&|ttdgdWdQRXdS)Nzo noes)r) assertRaisesKeyErrorr)rr r r .test_it_raises_a_key_error_for_unknown_formatss z@TestFormatChecker.test_it_raises_a_key_error_for_unknown_formatscCsFttj}|tjjdtdt|tjt|tdfddS)Nr r )r )dictrrZ addCleanuppopZ cls_checksr assertEqual)rZoriginalr r r !test_it_can_register_cls_checkerss  z3TestFormatChecker.test_it_can_register_cls_checkerscCs4t}|dt||jttjtdfddS)Nr r )r )rchecksr rrr)rrr r r test_it_can_register_checkers's z/TestFormatChecker.test_it_can_register_checkersc Cst}|jdttdt|t}|jdddWdQRX||j j t||j j t|tt |jdddWdQRXdS)Nr )raises )instanceformatr) rrtyper r rrcheckassertIs exceptioncause __cause__r)rrcmr r r !test_it_catches_registered_errors/s z3TestFormatChecker.test_it_catches_registered_errorsc Cslt}|jdtdttddi|d}|t}|dWdQRX||j j t ||j j t dS)Nr )rr )Zformat_checkerr ) rr ValueErrorr rrrZvalidater#r$r%r r&)rrZ validatorr'r r r 7test_format_error_causes_become_validation_error_causes=s zITestFormatChecker.test_format_error_causes_become_validation_error_causesc Cs.t}|t|jdddWdQRXdS)Nz not-an-ipv4Zipv4)rr )rrrr")rrr r r 'test_format_checkers_come_with_defaultsHs z9TestFormatChecker.test_format_checkers_come_with_defaultscCsTtdd}|ddd|ddd|dd d|t|d dS) Nr )rZfoocSsdS)NTr )r r r r Sz-TestFormatChecker.test_repr..ZbarcSsdS)NTr )r r r r r,Tr-ZbazcSsdS)NTr )r r r r r,Ur-z.)rrrrepr)rrr r r test_reprQs zTestFormatChecker.test_reprN) __name__ __module__ __qualname__rrrrr(r*r+r/r r r r rs   rN)__doc__ZunittestrZ jsonschemarrrZjsonschema.validatorsrr)r ZeroDivisionErrorrr rr r r r s