ó
ù`]c           @  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m	 Z	 d  d l
 m Z d  d l m Z d  d l m Z m Z m Z e j d ƒ Z d e j f d	 „  ƒ  YZ e ƒ  Z d
 e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   print_functionN(   t   tolistt   anyp(   t   Plugin(   t   ContextList(   t   Doctestt   logt   DocFileCaset   ALLOW_UNICODEt   _UnicodeOutputCheckerc           B  s/   e  Z e j d  e j ƒ Z d „  Z d „  Z RS(   s   (\W|^)[uU]([rR]?[\'\"])c         C  s   t  j |  j d | ƒ S(   Ns   \1\2(   t   ret   subt   _literal_re(   t   selft   txt(    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyt   _remove_u_prefixes   s    c         C  sp   t  j j |  | | | ƒ } | r% t S| t @s3 t S|  j | ƒ } |  j | ƒ } t  j j |  | | | ƒ } | S(   N(   t   doctestt   OutputCheckert   check_outputt   TrueR   t   FalseR   (   R   t   wantt   gott   optionflagst   rest   cleaned_wantt   cleaned_got(    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyR      s    
	(   t   __name__t
   __module__R
   t   compilet   UNICODER   R   R   (    (    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyR	      s   	t   DoctestPluginHelperc           B  sA   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s+  
    This mixin adds print_function future import to all test cases.

    It also adds support for:
        '#doctest +ALLOW_UNICODE' option that
        makes DocTestCase think u'foo' == 'foo'.

        '#doctest doctestencoding=utf-8' option that
        changes the encoding of doctest files
    t   doctestencodingc         c  s	  |  j  rt | j |  j  ƒ rt j j | ƒ } t j | d |  j j	 d ƒ ƒ } z | j
 ƒ  } Wd  | j ƒ  Xd  } i | d 6} |  j rZt j j | ƒ \ } } t j j | ƒ }	 t j j |	 ƒ | |  j }
 y" t |
 t ƒ  t ƒ  d g ƒ } Wn, t k
 r"} t j d |
 | t j ƒ n Xt j d |
 | ƒ t | d ƒ rZ| j | ƒ } qZn  t j ƒ  } | j | d | d | d	 | d
 d ƒ} | j rýt | d |  j d t  | d d  ƒ d t  | d d  ƒ d |  j! ƒ} | rõt" | f d | ƒVq| Vqt# Vn  d  S(   Nt   rR    t   __file__t   nops   Could not import %s: %s (%s)s    Fixture module %s resolved to %st   globst   namet   filenamet   linenoi    R   t   setUpt
   setup_testt   tearDownt   teardown_testt
   result_vart   context($   t	   extensionR   t   endswitht   ost   patht   basenamet   codecst   opent   optionst   gett   readt   closet   Nonet   fixturest   splitextt   dirnamet   syst   appendt
   __import__t   globalst   localst   ImportErrorR   t   debugt   hasattrR$   R   t   DocTestParsert   get_doctestt   examplesR   R   t   getattrt   doctest_result_varR   R   (   R   R&   R%   t   dht   doct   fixture_contextR$   t   baset   extR<   t   fixt_modt   et   parsert   testt   case(    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyt   loadTestsFromFileUnicode7   sD    !	"!		c         c  sq   |  j  | ƒ } x[ | D]S } t | t ƒ r[ t g  | D] } |  j | ƒ ^ q5 | j ƒ Vq |  j | ƒ Vq Wd  S(   N(   RT   t
   isinstanceR   t   _patchTestCaseR-   (   R   R&   t   casesRS   t   c(    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyt   loadTestsFromFilea   s
    0c         c  si   xb t  t |  ƒ j | ƒ D]H } g  | j ƒ  D] } |  j | ƒ ^ q, } |  j | d | d t ƒVq Wd S(   s'   Load doctests from the module.
        R-   t	   can_splitN(   t   superR   t   loadTestsFromModulet
   _get_testsRV   t
   suiteClassR   (   R   t   modulet   suiteRS   RW   (    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyR\   k   s    (c         C  s&   | r" t  | j j d <t | _ n  | S(   NR    (   R    t   _dt_testR$   t   _checkert   _dt_checker(   R   RS   (    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyRV   r   s    c         C  s¨  t  j |  | | ƒ | j |  _ | j |  _ t | j ƒ |  _ | j |  _ t	 j
 ƒ  |  _ d |  _ i  |  _ | j r¤d j | j ƒ j d ƒ } x| D]} y» | j d ƒ rÍ |  j t	 j | d O_ w• n0 | j d ƒ rý |  j t	 j | d M_ w• n  y | j d ƒ \ } } Wn t k
 r)n, X| |  j k rEt ƒ  ‚ n  | |  j | <w• Wn/ t t t f k
 r‡t d j | ƒ ƒ ‚ q• Xt d j | ƒ ƒ ‚ q• Wn  d  S(	   Ni    t   ,t   +i   t   -t   =s   Unknown doctest option {}s5   Doctest option is not a flag or a key/value pair: {} (   R   t	   configureRI   t   doctest_testsR   t   doctestExtensionR.   t   doctestFixturesR:   R   t   DocTestFindert   finderR   R5   t   doctestOptionst   joint   splitt
   startswitht   OPTIONFLAGS_BY_NAMEt
   ValueErrort   OPTION_BY_NAMEt   AttributeErrort   KeyErrort   format(   R   R5   t   configt
   stroptionst	   stroptiont   keyt   value(    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyRh   x   s>    			(   R    (	   R   R   t   __doc__Rt   RT   RY   R\   RV   Rh   (    (    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyR   )   s   
	*	
		t
   DoctestFixc           B  s   e  Z RS(    (   R   R   (    (    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyR~   £   s   (   t
   __future__R    R
   R=   R0   R3   R   t	   nose.utilR   R   t   nose.plugins.baseR   t
   nose.suiteR   t   nose.plugins.doctestsR   R   R   t   register_optionflagR   R   R	   Rb   t   objectR   R~   (    (    (    s<   lib/python2.7/site-packages/nltk/test/doctest_nose_plugin.pyt   <module>   s   	z