ó
ž›V]c           @   s´   d  d l  m Z d  d l Z d  d l m Z m Z d  d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d	 e f d
 „  ƒ  YZ
 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   TestCaseN(   t   Draft4Validatort
   exceptions(   t   PY3t   TestBestMatchc           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   sh   t  | ƒ } t j | ƒ } t j t | ƒ ƒ } d } |  j | j ƒ  | j ƒ  d | j | | ƒ ƒ| S(   Ns:   Didn't return a consistent best match!
Got: {0}

Then: {1}t   msg(   t   listR   t
   best_matcht   reversedt   assertEqualt	   _contentst   format(   t   selft   errorst   bestt   reversed_bestR   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyR   	   s    c         C   ss   t  i i i d d 6i i d d 6d 6d 6d 6d 6ƒ } |  j | j i i g  d 6d 6ƒ ƒ } |  j | j d ƒ d  S(   Ni   t   minPropertiest   objectt   typet   bart
   propertiest   foo(   R   R   t   iter_errorsR	   t	   validator(   R   R   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt(   test_shallower_errors_are_better_matches   s    #&c         C   sx   t  i d d 6i d d 6i d d 6g d 6i d d 6i d d 6g d 6ƒ } |  j | j i  ƒ ƒ } |  j | j d ƒ d S(	   so   
        A property you *must* match is probably better than one you have to
        match a part of.

        i   R   t   stringR   t   numbert   anyOft   oneOfN(   R   R   R   R	   R   (   R   R   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt%   test_oneOf_and_anyOf_are_weak_matches"   s    !c      
   C   s€   t  i i i i d d 6i i i d d 6d 6d 6g d 6d 6d 6ƒ } |  j | j i i d d 6d 6ƒ ƒ } |  j | j d ƒ d	 S(
   sM  
        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   t   arrayR   R   R   R   i   N(   R   R   R   R	   t   validator_value(   R   R   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt8   test_if_the_most_relevant_error_is_anyOf_it_is_traversed3   s    
-&c      
   C   s€   t  i i i i d d 6i i i d d 6d 6d 6g d 6d 6d 6ƒ } |  j | j i i d d 6d 6ƒ ƒ } |  j | j d ƒ d	 S(
   sM  
        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   i   N(   R   R   R   R	   R   (   R   R   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt8   test_if_the_most_relevant_error_is_oneOf_it_is_traversedM   s    
-&c      
   C   s€   t  i i i i d d 6i i i d d 6d 6d 6g d 6d 6d 6ƒ } |  j | j i i d d 6d 6ƒ ƒ } |  j | j d ƒ d	 S(
   s¦   
        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   R   R   R   t   allOfR   i   N(   R   R   R   R	   R   (   R   R   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt8   test_if_the_most_relevant_error_is_allOf_it_is_traversedg   s    
-&c         C   s”   t  i i i i d d 6i i d d 6i i i d d 6d 6d 6g d 6g d 6d 6d 6ƒ } |  j | j i i d d 6d 6ƒ ƒ } |  j | j d ƒ d  S(	   NR   R   R   R   R   R   R   i   (   R   R   R   R	   R   (   R   R   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   test_nested_context_for_oneOf}   s    

.
&c         C   sN   t  i d d 6ƒ } | j i  ƒ \ } |  j t j | j i  ƒ ƒ j d ƒ d  S(   Ni   R   (   R   R   R	   R   R   R   (   R   R   t   error(    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   test_one_error–   s
    c         C   s/   t  i  ƒ } |  j t j | j i  ƒ ƒ ƒ d  S(   N(   R   t   assertIsNoneR   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   test_no_errorsž   s    (   t   __name__t
   __module__R   R   R   R    R!   R#   R$   R&   R(   (    (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyR      s   								t   TestByRelevancec           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   t  j d d d g ƒ} t  j d d d d g ƒ} t | | g d t  j ƒ} |  j | | ƒ t | | g d t  j ƒ} |  j | | ƒ d  S(   Ns   Oh no!t   patht   bazs   Oh yes!R   R   t   key(   R   t   ValidationErrort   maxt	   relevancet   assertIs(   R   t   shallowt   deept   match(    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt#   test_short_paths_are_better_matches¤   s    c         C   sÑ   t  j d d g  ƒ} t  j d d d g ƒ} t | | g d t  j ƒ} |  j g  | D] } t | j ƒ ^ qU d g g  g ƒ t | | g d t  j ƒ} |  j g  | D] } t | j ƒ ^ q¥ d g g  g ƒ d  S(   Ns   Oh no!R,   s   Oh yes!R   R.   (   R   R/   t   sortedR1   R	   R   R,   (   R   R3   R4   R   R%   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt*   test_global_errors_are_even_better_matches­   s    c         C   sœ   t  j d d g  d d ƒ} t  j d d g  d d ƒ} t  j d d ƒ } t | | g d | ƒ} |  j | | ƒ t | | g d | ƒ} |  j | | ƒ d  S(	   Ns   Oh no!R,   R   t   as   Oh yes!t   bt   weakR.   (   R   R/   t   by_relevanceR0   R2   (   R   R;   t   normalR   R5   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt'   test_weak_validators_are_lower_priority½   s    c         C   sÃ   t  j d d g  d d ƒ} t  j d d g  d d ƒ} t  j d d g  d d ƒ} t  j d	 d d
 d ƒ } t | | | g d | ƒ} |  j | | ƒ t | | | g d | ƒ} |  j | | ƒ d  S(   Ns   Oh no!R,   R   R9   s   Oh yes!R:   s   Oh fine!t   cR;   t   strongR.   (   R   R/   R<   R0   R2   (   R   R;   R=   R@   R   R5   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt*   test_strong_validators_are_higher_priorityÉ   s    (   R)   R*   R6   R8   R>   RA   (    (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyR+   £   s   				t   TestErrorTreec           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   sT   g  t  d ƒ D] } t j d d | ƒ^ q } t j | ƒ } |  j | j d ƒ d  S(   Ni   t	   SomethingR   (   t   rangeR   R/   t	   ErrorTreeR	   t   total_errors(   R   t   iR   t   tree(    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt/   test_it_knows_how_many_total_errors_it_containsØ   s    +c         C   s>   t  j d d d g ƒg } t  j | ƒ } |  j d | ƒ d  S(   Ns	   a messageR,   R   (   R   R/   RE   t   assertIn(   R   R   RH   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt1   test_it_contains_an_item_if_the_item_had_an_errorá   s    c         C   s>   t  j d d d g ƒg } t  j | ƒ } |  j d | ƒ d  S(   Ns	   a messageR,   R   R   (   R   R/   RE   t   assertNotIn(   R   R   RH   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt9   test_it_does_not_contain_an_item_if_the_item_had_no_erroræ   s    c         C   sE   t  j d d d ƒ} t  j | g ƒ } |  j | j i | d 6ƒ d  S(   Ns	   a messageR   R   (   R   R/   RE   R	   R   (   R   R%   RH   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt1   test_validators_that_failed_appear_in_errors_dictë   s    c         C   sn   t  j d d d g ƒt  j d d d d g ƒg } t  j | ƒ } |  j d | d ƒ |  j d | d ƒ d  S(   Ns   a bar messageR,   R   s   a bar -> 0 messagei    i   (   R   R/   RE   RJ   RL   (   R   R   RH   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt1   test_it_creates_a_child_tree_for_each_nested_pathð   s
    c         C   s…   t  j d d d d d d g ƒt  j d d d d d d g ƒ} } t  j | | g ƒ } |  j | d d j i | d 6| d 6ƒ d  S(	   Nt   1R   R   R,   R   i    t   2t   quux(   R   R/   RE   R	   R   (   R   t   e1t   e2RH   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt+   test_children_have_their_errors_dicts_builtù   s    %c      	   C   sf   t  j d d d d d d g d d ƒt  j d	 d d
 d d d g d d ƒ} } t  j | | g ƒ d  S(   NRP   R   R   R,   R   t   bar2t   instancet   i1RQ   RR   t   foobari   t   i2(   R   R/   RE   (   R   RS   RT   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt"   test_multiple_errors_with_instance  s    c         C   sO   t  j d d d d g  ƒ} t  j | g ƒ } |  j t ƒ  | d Wd  QXd  S(   Nt   123R   R   RW   i    (   R   R/   RE   t   assertRaisest
   IndexError(   R   R%   RH   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt>   test_it_does_not_contain_subtrees_that_are_not_in_the_instance  s    c         C   sQ   t  j d d d d i  d d g ƒ} t  j | g ƒ } |  j | d t  j ƒ d S(   sË   
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        s	   a messageR   R   RW   R,   N(   R   R/   RE   t   assertIsInstance(   R   R%   RH   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt9   test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error  s    (   R)   R*   RI   RK   RM   RN   RO   RU   R[   R_   Ra   (    (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyRB   ×   s   										t   TestErrorInitReprStrc           B   sb   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   c         K   sH   t  d d d d d d d d d	 i d d 6ƒ } | j | ƒ t j |   S(
   Nt   messageu   helloR   u   typeR   u   stringRW   i   t   schema(   t   dictt   updateR   R/   (   R   t   kwargst   defaults(    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt
   make_error'  s    c         K   s‡   t  r | j d d ƒ } n  t j | ƒ j d ƒ } |  j |   } t | ƒ j d ƒ \ } } } |  j | | j	 ƒ |  j | | ƒ d  S(   Ns   u't   's   
(
   R   t   replacet   textwrapt   dedentt   rstripRi   t   strt	   partitionR	   Rc   (   R   t   expectedRg   R%   t   message_linet   _t   rest(    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   assertShows2  s    c         C   s)   |  j  ƒ  } |  j t | j ƒ d ƒ d  S(   Ni   (   Ri   t   assertGreatert   lent   args(   R   R%   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt!   test_it_calls_super_and_sets_args<  s    c         C   s*   |  j  t t j d d ƒ ƒ d d ƒ d  S(   NRc   s   Hello!s   <ValidationError: %r>(   R	   t   reprR   R/   (   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt	   test_repr@  s    c         C   sž   t  j d ƒ } |  j t | ƒ d ƒ i d d 6d d 6d d 6i d d 6d 6} xI | D]A } t | ƒ } | | =t  j d |  } |  j t | ƒ d ƒ qU Wd  S(	   NRc   R   R   R   R   i   RW   Rd   (   R   R/   R	   Ro   Re   (   R   R%   Rg   t   attrt   k(    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   test_unset_errorF  s    c         C   s   |  j  d d g  d g  ƒd  S(   Ns   
            Failed validating u'type' in schema:
                {u'type': u'string'}

            On instance:
                5
            R,   t   schema_path(   Ru   (   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   test_empty_pathsW  s    c         C   s#   |  j  d d d g d d g ƒd  S(   Ns’   
            Failed validating u'type' in schema:
                {u'type': u'string'}

            On instance[0]:
                5
            R,   i    R   t   items(   Ru   (   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   test_one_item_pathsd  s    	c         C   s,   |  j  d d d d g d d d d g ƒd  S(   Ns¥   
            Failed validating u'type' in schema[u'items'][0]:
                {u'type': u'string'}

            On instance[0][u'a']:
                5
            R,   i    u   aR   u   itemsi   (   Ru   (   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   test_multiple_item_pathsq  s    c      
   C   sJ   |  j  d d t t d ƒ ƒ d t t t d ƒ t d ƒ ƒ ƒ d d ƒd  S(   Ns@  
            Failed validating u'maxLength' in schema:
                {0: 0,
                 1: 1,
                 2: 2,
                 3: 3,
                 4: 4,
                 5: 5,
                 6: 6,
                 7: 7,
                 8: 8,
                 9: 9,
                 10: 10,
                 11: 11,
                 12: 12,
                 13: 13,
                 14: 14,
                 15: 15,
                 16: 16,
                 17: 17,
                 18: 18,
                 19: 19}

            On instance:
                [0,
                 1,
                 2,
                 3,
                 4,
                 5,
                 6,
                 7,
                 8,
                 9,
                 10,
                 11,
                 12,
                 13,
                 14,
                 15,
                 16,
                 17,
                 18,
                 19,
                 20,
                 21,
                 22,
                 23,
                 24]
            RW   i   Rd   i   R   u	   maxLength(   Ru   R   RD   Re   t   zip(   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   test_uses_pprint~  s
    2!c      
      sl   d t  f ‡  f d †  ƒ  Y} | ƒ  } t j d d d d | d d d	 d	 ƒ} ˆ  j t | ƒ t | ƒ ƒ d
 S(   sà   
        Check for https://github.com/Julian/jsonschema/issues/164 which
        rendered exceptions unusable when a `ValidationError` involved
        instances with an `__eq__` method that returned truthy values.

        t   DontEQMeBroc              s&   e  Z ‡  f d  †  Z ‡  f d †  Z RS(   c            s   ˆ  j  d ƒ d  S(   Ns   Don't!(   t   fail(   t   thist   other(   R   (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   __eq__À  s    c            s   ˆ  j  d ƒ d  S(   Ns   Don't!(   R‡   (   Rˆ   R‰   (   R   (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   __ne__Ã  s    (   R)   R*   RŠ   R‹   (    (   R   (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyR†   ¿  s   s	   a messageR   R   RW   R   t   someRd   N(   R   R   R/   RJ   Rz   Ro   (   R   R†   RW   R%   (    (   R   s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt:   test_str_works_with_instances_having_overriden_eq_operator·  s    		(   R)   R*   Ri   Ru   Ry   R{   R~   R€   R‚   Rƒ   R…   R   (    (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyRb   &  s   		
							9t   TestHashablec           B   s   e  Z d  „  Z RS(   c         C   s0   t  t j d ƒ g ƒ t  t j d ƒ g ƒ d  S(   Nt    (   t   setR   R/   t   SchemaError(   R   (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   test_hashableÒ  s    (   R)   R*   R’   (    (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyRŽ   Ñ  s   (   t   unittestR    Rl   t
   jsonschemaR   R   t   jsonschema.compatR   R   R+   RB   Rb   RŽ   (    (    (    s?   lib/python2.7/site-packages/jsonschema/tests/test_exceptions.pyt   <module>   s   ›4O«