ó
"ˆIc           @   s¨   d  d l  Z  d  d l Z d  d l m Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ e d	 k r¤ e j	 d
 d ƒ Z
 e j d e
 ƒ n  d S(   iÿÿÿÿN(   t   GenePopt
   RecordTestc           B   s   e  Z d  „  Z RS(   c         C   s|   t  j ƒ  } t | j ƒ t k s' t ‚ t | j ƒ t k sB t ‚ t | j ƒ t	 k s] t ‚ t | j
 ƒ t	 k sx t ‚ d S(   s   Basic test on Record
        N(   R    t   Recordt   typet
   marker_lent   intt   AssertionErrort   comment_linet   strt	   loci_listt   listt   populations(   t   selft   r(    (    s   test_PopGen_GenePop.pyt   test_record_basic   s
    (   t   __name__t
   __module__R   (    (    (    s   test_PopGen_GenePop.pyR      s   t
   ParserTestc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   sÐ   d d d d g } g  |  _  x3 | D]+ } |  j  j t t j j d | ƒ ƒ ƒ q" Wd d d d g f d d d d g f d d d d g f d d d d g f g |  _ d d d d g |  _ d	 d d	 d g |  _ d  S(
   Ns
   c2line.gens
   c3line.gens   c2space.gens   c3space.gent   PopGeni   i   i   i   (	   t   handlest   appendt   opent   ost   patht   joint   pops_indivst   num_lociR   (   R   t   filest   filename(    (    s   test_PopGen_GenePop.pyt   setUp   s    	)c         C   s"   x |  j  D] } | j ƒ  q
 Wd  S(   N(   R   t   close(   R   t   handle(    (    s   test_PopGen_GenePop.pyt   tearDown'   s    c         C   s  xt  t |  j ƒ ƒ D]î } |  j | } t j | ƒ } t | t j ƒ sP t ‚ t | j ƒ |  j	 | k sr t ‚ | j
 |  j
 | k sŽ t ‚ t | j ƒ |  j | d k s´ t ‚ xM t  |  j | d ƒ D]4 } t | j | ƒ |  j | d | k sÌ t ‚ qÌ Wq Wd S(   s.   Basic operation of the Record Parser.
        i    i   N(   t   ranget   lenR   R    t   parset
   isinstanceR   R   R	   R   R   R   R   (   R   t   indexR   t   rect   i(    (    s   test_PopGen_GenePop.pyt   test_record_parser+   s    "&c         C   s\   t  t j j d d ƒ ƒ } y t j | ƒ } t d ƒ ‚ Wn t k
 rM n X| j ƒ  d S(   sA   Testing the ability to deal with wrongly formatted files
        R   t   fdist1s   Should have raised exceptionN(	   R   R   R   R   R    R#   t   Errort
   ValueErrorR   (   R   t   fR&   (    (    s   test_PopGen_GenePop.pyt   test_wrong_file_parser9   s    (   R   R   R   R    R(   R-   (    (    (    s   test_PopGen_GenePop.pyR      s   			t	   UtilsTestc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   sL   d g } g  |  _  x3 | D]+ } |  j  j t t j j d | ƒ ƒ ƒ q Wd  S(   Ns
   c2line.genR   (   R   R   R   R   R   R   (   R   R   R   (    (    s   test_PopGen_GenePop.pyR   E   s    		c         C   s"   x |  j  D] } | j ƒ  q
 Wd  S(   N(   R   R   (   R   R   (    (    s   test_PopGen_GenePop.pyR    M   s    c         C   s  x9 t  t |  j ƒ ƒ D]" } |  j | } t j | ƒ } q Wt | j ƒ } t | j ƒ } | j d } | j d ƒ t | j ƒ | d k s“ t ‚ | j	 | ƒ t | j ƒ | d k s¿ t ‚ | j d | k sØ t ‚ | j
 d ƒ t | j ƒ | d k st ‚ d S(   s*   Basic operation of GenePop Utils.
        i    i   i   N(   R!   R"   R   R    R#   R   R	   t   remove_populationR   t   remove_locus_by_namet   remove_locus_by_position(   R   R%   R   R&   t   initial_popst   initial_locit
   first_loci(    (    s   test_PopGen_GenePop.pyt
   test_utilsQ   s    (   R   R   R   R    R5   (    (    (    s   test_PopGen_GenePop.pyR.   D   s   		t   __main__t	   verbosityi   t
   testRunner(   R   t   unittestt
   Bio.PopGenR    t   TestCaseR   R   R.   R   t   TextTestRunnert   runnert   main(    (    (    s   test_PopGen_GenePop.pyt   <module>   s   -