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)�mock�unittestc @ 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_match�reversed�assertEqual�format)�self�errors�bestZ reversed_bestr � r �%/usr/lib/python3.6/test_exceptions.pyr s zTestBestMatch.best_matchc C sH t ddddddiid�ii�}| j|jddg ii��}| j|jd� d S ) N� properties�foo� �bar�type�object)� 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 �anyOf�oneOfr 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"