ó
LAêIc           @   sž   d  Z  d d l Z d d l m Z m Z m Z m Z d d l m Z m	 Z	 m
 Z
 d e j f d „  ƒ  YZ e d k rš e j d d	 ƒ Z e j d
 e ƒ n  d S(   s   Unittests for the Seq objects.iÿÿÿÿN(   t   generic_proteint   generic_nucleotidet   generic_dnat   generic_rna(   t   Seqt
   UnknownSeqt
   MutableSeqt   StringMethodTestsc           B   s
  e  Z e d  e ƒ e d  e ƒ e d  e ƒ e d e ƒ e d e ƒ e d e ƒ e d e ƒ e d e ƒ e d e ƒ e d e ƒ e d e ƒ e d e ƒ e d ƒ e d d d ƒe d e ƒ e d e d ƒ e d e d ƒ e d e d ƒ e d e d ƒ e d e d ƒ e d e d	 ƒ e d d d	 ƒe d ƒ g Z x4 e D]+ Z	 e
 e	 e ƒ r:e j e	 j ƒ  ƒ q:q:Wd
 d d d d d d g Z d e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   t	   ACGTGGGGTt	   ACGUGGGGUt   GGt   Ai   t	   charactert   nt   Ni
   t   Xi    i   iè  iÿÿÿÿiþÿÿÿiüÿÿc         C   sû  t  | t ƒ s t ‚ xß|  j D]Ô} t | | ƒ s: q n  t | ƒ } xª|  j D]Ÿ} t | | ƒ sk qP n  t | ƒ } t | | ƒ | ƒ } t | | ƒ | ƒ }	 | rÂ | | ƒ } | |	 ƒ }	 n  | |	 k rü t d t | ƒ | t | ƒ | |	 f ƒ ‚ n  y‰ t | | ƒ | ƒ } t | | ƒ | ƒ }	 | rJ| | ƒ } | |	 ƒ }	 n  | |	 k r„t d t | ƒ | t | ƒ | |	 f ƒ ‚ n  Wn t k
 r˜n X| rP xM|  j	 D]?}
 t | | ƒ | |
 ƒ } t | | ƒ | |
 ƒ }	 | r | | ƒ } | |	 ƒ }	 n  | |	 k r=t d t | ƒ | t | ƒ |
 | |	 f ƒ ‚ n  x¨ |  j	 D] } t | | ƒ | |
 | ƒ } t | | ƒ | |
 | ƒ }	 | r¤| | ƒ } | |	 ƒ }	 n  | |	 k rGt d t | ƒ | t | ƒ |
 | | |	 f ƒ ‚ qGqGWq©WqP qP Wq Wd S(   s4   Check this method matches the plain string's method.s   %s.%s(%s) = %i, not %is   %s.%s(%s, %i) = %i, not %is   %s.%s(%s, %i, %i) = %i, not %iN(
   t
   isinstancet   strt   AssertionErrort	   _examplest   hasattrt   getattrt
   ValueErrort   reprt	   TypeErrort   _start_end_values(   t   selft   method_namet   pre_comp_functiont	   start_endt   example1t   str1t   example2t   str2t   it   jt   startt   end(    (    s   test_Seq_objs.pyt   _test_method-   s„    								c         C   s   |  j  d d t ƒd S(   s-   Check matches the python string count method.t   countR   N(   R&   t   True(   R   (    (    s   test_Seq_objs.pyt
   test_countz   s    c         C   s   |  j  d d t ƒd S(   s,   Check matches the python string find method.t   findR   N(   R&   R(   (   R   (    (    s   test_Seq_objs.pyt	   test_find~   s    c         C   s   |  j  d d t ƒd S(   s-   Check matches the python string rfind method.t   rfindR   N(   R&   R(   (   R   (    (    s   test_Seq_objs.pyt
   test_rfind‚   s    c         C   s†  |  j  d d t ƒy |  j d j d ƒ ƒ Wn t k
 rA d SXx=|  j D]2} t | d ƒ sg qL n  t g  t d t	 | ƒ d	 d
 ƒ D] } | | | d	 !^ q‡ ƒ } t g  | D] } t
 | ƒ ^ q± ƒ } |  j t
 | ƒ j | ƒ | j | ƒ ƒ |  j t
 | ƒ j | ƒ | j | ƒ ƒ |  j t
 | ƒ j | d
 ƒ | j | d
 ƒ ƒ |  j t
 | ƒ j | d	 d ƒ | j | d	 d ƒ ƒ qL Wd S(   s2   Check matches the python string startswith method.t
   startswithR   t   ABCDEt   ABEt   OBEt   ABCNi    i   i   i   (   R0   R1   R2   (   R&   R(   t   assert_R.   R   R   R   t   tuplet   ranget   lenR   t   assertEqual(   R   R   R$   t   subst   st   subs_str(    (    s   test_Seq_objs.pyt   test_startswith†   s&    :%c         C   s†  |  j  d d t ƒy |  j d j d ƒ ƒ Wn t k
 rA d SXx=|  j D]2} t | d ƒ sg qL n  t g  t d t	 | ƒ d	 d
 ƒ D] } | | | d	 !^ q‡ ƒ } t g  | D] } t
 | ƒ ^ q± ƒ } |  j t
 | ƒ j | ƒ | j | ƒ ƒ |  j t
 | ƒ j | ƒ | j | ƒ ƒ |  j t
 | ƒ j | d
 ƒ | j | d
 ƒ ƒ |  j t
 | ƒ j | d	 d ƒ | j | d	 d ƒ ƒ qL Wd S(   s0   Check matches the python string endswith method.t   endswithR   R/   R0   R1   t   CDENi    i   i   i   (   R0   R1   R=   (   R&   R(   R3   R<   R   R   R   R4   R5   R6   R   R7   R.   (   R   R   R$   R8   R9   R:   (    (    s   test_Seq_objs.pyt   test_endswith¢   s&    :%c         C   s   |  j  d d t ƒd S(   s-   Check matches the python string strip method.t   stripR   N(   R&   R   (   R   (    (    s   test_Seq_objs.pyt
   test_strip¾   s    c         C   s   |  j  d d t ƒd S(   s.   Check matches the python string rstrip method.t   rstripR   N(   R&   R   (   R   (    (    s   test_Seq_objs.pyt   test_rstripÂ   s    c         C   s   |  j  d d d „  ƒd S(   s.   Check matches the python string rstrip method.RA   R   c         S   s   t  t |  ƒ S(   N(   t   mapR   (   t   x(    (    s   test_Seq_objs.pyt   <lambda>Ê   s    N(   R&   (   R   (    (    s   test_Seq_objs.pyt
   test_splitÆ   s    c         C   s   |  j  d d d „  ƒd S(   s.   Check matches the python string rstrip method.RA   R   c         S   s   t  t |  ƒ S(   N(   RC   R   (   RD   (    (    s   test_Seq_objs.pyRE   Ð   s    N(   R&   (   R   (    (    s   test_Seq_objs.pyt   test_rsplitÌ   s    c         C   s   |  j  d d d „  ƒd S(   s.   Check matches the python string rstrip method.RA   R   c         S   s   t  t |  ƒ S(   N(   RC   R   (   RD   (    (    s   test_Seq_objs.pyRE   Ö   s    N(   R&   (   R   (    (    s   test_Seq_objs.pyt   test_lsplitÒ   s    c         C   s@   x9 |  j  D]. } t | ƒ } |  j t | ƒ t | ƒ ƒ q
 Wd S(   s/   Check matches the python string __len__ method.N(   R   R   R7   R6   (   R   R   R   (    (    s   test_Seq_objs.pyt   test_lengthØ   s    c      
   C   su  xn|  j  D]c} t | ƒ } xN|  j D]C} t | ƒ t | ƒ k  re |  j t | | ƒ | | ƒ n  |  j t | |  ƒ | |  ƒ |  j t | | ƒ | | ƒ xÅ |  j D]º } |  j t | | | !ƒ | | | !ƒ x t d d ƒ D]| } | d k r1y# | | | | … GH|  j t ƒ Wqat	 k
 r-qaXqå |  j t | | | | … ƒ | | | | … ƒ qå Wq« Wq& Wq
 Wd S(   s/   Check slicing and indexing works like a string.iýÿÿÿi   i    N(
   R   R   R   t   absR6   R7   R5   t   _assertt   FalseR   (   R   R   R   R"   R#   t   step(    (    s   test_Seq_objs.pyt   test_getitemÞ   s$    !$c         C   s_   xX |  j  D]M } t | ƒ } |  j | j ƒ  | ƒ t | t ƒ s
 |  j | j | ƒ q
 q
 Wd S(   so   Check str(obj) and obj.tostring() match.

        Also check the obj.data attribute for non-MutableSeq objects.N(   R   R   R7   t   tostringR   R   t   data(   R   R   R   (    (    s   test_Seq_objs.pyt   test_tostringô   s
    N(   t   __name__t
   __module__R   R    R   R   R   R   R   t   seqR   t   appendt	   tomutableR   t   NoneRL   R&   R)   R+   R-   R;   R>   R@   RB   RF   RG   RH   RI   RN   RQ   (    (    (    s   test_Seq_objs.pyR      sR   	M												t   __main__t	   verbosityi   t
   testRunner(   t   __doc__t   unittestt   Bio.AlphabetR    R   R   R   t   Bio.SeqR   R   R   t   TestCaseR   RR   t   TextTestRunnert   runnert   main(    (    (    s   test_Seq_objs.pyt   <module>   s   "ó