ó
‡ˆ\c           @   s   d  Z  d d l Z d d l Z d d l Z d „  Z d d d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e j f d „  ƒ  YZ d S(   sJ  
This is a backport of assertRaises() and assertRaisesRegex from Python 3.5.4

The original copyright message is as follows

Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's
Smalltalk testing framework (used with permission).

This module contains the core framework classes that form the basis of
specific test cases and suites (TestCase, TestSuite etc.), and also a
text-based utility class for running the tests and reporting the results
 (TextTestRunner).

Simple usage:

    import unittest

    class IntegerArithmeticTestCase(unittest.TestCase):
        def testAdd(self):  # test method names begin with 'test'
            self.assertEqual((1 + 2), 3)
            self.assertEqual(0 + 1, 1)
        def testMultiply(self):
            self.assertEqual((0 * 10), 0)
            self.assertEqual((5 * 8), 40)

    if __name__ == '__main__':
        unittest.main()

Further information is available in the bundled documentation, and from

  https://docs.python.org/library/unittest.html

Copyright (c) 1999-2003 Steve Purcell
Copyright (c) 2003-2010 Python Software Foundation
This module is free software, and you may redistribute it and/or modify
it under the same terms as Python itself, so long as this copyright message
and disclaimer are retained in their original form.

IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
iÿÿÿÿNc            sE   t  |  t ƒ r) t ‡  f d †  |  Dƒ ƒ St  |  t ƒ oD t |  ˆ  ƒ S(   Nc         3   s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   t   _is_subtype(   t   .0t   e(   t   basetype(    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pys	   <genexpr>:   s    (   t
   isinstancet   tuplet   allt   typet
   issubclass(   t   expectedR   (    (   R   s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyR    8   s    t   _BaseTestCaseContextc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t	   test_case(   t   selfR   (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyt   __init__@   s    c         C   s.   |  j  j |  j | ƒ } |  j  j | ƒ ‚ d  S(   N(   R   t   _formatMessaget   msgt   failureException(   R   t   standardMsgR   (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyt   _raiseFailureC   s    (   t   __name__t
   __module__R   R   (    (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyR
   >   s   	t   _AssertRaisesBaseContextc           B   s   e  Z d d  „ Z d „  Z RS(   c         C   s_   t  j |  | ƒ | |  _ | |  _ | d  k	 r@ t j | ƒ } n  | |  _ d  |  _ d  |  _	 d  S(   N(
   R
   R   R	   R   t   Nonet   ret   compilet   expected_regext   obj_nameR   (   R   R	   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyR   J   s    				c         C   s"  zt  |  j |  j ƒ s4 t d | |  j f ƒ ‚ n  | rf | d d k rf t j d t d ƒ d	 } n  | s± | j	 d d ƒ |  _
 | r­ t j d t t | ƒ ƒ t d ƒ n  |  S| d | d } } y | j |  _ Wn  t k
 rø t | ƒ |  _ n X|   | | | Ž  Wd QXWd d }  Xd S(
   sî   
        If args is empty, assertRaises/Warns is being used as a
        context manager, so check for a 'msg' kwarg and return self.
        If args is not empty, call a callable passing positional and keyword
        arguments.
        s   %s() arg 1 must be %si    s   callable is Nonei   R   s3   %r is an invalid keyword argument for this functioni   N(    (   R    R	   t
   _base_typet	   TypeErrort   _base_type_strR   t   warningst   warnt   DeprecationWarningt   popR   t   nextt   iterR   R   t   AttributeErrort   str(   R   t   namet   argst   kwargst   callable_obj(    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyt   handleT   s.    	
		N(   R   R   R   R   R*   (    (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyR   H   s   
t   _AssertRaisesContextc           B   s,   e  Z d  Z e Z d Z d „  Z d „  Z RS(   sC   A context manager used to implement TestCase.assertRaises* methods.s-   an exception type or tuple of exception typesc         C   s   |  S(   N(    (   R   (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyt	   __enter__}   s    c         C   sð   | d  k r€ y |  j j } Wn  t k
 r> t |  j ƒ } n X|  j rg |  j d j | |  j ƒ ƒ q€ |  j d j | ƒ ƒ n  t | |  j ƒ s– t	 S|  j
 d  k r© t S|  j
 } | j t | ƒ ƒ sì |  j d j | j t | ƒ ƒ ƒ n  t S(   Ns   {} not raised by {}s   {} not raiseds   "{}" does not match "{}"(   R   R	   R   R$   R%   R   R   t   formatR   t   FalseR   t   Truet   searcht   pattern(   R   t   exc_typet	   exc_valuet   tbt   exc_nameR   (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyt   __exit__€   s$    		(   R   R   t   __doc__t   BaseExceptionR   R   R,   R6   (    (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyR+   w   s
   	t   TestCasec           B   s/   e  Z e Z e Z d  „  Z d „  Z d „  Z RS(   c         C   sX   |  j  s | p | S| d k r# | Sy d | | f SWn t k
 rS d | | f SXd S(   s~  Honour the longMessage attribute when generating failure messages.
        If longMessage is False this means:
        * Use only an explicit message if it is provided
        * Otherwise use the standard message for the assert

        If longMessage is True:
        * Use the standard message
        * If an explicit message is provided, plus ' : ' and the explicit msg
        s   %s : %sN(   t   longMessageR   t   UnicodeDecodeError(   R   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyR   ›   s    
	
c         O   s4   t  | |  ƒ } z | j d | | ƒ SWd d } Xd S(   s=  Fail unless an exception of class expected_exception is raised
           by the callable when invoked with specified positional and
           keyword arguments. If a different type of exception is
           raised, it will not be caught, and the test case will be
           deemed to have suffered an error, exactly as for an
           unexpected exception.

           If called with the callable and arguments omitted, will return a
           context object used like this::

                with self.assertRaises(SomeException):
                    do_something()

           An optional keyword argument 'msg' can be provided when assertRaises
           is used as a context object.

           The context manager keeps a reference to the exception as
           the 'exception' attribute. This allows you to inspect the
           exception after the assertion::

               with self.assertRaises(SomeException) as cm:
                   do_something()
               the_exception = cm.exception
               self.assertEqual(the_exception.error_code, 3)
        t   assertRaisesN(   R+   R*   R   (   R   t   expected_exceptionR'   R(   t   context(    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyR<   °   s    c         O   s%   t  | |  | ƒ } | j d | | ƒ S(   s  Asserts that the message in a raised exception matches a regex.

        Args:
            expected_exception: Exception class expected to be raised.
            expected_regex: Regex (re pattern object or string) expected
                    to be found in error message.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
            msg: Optional message used in case of failure. Can only be used
                    when assertRaisesRegex is used as a context manager.
        t   assertRaisesRegex(   R+   R*   (   R   R=   R   R'   R(   R>   (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyR?   Ñ   s    (	   R   R   R/   R:   t   AssertionErrorR   R   R<   R?   (    (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyR9   —   s
   		!(    (	   R7   R   R   t   unittestR    R
   R   R+   R9   (    (    (    s?   lib/python2.7/site-packages/sklearn/utils/_unittest_backport.pyt   <module>1   s   	
/ 