ó
ˆ5„Oc           @   su   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d „  Z d „  Z d e  j f d „  ƒ  YZ	 e  j
 ƒ  d S(   iÿÿÿÿNc         C   s   t  j |  ƒ d S(   s   Test thread to just wait a bit.N(   t   timet   sleep(   t   seconds(    (    s,   /usr/share/apport/testsuite/test_rethread.pyt   idle   s    c         C   s   |  | S(   s"   Test thread to divide two numbers.(    (   t   xt   y(    (    s,   /usr/share/apport/testsuite/test_rethread.pyt   div
   s    t   Tc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   si   t  j j d t d d ƒ } | j ƒ  | j ƒ  | j ƒ  |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ d S(   s   return value works properly.t   targett   argsi*   i   i   N(   i*   i   (
   t   apportt   REThreadR   t   startt   joint	   exc_raiset   assertEqualt   return_valuet   exc_infot   None(   t   selft   t(    (    s,   /usr/share/apport/testsuite/test_rethread.pyt   test_return_value   s    


c         C   sr   t  j j d t d d ƒ } | j ƒ  |  j t | j ƒ | j ƒ  |  j | j ƒ  d ƒ |  j | j
 ƒ  d ƒ d S(   sA   apport.REThread.REThread works if run() does not return anything.R   R	   g      à?N(   g      à?(   R
   R   R   R   t   assertRaisest   AssertionErrorR   R   R   R   R   (   R   R   (    (    s,   /usr/share/apport/testsuite/test_rethread.pyt   test_no_return_value   s    

c         C   s×   t  j j d t d d ƒ } | j ƒ  | j ƒ  |  j t | j ƒ |  j | j	 ƒ  d t
 k ƒ t j | j	 ƒ  d | j	 ƒ  d | j	 ƒ  d ƒ } |  j | d j d ƒ d t | ƒ ƒ |  j | d	 j d
 ƒ ƒ d S(   s)   exception in thread is caught and passed.R   R	   i   i    i   iÿÿÿÿt   ZeroDivisionErrors   not a ZeroDivisionError:iþÿÿÿs   return x / y
N(   i   i    (   R
   R   R   R   R   R   R   R   t
   assertTrueR   R   t	   tracebackt   format_exceptiont
   startswitht   strt   endswith(   R   R   t   exc(    (    s,   /usr/share/apport/testsuite/test_rethread.pyt   test_exception&   s    

 'c         C   så   t  j j d t d d ƒ } | j ƒ  | j ƒ  |  j t | j ƒ t } y | j	 ƒ  Wn{ t
 } t j ƒ  } t j | d | d | d ƒ } |  j | d j d ƒ d t | ƒ ƒ |  j | d	 j d
 ƒ ƒ n X|  j | ƒ d S(   s+   exc_raise() raises caught thread exception.R   R	   i   i    i   iÿÿÿÿR   s   not a ZeroDivisionError:iþÿÿÿs   return x / y
N(   i   i    (   R
   R   R   R   R   R   R   R   t   FalseR   t   Truet   sysR   R   R   R   R   R   R   (   R   R   t   raisedt   eR    (    (    s,   /usr/share/apport/testsuite/test_rethread.pyt   test_exc_raise4   s    

!'(   t   __name__t
   __module__R   R   R!   R'   (    (    (    s,   /usr/share/apport/testsuite/test_rethread.pyR      s   			(   t   unittestR    R   R$   t   apport.REThreadR
   R   R   t   TestCaseR   t   main(    (    (    s,   /usr/share/apport/testsuite/test_rethread.pyt   <module>   s
   0		8