3 +;X 6 @ s d dl Z d dlmZmZ d dlmZ d dlmZmZ G dd dej Z G dd dej ZG d d d ej ZG dd dej Z dS ) N)Draft4Validator exceptions)PY3)mockunittestc @ sT e Zd Zdd Zdd Zdd Zdd Zd d Zdd Zd d Z dd Z dd ZdS ) TestBestMatchc C s@ t |}tj|}tjt|}d}| j|||j||d |S )Nz:Didn't return a consistent best match! Got: {0} Then: {1})msg)listr best_matchreversedassertEqualformat)selferrorsbestZ reversed_bestr r %/usr/lib/python3.6/test_exceptions.pyr s zTestBestMatch.best_matchc C sH t ddddddiidii}| j|jddg ii}| j|jd d S ) N propertiesfoo bartypeobject) minPropertiesr r )r r iter_errorsr validator)r r r r r r (test_shallower_errors_are_better_matches s z6TestBestMatch.test_shallower_errors_are_better_matchesc C sJ t dddiddigddiddigd}| j|ji }| j|jd dS )zo A property you *must* match is probably better than one you have to match a part of. r r stringZnumber)r anyOfoneOfr N)r r r r r )r r r r r r %test_oneOf_and_anyOf_are_weak_matches! s z3TestBestMatch.test_oneOf_and_anyOf_are_weak_matchesc C sR t dddddiddddiiigiii}| j|jdddii}| j|jd d S ) aM If the most relevant error is an anyOf, then we traverse its context and select the otherwise *least* relevant error, since in this case that means the most specific, deep, error inside the instance. I.e. since only one of the schemas must match, we look for the most relevant one. r r r r r r array N)r r r r validator_value)r r r r r r 8test_if_the_most_relevant_error_is_anyOf_it_is_traversed2 s zFTestBestMatch.test_if_the_most_relevant_error_is_anyOf_it_is_traversedc C sR t dddddiddddiiigiii}| j|jdddii}| j|jd d S ) aM If the most relevant error is an oneOf, then we traverse its context and select the otherwise *least* relevant error, since in this case that means the most specific, deep, error inside the instance. I.e. since only one of the schemas must match, we look for the most relevant one. r r r r r r r! r" N)r r r r r# )r r r r r r 8test_if_the_most_relevant_error_is_oneOf_it_is_traversedL s zFTestBestMatch.test_if_the_most_relevant_error_is_oneOf_it_is_traversedc C sR t dddddiddddiiigiii}| j|jdddii}| j|jd d S ) z Now, if the error is allOf, we traverse but select the *most* relevant error from the context, because all schemas here must match anyways. r r ZallOfr r r r! r" N)r r r r r# )r r r r r r 8test_if_the_most_relevant_error_is_allOf_it_is_traversedf s zFTestBestMatch.test_if_the_most_relevant_error_is_allOf_it_is_traversedc C s^ t dddddidddiddddiiigigiii}| j|jdddii}| j|jd d S ) Nr r r r r r r! r" )r r r r r# )r r r r r r test_nested_context_for_oneOf| s z+TestBestMatch.test_nested_context_for_oneOfc C s6 t ddi}|ji \}| jtj|ji jd d S )Nr r )r r r r r r )r r errorr r r test_one_error s zTestBestMatch.test_one_errorc C s" t i }| jtj|ji d S )N)r ZassertIsNoner r r )r r r r r test_no_errors s zTestBestMatch.test_no_errorsN)__name__ __module____qualname__r r r r$ r% r&