U `O@sddlZddlZddlmZmZmZmZddlmZidddfddZ ddZ dd Z dd d Z dd dZ dddZddZddZddZdddZdS)N)errors Validator SchemaError DocumentError) sample_schemac Csf|dkrt}|dkr8t||||W5QRXn*tj|t|d|||W5QRXdS)z Tests whether a specific exception is raised. Optionally also tests whether the exception message is as expected. N)match)rpytestZraisesreescape)Z exceptiondocumentschema validatormsgrH/opt/alt/python38/lib/python3.8/site-packages/cerberus/tests/__init__.pyassert_exception s rcGsttf|dS)zITests whether a validation raises an exception due to a malformed schema.N)rrargsrrrassert_schema_errorsrcGsttf|dS)zKTests whether a validation raises an exception due to a malformed document.N)rrrrrrassert_document_errorsrFc Cs|dkrtt}||||}t|ts*t|r2t|j}|dk rL|dk rLt|dk rd|dk rdtd|dk rx|dkrxt|dk rt|dkstt|f||dk rt|djt|kstt |dj|n&|dk rt|t|kstt |||S)z!Tests whether a validation fails.NzGchild_errors can only be tested in conjunction with the error parameterr) rr isinstanceboolAssertionError_errorslenassert_has_error child_errorsassert_has_errors) r r r updateerrorrrresultZ actual_errorsrrr assert_fail$s*   r"cCs<|dkrtt}||||}t|ts*t|s8t|jdS)z$Tests whether a validation succeeds.N)rrrrrr)r r r rr!rrrassert_successJs  r#rc Cst|ts|f}t|ts |f}t|tjs0tt|D]\}}t|tjsPtzb|j|ks`t|j|ksnt|j |j ks~t|j |j kst|j |kst|j s|j |kstWn(tk rYq8tk rYq8Xqq8tdj||t|j |||d|S)Nz Error with properties: document_path={doc_path} schema_path={schema_path} code={code} constraint={constraint} info={info} not found in errors: {errors} )Zdoc_path schema_pathcodeinfo constraintr)rtuplerZ ErrorListr enumerateZValidationErrorZ document_pathr$r%Zruler'Zis_group_errorr& Exceptionformathex)rZd_pathZs_pathZ error_defr'r&ir rrrrTs>   rcCs8t|tst|D] }t|ts$tt|f|qdSN)rlistrr(r)rZ _exp_errorsr rrrrsrc OsZzt|f||Wn8tk r(Yn.tk rL}z|W5d}~XYn XtddS)NzAn unexpected error occurred.)rrr*)rrkwargserrrassert_not_has_errorsr2cCs"t||i||dftj|fddS)Ntype)r )r"rZBAD_TYPE)ZfieldZ data_typevaluerrrassert_bad_typesr5cCs.|dkrtt}t||||j|ks*tdSr.)rrr#r r)r Zexpectedr r rrrassert_normalizeds r6)NNFNNN)NNF)r)NN)r rZcerberusrrrrZcerberus.tests.conftestrrrrr"r#rrr2r5r6rrrrs&  & /