B pSe@sddlmZddlmZddlmZddlmZddlm Z ddl Z ddl Z ddl Z ddl Z ddlZddlmZddlZddlmZmZmZmZdd lmZmZdd lmZd d ZGd ddeZGdddeZGddde ZGddde ZGddde Z Gddde!Z"Gddde"e!Z#Gddde!Z$Gddde$e#e Z%Gdd d e$e#e Z&Gd!d"d"e#e Z'Gd#d$d$e#e Z(Gd%d&d&eZ)Gd'd(d(eZ*Gd)d*d*eZ+d+d,Z,ej-Gd-d.d.e!Z.ej-Gd/d0d0e!Z/dS)1)deque)contextmanager)Decimal)BytesIO)TestCaseN)SynchronousTestCase) FormatChecker TypeChecker exceptions validators)PY3 pathname2url)bugccs||stdVdS)NzWhoops!) startswithr ValidationError) validatorrinstanceschemarQ/opt/alt/python37/lib/python3.7/site-packages/jsonschema/tests/test_validators.pyrs rc@sdeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ dS)TestCreateAndExtendcCsP||jtjttjddi|_dti|_t|_tj |j|j|jd|_ dS)Nz$idzsome://meta/schemar) meta_schemar type_checker) addCleanup assertEqualr meta_schemasdictrrr rcreate Validator)selfrrrsetUps   zTestCreateAndExtend.setUpcCs.||jj|jj|jjf|j|j|jfdS)N)rr VALIDATORS META_SCHEMA TYPE_CHECKERr rr)rrrr test_attrs*szTestCreateAndExtend.test_attrscCs ddi}|||j|dS)Nrfoo)rrr)rrrrr test_init7szTestCreateAndExtend.test_initcCsddi}||j}t|d}||gtjdd|ddtdgd}t|d}|t|d||d|dS) NrZhelZhellozWhoops!Zgoodbye)rrrvalidator_value schema_pathr) r iter_errorslistrr rrlenZ _contents)rrr*errorsZexpected_errorrrrtest_iter_errors;s    z$TestCreateAndExtend.test_iter_errorscCs4tjddidd}|tjjd||jddS)Nz$id somethingz my version)rversionZMyVersionValidator)r rrrpopr__name__)rrrrr.test_if_a_version_is_provided_it_is_registeredOs zBTestCreateAndExtend.test_if_a_version_is_provided_it_is_registeredcCs,ttj}tjddid|tj|dS)Nid)r)rr rrr)roriginalrrr6test_if_a_version_is_not_provided_it_is_not_registeredWs zJTestCreateAndExtend.test_if_a_version_is_not_provided_it_is_not_registeredcCsBd}d|i}tj|dddd|tjj|||tjdS)Nzmeta schema idr4z my versioncSs |ddS)Nr4)get)srrrczMTestCreateAndExtend.test_validates_registers_meta_schema_id..)rr0id_of)r rrrr1assertIn)rmeta_schema_keymy_meta_schemarrr'test_validates_registers_meta_schema_id\s z;TestCreateAndExtend.test_validates_registers_meta_schema_idcCs<d}d|i}tj|dd|tjj|||tjdS)Nzmeta schema $idz$idz my version)rr0)r rrrr1r=)rr>r?rrr.test_validates_registers_meta_schema_draft6_idiszBTestCreateAndExtend.test_validates_registers_meta_schema_draft6_idc sDtjidd|tfdddgfdddd d ifd gDdS) Nr)rr c3s$|]\}}ij||dVqdS))rtypeN)is_type).0rBr)rrr ysz@TestCreateAndExtend.test_create_default_types..array)booleanT)integer )nullN)numberg(@object)stringr%)r r assertTrueall)rr)rrtest_create_default_typesus z-TestCreateAndExtend.test_create_default_typescCs`t|jj}t}tj|jd|id}||j|j|j|jjft||d|jj|jj|fdS)Nnew)r )rQ) rrr!rLr extendrr"r#)rr5rQExtendedrrr test_extends   zTestCreateAndExtend.test_extendcsffdd}d}d|d}tj|jj|d}||j|t|}||j|dS)zK Extending a validator preserves its notion of schema IDs. cs|dj|S)N__test__)r8rID_OF)r)rrrr<sz3TestCreateAndExtend.test_extend_idof..id_ofzthe://correct/id/zthe://wrong/id/)z$idrU)rr rr<N)r rrrrVr"rR)rr<Z correct_idrZOriginalZDerivedr)rrtest_extend_idofs  z$TestCreateAndExtend.test_extend_idofN)r2 __module__ __qualname__r r$r&r.r3r6r@rArPrTrWrrrrrs   rc@steZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZdS)TestLegacyTypeCheckingc Cs:tjidd}|t|jddddddd h|dS) Nr)rr rFrGrHrJrKrLrM)r rrset DEFAULT_TYPES flushWarnings)rrrrrrPs z0TestLegacyTypeChecking.test_create_default_typesc Cstjidd}t|j}t}tj|d|id}||j|j|j|j|j |ij | ddft||d|j|j||j |j | ddfdS)Nr)rr rQ)r rmessage)rQ) r rrr!rLrRrr"r#r\r])rrr5rQrSrrrrTs*   z"TestLegacyTypeChecking.test_extendcCsPddi}|t|dtj|dttfid}||d|dS)NrBrMrI)types) assertFalser Draft7Validatoris_validstrintrNr])rrrrrr0test_types_redefines_the_validators_type_checkerszGTestLegacyTypeChecking.test_types_redefines_the_validators_type_checkerc Cs.|jtdtj|jjjtjiidtiddS)NzPThe default_types argument is deprecated. Use the type_checker argument instead.r%)categoryr^filenamefrr default_types) assertWarnsDeprecationWarningsysmodulesrX__file__r rrL)rrrr"test_providing_default_types_warnssz9TestLegacyTypeChecking.test_providing_default_types_warnsc Csvtjiitd}|tj }|jWdQRX|dt|j|tj|ijWdQRX| | dS)a We raise an error when you ask a validator with non-default type checker for its DEFAULT_TYPES. The type checker argument is new, so no one but this library itself should be trying to use it, and doing so while then asking for DEFAULT_TYPES makes no sense (not to mention is deprecated), since type checkers are not strictly about Python type. )rr rNz=DEFAULT_TYPES cannot be used on Validators using TypeCheckers) r rr assertRaisesZ _DontDoThatr\r=rc exceptionr`r])rrerrr?test_cannot_ask_for_default_types_with_non_default_type_checkers   zVTestLegacyTypeChecking.test_cannot_ask_for_default_types_with_non_default_type_checkercCs:tjiitd}|||i||dS)N)rr r)r rr r`r])rrrrr2test_providing_explicit_type_checker_does_not_warns zITestLegacyTypeChecking.test_providing_explicit_type_checker_does_not_warncCs6tjiid}|||i||dS)N)rr )r rr`r])rrrrr$test_providing_neither_does_not_warn#sz;TestLegacyTypeChecking.test_providing_neither_does_not_warnc CsR|t}tjiidtitdWdQRX|dt|j| | dS)Nr%)rr rirz:Do not specify default_types when providing a type checker) rp TypeErrorr rrLr r=rcrqr`r])rrrrrr5test_providing_default_types_with_type_checker_errors*s  zLTestLegacyTypeChecking.test_providing_default_types_with_type_checker_errorsc CsZtjiidtid}|t}tj|itdWdQRX|dt|j | dS)NrF)rr ri)r rzCannot extend a validator created with default_types with a type_checker. Update the validator to use a type_checker when created.) r rr+rprvrRr r=rcrqr])rrrrrrr.z%r is disallowed for [1, 2]rz[1, 2] is too shortz[1, 2] is not one of %rr)rr*rsorted)rrrZgotZexpectedrrrr.s zTestIterErrors.test_iter_errorscCs\ddgddd}dddid did dd d d gddi}t|j||}|t|d dS)Nrr)spam)r%r}bazquux propertiesrBrMr )maximumr)r%r}r)r+rr*rr,)rrrr-rrr0test_iter_errors_multiple_failures_one_validatorsz?TestIterErrors.test_iter_errors_multiple_failures_one_validatorN)r2rXrYr r.rrrrrrsrc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)S)*TestValidationErrorMessagesc OsB|dtj|tj}tj||f||WdQRX|jjS)Ncls) setdefaultr rrpr rvalidaterqr^)rrrargskwargsrrrrr message_forsz'TestValidationErrorMessages.message_forcCs&|jdddid}||dddS)Nr)rBrM)rrz1 is not of type %r)rr)rr^rrrtest_single_type_failuresz4TestValidationErrorMessages.test_single_type_failurecCs(|jdddgid}||dddS)Nr)rBrM)rrz1 is not of type %r)rr)rr^rrrtest_single_type_list_failuresz9TestValidationErrorMessages.test_single_type_list_failurecCs.d}|jddt|id}||d|dS)N)rMrLr)rB)rrz1 is not of type %r, %r)rr+r)rr_r^rrrtest_multiple_type_failuresz6TestValidationErrorMessages.test_multiple_type_failurecCs2dddigi}|jdd|gid}||ddS)NrBminimumrr))rrz1 is less than the minimum of 3)rr)rrBr^rrr&test_object_without_title_type_failureszBTestValidationErrorMessages.test_object_without_title_type_failurecCs.ddddgi}|jd|d}||ddS)NrBZFoor)namerr))rrz1 is less than the minimum of 3)rr)rrr^rrr#test_object_with_named_type_failuresz?TestValidationErrorMessages.test_object_with_named_type_failurecCs"|jdddid}||ddS)Nr)rr)rrz1 is less than the minimum of 2)rr)rr^rrr test_minimumsz(TestValidationErrorMessages.test_minimumcCs"|jdddid}||ddS)Nr)rr)rrz"1 is greater than the maximum of 0)rr)rr^rrr test_maximumsz(TestValidationErrorMessages.test_maximumcCsBd\}}d||ii}|jddi|tjd}||d||fdS)N)r}r% dependenciesr}r)rrrz%r is a dependency of %r)rr rr)rdependonrr^rrr test_dependencies_single_elements  z.formatZbla)rrformat_checkerzis not a)rchecksrr=r)rcheckerrr^rrr#test_invalid_format_default_message)s z?TestValidationErrorMessages.test_invalid_format_default_messagec Csddddiddidd}|jddi|tjd }||d tdtd td |jdd d|tjd }||dtdtdtd td dS)NrLFrBrM)z^abc$z^def$)rBrpatternPropertieszebra{)rrrz,{} does not match any of the regexes: {}, {}z^abc$z^def$i)rfishz.{}, {} do not match any of the regexes: {}, {}r)rr Draft4Validatorrrr)rrr^rrr1test_additionalProperties_false_patternProperties8s(  zMTestValidationErrorMessages.test_additionalProperties_false_patternPropertiescCs"|jddtjd}|d|dS)Nr/F)rrrz'False schema does not allow 'something')rr rar=)rr^rrrtest_False_schemaVs  z-TestValidationErrorMessages.test_False_schemaN)r2rXrYrrrrrrrrrrrrrrrrrrrrrrrrrs(      rc@s|eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZdS)TestValidationErrorDetailscCsd}dddiddigi}t|}t||}|t|d|d}||jd||j|d||j|||j || |j ||j t g||jt g||jt g||jt dg||jt dg||jt dg|t|jd t|j\}}||jd||j|ddd||j|||j |dd||j |||j t g||jt g||jt g||jt ddg||jt ddg||jt dddg||j||jd||j|ddd||j|||j |dd||j |||j t g||jt g||jt g||jt ddg||jt ddg||jt dddg|t|jddS) NanyOfrrBrMr)rr)r rr+r*rr,rr'rr assertIsNoneparentpathr relative_path absolute_pathr(relative_schema_pathabsolute_schema_pathcontext sorted_errorsassertIsr`)rrrrr-rre1e2rrr test_anyOfbs\    z%TestValidationErrorDetails.test_anyOfc Csddi}dddiddddgiidgi}t|}t||}|t|d|d }||jd||j|d||j|||j || |j ||j t g||jt g||jt g||jt dg||jt dg||jt dg|t|jdt|j\}}||jd||j|dd d||j|||j |dd ||j |||j t g||jt g||jt g||jt d dg||jt d dg||jt dd dg||j||jd||jdg||jd||j ddgi||j |||j t dg||jt dg||jt dg||jt dd ddg||jt dd ddg||jt ddd ddg||jdS) Nr%r)rBrHrLrr)rBrrr)r rr+r*rr,rr'rrrrrrrrr(rrrrrr`)rrrrr-rrrrrrr test_typesd   z$TestValidationErrorDetails.test_typec Csddgddd}dddid did dd d d gddi}t|}||}t|\}}}}||jtdg||jtdg||jtdg||jtdg||jtdg||jtdg||jtdg||jtdg||jtdg||jtdg||jtdg||jtdg||j d ||j d||j d||j ddS)Nrr)rr)r%r}rrrrBrMrrrrr)rr)r%r}rr}rr%rr) r rr*rrrrrrr) rrrrr-rre3e4rrrtest_single_nestings0  z.TestValidationErrorDetails.test_single_nestingc Csddddgiddg}dddgddd gid d d id diddddd}t|}||}t|\}}}}} } ||jtg||jtdg||jtddg||jtdddg|| jtdddg|| jtddg||jtdg||jtddg|t|jddddg|t|jdddddd g|t| jdddddd g|t| jddddg||j d||j d||j d||j d || j d || j ddS)Nr)rr)r%r}rrMrLrrrFrequiredTr)r}r)rBr)rBrrr}r%rBrr) r rr*rrrrr(r+r) rrrrr-rrrrZe5Ze6rrrtest_multiple_nestingsD   z0TestValidationErrorDetails.test_multiple_nestingcCsDdddddgddiddd d iid d d giiddgdd d iid}dddddddiid id i}t|}||\}||jtdg||jtdddg|j\}||jtdddg||jtdddddddddg |j\}||jtdddddg||jtdddddddddddddddgdS)NnoderrLrchildrenrBrMz^.*$z$refz#/definitions/node)rBr)rr)rBrrroot) definitionsrBrrrabrrr)r rr*rrrrr)rrrrrrrrrrrtest_recursiveFsp   z)TestValidationErrorDetails.test_recursivecCsddd}ddddi}t|}||}t|\}}||jtdg||jtdg||jd ||jd dS) Nr}r)r}r%rrHr)rBrr%rBr)r rr*rrrrr)rrrrr-rrrrrtest_additionalPropertiess    z4TestValidationErrorDetails.test_additionalPropertiescCsddd}dddiddidi}t|}||}t|\}}||jtd g||jtd g||jd||jddS) Nr)r)r}r%rrBrMrrr}r%)r rr*rrrrr)rrrrr-rrrrrtest_patternPropertiess    z1TestValidationErrorDetails.test_patternPropertiescCsddg}gdddd}t|}||}t|\}}||jtdg||jtdg||jd||jd dS) Nr%r)rHr)rBr)rrrrBr)r rr*rrrrr)rrrrr-rrrrrtest_additionalItemss   z/TestValidationErrorDetails.test_additionalItemscCsdddg}igdddd}t|}||}t|\}}||jtdg||jtdg||jd ||jd dS) Nr%r}r)rHr)rBr)rrrrBr)r rr*rrrrr)rrrrr-rrrrrtest_additionalItems_with_itemss    z:TestValidationErrorDetails.test_additionalItems_with_itemscCsddi}ddddiii}t|}||\}||jd||jdddidf||jtg||jtddgdS)Nr%rIZ propertyNamesnotrz%r is not allowed for %r) r rar*rrr^rrr()rrrrerrorrrrtest_propertyNamess  z-TestValidationErrorDetails.test_propertyNamescCsrddiddid}t|}|d\}||jd||jd||jtg||jtdddgdS)NrrI )ifthenz13 was expectedrr) r rar*rrr^rrr()rrrrrrr test_if_thens   z'TestValidationErrorDetails.test_if_thencCsrddiddid}t|}|d\}||jd||jd||jtg||jtdddgdS) NrrIr)relserz13 was expectedrr) r rar*rrr^rrr()rrrrrrr test_if_elses   z'TestValidationErrorDetails.test_if_elsec CsNtd}|d\}||j|j|j|j|j|j fdddddt gfdS)NFrIzFalse schema does not allow 12) r rar*rr^rr'rrr(r)rrrrrrtest_boolean_schema_Falses  z4TestValidationErrorDetails.test_boolean_schema_Falsec Csddddii}}tjd|itjdi||idd}|d d i\}||j|j|j|j|j |j |j fd ddd t d gddit ddgfdS) NZsomeRefrrBrHz$refr7)store)resolverr%Z notAnIntegerz''notAnInteger' is not of type 'integer') r ra RefResolverr*rr^rr'rrrr(r)rrefrrrrrrtest_ref-s(z#TestValidationErrorDetails.test_refN)r2rXrYrrrrrrrrrrrrrrrrrrr_sBJ"6brc@s,eZdZddZddZddZddZd S) MetaSchemaTestsMixinc Cs2|tj|jddtiiWdQRXdS)Nrtest)rpr SchemaErrorr check_schemarL)rrrrtest_invalid_propertiesMsz,MetaSchemaTestsMixin.test_invalid_propertiesc Cs,|tj|jddiWdQRXdS)Nr1)rpr rrr)rrrrtest_minItems_invalid_stringQsz1MetaSchemaTestsMixin.test_minItems_invalid_stringcCs|jdgidS)z Technically, all the spec says is they SHOULD have elements, not MUST. See https://github.com/Julian/jsonschema/issues/529. rN)rr)rrrrtest_enum_allows_empty_arraysVsz2MetaSchemaTestsMixin.test_enum_allows_empty_arrayscCs|jdddgidS)z Technically, all the spec says is they SHOULD be unique, not MUST. See https://github.com/Julian/jsonschema/issues/529. rrIN)rr)rrrr!test_enum_allows_non_unique_items^sz6MetaSchemaTestsMixin.test_enum_allows_non_unique_itemsN)r2rXrYrrrrrrrrrKsrc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ e edddZddZddZddZddZddZd d!Zd"d#Zd$S)%ValidatorTestMixincCs$|j\}}||||dS)N)validrNrrb)rrrrrrtest_valid_instances_are_validhs z1ValidatorTestMixin.test_valid_instances_are_validcCs$|j\}}||||dS)N)invalidr`rrb)rrrrrr$test_invalid_instances_are_not_validls z7ValidatorTestMixin.test_invalid_instances_are_not_validcCs |ttijtddS)N)r)rrLr)rrrr(test_non_existent_properties_are_ignoredpsz;ValidatorTestMixin.test_non_existent_properties_are_ignoredcCs||ijtjdS)N)ZassertIsInstancerrr r)rrrr.test_it_creates_a_ref_resolver_if_not_providedss zAValidatorTestMixin.test_it_creates_a_ref_resolver_if_not_providedc CsZdddi}}tjdi||id}|jd|i|d}|tj|dWdQRXdS)NZ someCoolRefrBrHr7)rz$ref)r)r rrrpr rr)rrrrrrrr#test_it_delegates_to_a_ref_resolverys z6ValidatorTestMixin.test_it_delegates_to_a_ref_resolverc sRGfdddt}|}ddi}tjj||ddWdQRXdS)zb Legacy RefResolvers support only the context manager form of resolution. cseZdZefddZdS)zXValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolver..LegacyRefResolverc3s|dddiVdS)Nzthe refrBrH)r)thisr)rrr resolvings zbValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolver..LegacyRefResolver.resolvingN)r2rXrYrr r)rrrLegacyRefResolversr z$refzthe ref)rN)rLrpr rrr)rr rrr)rr*test_it_delegates_to_a_legacy_ref_resolvers z=ValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolvercCs||idddS)Nr%rM)rNrrC)rrrr#test_is_type_is_true_for_valid_typesz6ValidatorTestMixin.test_is_type_is_true_for_valid_typecCs||idddS)Nr%rF)r`rrC)rrrr&test_is_type_is_false_for_invalid_typesz9ValidatorTestMixin.test_is_type_is_false_for_invalid_typecCs4||idd||idddS)NTrHrK)r`rrC)rrrr,test_is_type_evades_bool_inheriting_from_intsz?ValidatorTestMixin.test_is_type_evades_bool_inheriting_from_intz-In Python 3 json.load always produces unicodecCs|ddiddS)NrBrMsfoo)rr)rrrr$test_string_a_bytestring_is_a_stringsz7ValidatorTestMixin.test_string_a_bytestring_is_a_stringcCs|ddiddS)zF See https://github.com/Julian/jsonschema/issues/611. patternr%N)rr)rrrr#test_patterns_can_be_native_stringssz6ValidatorTestMixin.test_patterns_can_be_native_stringscCs~dddii}tj|j|jjdddd}||}|ddtdtd gd igd dg}|d d ||D|dS)NrrBrKcSst|tttfot|t S)N) isinstancerdfloatrbool)rrrrrr:szGValidatorTestMixin.test_it_can_validate_with_decimals..)rr)g?rr%TcSsg|] }|jqSr)r)rDrrrr szIValidatorTestMixin.test_it_can_validate_with_decimals..) r rRrr#redefinerrrr*)rrrrrrrr"test_it_can_validate_with_decimalss z5ValidatorTestMixin.test_it_can_validate_with_decimalscCs"|jdditd}|ddS)NrZcarrot)rZbugs)rrr)rrrrr7test_it_returns_true_for_formats_it_does_not_know_aboutszJValidatorTestMixin.test_it_returns_true_for_formats_it_does_not_know_aboutcCs|i}||jdS)N)rrr)rrrrr,test_it_does_not_validate_formats_by_defaults z?ValidatorTestMixin.test_it_does_not_validate_formats_by_defaultc s|t}td|jdtdfdd}jddi|d}|dtj}|d WdQRX|j j dS) NzBad!r%)Zraisescs.|dkr dS|dkrnd|dS)NgoodTbadz What is {}? [Baby Don't Hurt Me])failr)r)rrrrchecks zTValidatorTestMixin.test_it_validates_formats_if_a_checker_is_provided..checkr)rrr) r ValueErrorrrrrpr rrrqcause)rrr rcmr)rrr2test_it_validates_formats_if_a_checker_is_provideds  zEValidatorTestMixin.test_it_validates_formats_if_a_checker_is_providedcCsBt}d|gi}tj|j|jj|ddd}||ddS)NrBcSs t|tS)N)rrd)rrrrrr:r;z@ValidatorTestMixin.test_non_string_custom_type..)rr)rLr rRrr#rr)rZnon_string_typerCrazyrrrtest_non_string_custom_types z.ValidatorTestMixin.test_non_string_custom_typec Cs`tj|j|jjdddd}|tj}|ddidWdQRX| d t |j dS) z A tuple instance properly formats validation errors for uniqueItems. See https://github.com/Julian/jsonschema/pull/224 rFcSs t|tS)N)rtuple)rrrrrr:r;zNValidatorTestMixin.test_it_properly_formats_tuples_in_errors..)rZ uniqueItemsT)r)r)Nz(1, 1) has non-unique elements) r rRrr#rrpr rrr=rcrq)rZTupleValidatorrrrrr)test_it_properly_formats_tuples_in_errorssz.)rrBrIr%N) r rRrr#rrrpr r)rr%rrrrtest_any_type_is_redefinable#s  z0TestDraft3Validator.test_any_type_is_redefinablecCs"||itddidS)NrBr4)rNrrbrL)rrrr!test_is_type_is_true_for_any_type2sz5TestDraft3Validator.test_is_type_is_true_for_any_typecCs8||idd||idddidS)NTrGrBr4)rNrrCrb)rrrr6test_is_type_does_not_evade_bool_if_it_is_being_tested5szJTestDraft3Validator.test_is_type_does_not_evade_bool_if_it_is_being_testedN) r2rXrYr rrrrr5r6r7r8rrrrr3s r3c@s&eZdZejZiifZddidfZdS)TestDraft4ValidatorrBrHr%N)r2rXrYr rrrrrrrrr9:sr9c@s&eZdZejZiifZddidfZdS)TestDraft6ValidatorrBrHr%N)r2rXrYr rrrrrrrrr:@sr:c@s&eZdZejZiifZddidfZdS)TestDraft7ValidatorrBrHr%N)r2rXrYr rarrrrrrrr;Fsr;c@sleZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZdS)TestValidatorForcCs<ddi}|t|tjddi}|t|tjdS)Nz$schemaz&http://json-schema.org/draft-03/schemaz'http://json-schema.org/draft-03/schema#)rr validator_forr)rrrrr test_draft_3MszTestValidatorFor.test_draft_3cCs<ddi}|t|tjddi}|t|tjdS)Nz$schemaz&http://json-schema.org/draft-04/schemaz'http://json-schema.org/draft-04/schema#)rr r=r)rrrrr test_draft_4ZszTestValidatorFor.test_draft_4cCs<ddi}|t|tjddi}|t|tjdS)Nz$schemaz&http://json-schema.org/draft-06/schemaz'http://json-schema.org/draft-06/schema#)rr r=r)rrrrr test_draft_6gszTestValidatorFor.test_draft_6cCs<ddi}|t|tjddi}|t|tjdS)Nz$schemaz&http://json-schema.org/draft-07/schemaz'http://json-schema.org/draft-07/schema#)rr r=ra)rrrrr test_draft_7tszTestValidatorFor.test_draft_7cCs|tdtjdS)NT)rr r=_LATEST_VERSION)rrrr test_TrueszTestValidatorFor.test_TruecCs|tdtjdS)NF)rr r=rB)rrrr test_FalseszTestValidatorFor.test_FalsecCs6tjddidddd}ddi}|t||dS)Nr4zmeta schema idZ12cSs |ddS)Nr4r7)r8)r9rrrr:r;z8TestValidatorFor.test_custom_validator..)rr0r<z$schema)r rrr=)rrrrrrtest_custom_validators z&TestValidatorFor.test_custom_validatorcCs0tjddidd}ddi}|t||dS)Nz$idzmeta schema $idZ13)rr0z$schema)r rrr=)rrrrrrtest_custom_validator_draft6sz-TestValidatorFor.test_custom_validator_draft6cCs|titjdS)N)rr r=rB)rrrr%test_validator_for_jsonschema_defaultsz6TestValidatorFor.test_validator_for_jsonschema_defaultcCs|tjiddddS)N)default)rr r=)rrrr!test_validator_for_custom_defaultsz2TestValidatorFor.test_validator_for_custom_defaultcCs,|jtdtj|jjjtjddiiddS)NzThe metaschema specified by $schema was not found. Using the latest draft to validate, but this will raise an error in the future.z$schemaZ unknownSchema)rfr^rgrhrrH)rjrkrlrmrXrnr r=)rrrr1test_warns_if_meta_schema_specified_was_not_foundszBTestValidatorFor.test_warns_if_meta_schema_specified_was_not_foundcCs"tjiidf||dS)N)rrH)r r=r`r])rrrr0test_does_not_warn_if_meta_schema_is_unspecifiedszATestValidatorFor.test_does_not_warn_if_meta_schema_is_unspecifiedN)r2rXrYr>r?r@rArCrDrErFrGrIrJrKrrrrr<Ls      r<c@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS) TestValidatecCs2g}||d|jti||||gdS)Nr)patchappendr rr)rrrresultrrr assertUsess zTestValidate.assertUsescCs,|jdditjd|jdditjddS)Nz$schemaz'http://json-schema.org/draft-03/schema#)rrz&http://json-schema.org/draft-03/schema)rPr r)rrrrtest_draft3_validator_is_chosens  z,TestValidate.test_draft3_validator_is_chosencCs,|jdditjd|jdditjddS)Nz$schemaz'http://json-schema.org/draft-04/schema#)rrz&http://json-schema.org/draft-04/schema)rPr r)rrrrtest_draft4_validator_is_chosens  z,TestValidate.test_draft4_validator_is_chosencCs,|jdditjd|jdditjddS)Nz$schemaz'http://json-schema.org/draft-06/schema#)rrz&http://json-schema.org/draft-06/schema)rPr r)rrrrtest_draft6_validator_is_chosens  z,TestValidate.test_draft6_validator_is_chosencCs,|jdditjd|jdditjddS)Nz$schemaz'http://json-schema.org/draft-07/schema#)rrz&http://json-schema.org/draft-07/schema)rPr ra)rrrrtest_draft7_validator_is_chosens  z,TestValidate.test_draft7_validator_is_chosencCs|jitjddS)N)rr)rPr ra)rrrr$test_draft7_validator_is_the_defaultsz1TestValidate.test_draft7_validator_is_the_defaultc Cs>|tj}tdddiWdQRX|t|jddS)NrIrBrMz3(?s)Failed validating u?'.*' in schema.*On instance)rpr rr rassertRegexpMatchesrcrq)rrrrrrtest_validation_error_messages z*TestValidate.test_validation_error_messagec Cs>|tj}tdddiWdQRX|t|jddS)NrIrBz5(?s)Failed validating u?'.*' in metaschema.*On schema)rpr rr rrVrcrq)rrrrrrtest_schema_error_messages z&TestValidate.test_schema_error_messagec CsNdddiddigi}|tj}td|WdQRX|dt|jdS)NoneOfrBrMrFrIz12 is not of type)rpr rr rr=rcrq)rrrrrrrtest_it_uses_best_matchsz$TestValidate.test_it_uses_best_matchN) r2rXrYrPrQrRrSrTrUrWrXrZrrrrrLs    rLc@seZdZdZdZddiZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZdd Zd!d"Zd#S)$TestRefResolverr7z foo://storedZstoredrcCs.i|_|j|ji|_t|j|j|j|_dS)N)referrer stored_uri stored_schemarr rbase_urir)rrrrr szTestRefResolver.setUpc sPtjjd}jdfddj|}WdQRX|tjjdS)Nr4Zresolve_remotecs dS)NzShould not have been called!)r)rr)rrrr:r;zXTestRefResolver.test_it_does_not_retrieve_schema_urls_from_the_network..)r rr"rMrr r)rrresolvedr)rr6test_it_does_not_retrieve_schema_urls_from_the_networks  zFTestRefResolver.test_it_does_not_retrieve_schema_urls_from_the_networkc CsFd}dti|jd<|j|}|||jddWdQRXdS)Nz#/properties/foor%r)rLr\rr r)rrr`rrrtest_it_resolves_local_refs%sz+TestRefResolver.test_it_resolves_local_refsc Csrdddid}tjj|ddd}|d}|||d WdQRX|d }|||d WdQRXdS) Nzhttp://bar/schema#r%r})r4rcSs |ddS)Nr4r7)r8)rrrrr:/r;zETestRefResolver.test_it_resolves_local_refs_with_id..)r<z#/arzhttp://bar/schema#/a)r r from_schemar r)rrrr`rrr#test_it_resolves_local_refs_with_id+s   z3TestRefResolver.test_it_resolves_local_refs_with_idc Cs`|j|j}|||jWdQRXddi|jjd<|jd}||dWdQRXdS)Nr%rIZ cached_refzcached_ref#/foo)rr r]rr^rr)rr`rrrtest_it_retrieves_stored_refs6s z-TestRefResolver.test_it_retrieves_stored_refsc Cshd}ddi}dtjkr.|tjjdtjdtd|itjd<|j|}||dWdQRXdS)Nzhttp://bar#bazrrIrequestsz http://bar)rlrmr __setitem__ReallyFakeRequestsrr r)rrrr`rrr,test_it_retrieves_unstored_refs_via_requests>s z.fake_urlopenurlopen) rlrmrrgrsetattrr rprr r)rrror`r)rrr+test_it_retrieves_unstored_refs_via_urlopenKs   z;TestRefResolver.test_it_retrieves_unstored_refs_via_urlopenc Csrtjddd&}|tj|jtddi|WdQRXdt |j}|j |}| |dWdQRXdS)NFwt)deletemoder%r}z file://{}#foo) tempfileNamedTemporaryFilerosremoverrkdumprr rr r)rZtempfrr`rrr(test_it_retrieves_local_refs_via_urlopenas z8TestRefResolver.test_it_retrieves_local_refs_via_urlopenc Csddi}tjj|ddd}||jd||jd|d}|||WdQRX|d}|||WdQRX|d}|||WdQRX|d}|||WdQRXdS) Nr4r%cSs |ddS)Nr4r7)r8)rrrrr:nr;zPTestRefResolver.test_it_can_construct_a_base_uri_from_a_schema..)r<r7#zfoo#)r rrcrr_resolution_scoper )rrrr`rrr.test_it_can_construct_a_base_uri_from_a_schemajs     z>TestRefResolver.test_it_can_construct_a_base_uri_from_a_schemac Csti}tj|}||jd||jd|d}|||WdQRX|d}|||WdQRXdS)Nr7r|)r rrcrr_r}r )rrrr`rrr9test_it_can_construct_a_base_uri_from_a_schema_without_id{s   zITestRefResolver.test_it_can_construct_a_base_uri_from_a_schema_without_idc sVfdd}ddidtjdid|id}|}|WdQRXdS)Ncs|S)N)r)rn)rrrrrhandlers z@TestRefResolver.test_custom_uri_scheme_handlers..handlerr%r}z foo://barr7)handlers)r rr r)rrrr`r)rrrrtest_custom_uri_scheme_handlerss  z/TestRefResolver.test_custom_uri_scheme_handlersc s`tgfdd}d}tjdidd|id}||WdQRX||WdQRXdS)Ncs,yStk r&dYnXdS)Nz#Response must not have been cached!)r1 IndexErrorr)rn)responserrrrsz5TestRefResolver.test_cache_remote_on..handlerz foo://barr7Tr%) cache_remoter)rLr rr )rrrrr)rrrtest_cache_remote_ons   z$TestRefResolver.test_cache_remote_onc sJtgfdd}d}tjdidd|id}||WdQRXdS)Ncs,yStk r&dYnXdS)NzHandler called twice!)r1rr)rn)rrrrrsz6TestRefResolver.test_cache_remote_off..handlerz foo://barr7Fr%)rr)rLr rr )rrrrr)rrrtest_cache_remote_offs z%TestRefResolver.test_cache_remote_offc s|tdfdd}d}tjdid|id}|tj&}|||dWdQRXWdQRX||j tdS) NzOh no! What's this?csdS)Nr)rn)rrrrszTTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_error..handlerz foo://barr7r%)rzShouldn't get this far!) r!r rrpr RefResolutionErrorr rrrq)rrrrerrr)rr3test_if_you_give_it_junk_you_get_a_resolution_errors  zCTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_errorc CsJtdi}||tj}|WdQRX|dt|jdS)Nr7zFailed to pop the scope) r rZ pop_scoperpr rr=rcrq)rrexcrrr.test_helpful_error_message_on_failed_pop_scopes  z>TestRefResolver.test_helpful_error_message_on_failed_pop_scopeN)r2rXrYr_r]r^r rarbrdrerirrr{r~rrrrrrrrrrr[ s$       r[cCsdd}t||dS)NcSs dd|jDdd|jDfS)NcSsg|] }t|qSr)rc)rDrrrrrrsz.sorted_errors..key..cSsg|] }t|qSr)rc)rDrrrrrrs)rr()rrrrkeyszsorted_errors..key)r)r)r-rrrrrsrc@seZdZeZddZdS)rhcCs2|j|}|dkr$tdt|tt|S)Nz Unknown URL: ) _responsesr8r!r_ReallyFakeJSONResponserkrl)rrnrrrrr8s zReallyFakeRequests.getN)r2rXrYattribrr8rrrrrhsrhc@seZdZeZddZdS)rcCs t|jS)N)rkloads _response)rrrrrksz_ReallyFakeJSONResponse.jsonN)r2rXrYrrrrkrrrrrsr)0 collectionsr contextlibrZdecimalriorr)rrkrxrlrvZtwisted.trial.unittestrrZ jsonschemarr r r Zjsonschema.compatr r Zjsonschema.tests._helpersrrrrZrrrrLrrr*r3r9r:r;r<rLr[rr9rhrrrrrsV       ]"/o sN;