ó
qxPXc           @   s“   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z
 d e  j f d „  ƒ  YZ e  j ƒ  d S(   iÿÿÿÿNt   Tc           B   s¼   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e j e j j j j e j ƒ  ƒ d k d	 ƒ d
 „  ƒ Z d „  Z d „  Z d „  Z e d „  ƒ Z RS(   c         C   s   t  j ƒ  |  _ d  S(   N(   t   tempfilet   mkdtempt   workdir(   t   self(    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   setUp   s    c         C   s   t  j |  j ƒ d  S(   N(   t   shutilt   rmtreeR   (   R   (    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   tearDown
   s    c         C   sD  d „  } | d ƒ } | d ƒ } |  j  d t j j d ƒ k ƒ |  j t j j d ƒ d ƒ |  j  d t j j | j ƒ k ƒ |  j  d t j j | j ƒ k ƒ t j ƒ  } | j d | j | j f j	 ƒ  ƒ | j
 ƒ  t j j | j ƒ } |  j d | k ƒ |  j  d | k ƒ |  j | j | k ƒ |  j  | j | k ƒ d S(	   s*   module licenses can be validated correctlyc         S   s|   t  j d d |  d d ƒ } | j d |  j ƒ  ƒ | j ƒ  t  j d d |  d d ƒ } t j d | j d | j g ƒ | S(	   Nt   prefixs   %s-t   suffixs   .Ss'   .section .modinfo
.string "license=%s"
s   .kos   /usr/bin/ass   -o(   R   t   NamedTemporaryFilet   writet   encodet   flusht
   subprocesst   callt   name(   t   licenset   asmt   ko(    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt	   _build_ko   s    	
	t   GPLt   BADt   isofss   does-not-existt   invalids   isofs
does-not-exist
%s
%s
N(   t
   assertTruet   apportt	   hookutilst   _get_module_licenset   assertEqualR   R   R   R   R   R   t   nonfree_kernel_modulest   assertFalse(   R   R   t   good_kot   bad_kot   ft   nonfree(    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_module_license_evaluation   s     	
	""	
c         C   sk   i  } t  j j | ƒ |  j | d j d ƒ ƒ |  j t | d ƒ d k ƒ |  j | d j d ƒ ƒ d S(   s7   attach_dmesg() does not overwrite already existing datat	   BootDmesgt   [iô  t   CurrentDmesgN(   R   R   t   attach_dmesgR   t
   startswitht   len(   R   t   report(    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_attach_dmesg4   s
    c         C   sŸ   i d d 6} t  j j | ƒ |  j | d d  d ƒ |  j | d j d ƒ ƒ i d d 6d d 6} t  j j | ƒ |  j | d d ƒ |  j | d d ƒ d S(   s7   attach_dmesg() does not overwrite already existing datat   existingbootR&   i2   R(   R'   t   existingcurrentN(   R   R   R)   R   R   R*   (   R   R,   (    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_dmesg_overwrite>   s    c         C   sò  t  d d ƒ  } | j ƒ  j ƒ  } Wd QXt  d d ƒ  } | j ƒ  j ƒ  } Wd QXi  } t j j | d ƒ |  j t | ƒ d g ƒ |  j | d | ƒ i  } t j j | d d ƒ |  j t | ƒ d g ƒ |  j | d | ƒ i  } t j j | d ƒ |  j t | ƒ d g ƒ |  j | d j	 d	 ƒ ƒ i  } t j j | d ƒ t j j | d ƒ |  j t | ƒ d g ƒ |  j | d | ƒ t j j | d d d
 t
 ƒ|  j t | j ƒ  ƒ d d g ƒ |  j | d | ƒ |  j | d | ƒ d S(   s   attach_file()s	   /etc/motdt   rbNs
   /etc/issues	   .etc.motdt   Motds   /nonexistings   .nonexistings   Error: t	   overwrites
   .etc.motd_(   t   opent   readt   stripR   R   t   attach_fileR   t   listR   R*   t   Falset   sortedt   keys(   R   R#   t   motd_contentst   issue_contentsR,   (    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_attach_fileM   s2    "c         C   sì   t  d d ƒ  } | j ƒ  j ƒ  } Wd QXi  } t j j | d ƒ |  j t | ƒ d g ƒ |  j | d | ƒ i  } t j j | d d ƒ |  j t | ƒ d g ƒ |  j | d | ƒ i  } t j j | d ƒ |  j t | ƒ g  ƒ d S(   s   attach_file_if_exists()s	   /etc/motdR1   Ns	   .etc.motdR2   s   /nonexisting(   R4   R5   R6   R   R   t   attach_file_if_existsR   R8   (   R   R#   R<   R,   (    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_attach_file_if_existss   s    c         C   s|   |  j  t j j d t j d ƒ ƒ d ƒ |  j  t j j t j d ƒ ƒ d ƒ |  j t t j j t j d ƒ ƒ ƒ d ƒ d S(   t   recent_logfiles   /nonexistingt   .t    t   ThisCantPossiblyHitAnythingi    N(	   R   R   R   RA   t   ret   compilet   recent_syslogt   assertNotEqualR+   (   R   (    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_recent_logfileŠ   s    (%c         C   s
  t  j j |  j d ƒ } t | d ƒ 7 } d } x' | d k rY | j d ƒ | d 8} q3 WWd QX|  j ƒ  } t j j	 | t
 j d ƒ ƒ } |  j ƒ  } | | } t j j d	 | ƒ |  j | d
 ƒ |  j | j d ƒ ƒ |  j t | ƒ d ƒ |  j t | ƒ d ƒ d S(   s   recent_logfile on a huge filet   syslogt   wi@B i    s/   Apr 20 11:30:00 komputer kernel: bogus message
i   Nt   kernels   [Î” %i kB] iˆ  i † (   t   ost   patht   joinR   R4   R   t   _get_mem_usageR   R   RA   RE   RF   t   syst   stderrt
   assertLessR   R*   t   assertGreaterR+   (   R   t   logR#   t   linest
   mem_beforet   datat	   mem_aftert   delta_kb(    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_recent_logfile_overflow‘   s    
s   no ConsoleKit sessionc         C   sN  t  j t  j ƒ } t  j t  j d ƒ i d d 6} |  j t j j | ƒ ƒ i d d 6} |  j t j j | ƒ ƒ i d d 6} |  j t j j | ƒ ƒ t  j t  j d ƒ i d d 6} |  j t j j | ƒ ƒ i d d 6} |  j t j j | ƒ ƒ t j	 ƒ  } |  j t j j | ƒ ƒ |  j
 t j j i  ƒ d ƒ t  j t  j | ƒ d S(   s   in_session_of_problem()t   Cs   Sat Jan  1 12:00:00 2011t   Dates   Mon Oct 10 21:06:03 2009s   Tue Jan  1 12:00:00 2211RC   N(   t   localet	   getlocalet   LC_TIMEt	   setlocaleR    R   R   t   in_session_of_problemR   t   ReportR   t   None(   R   t	   old_ctimeR,   (    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_in_session_of_problem¦   s"    c         C   sà  t  t j j |  j d ƒ d ƒ  } | j d ƒ Wd QXt j j d ƒ } zf|  j t j d <t j	 d ƒ } |  j
 t j j | ƒ d ƒ t j	 d ƒ } t j j | ƒ j ƒ  } |  j
 t | ƒ d	 ƒ |  j | d
 j d ƒ ƒ |  j | d j d ƒ ƒ t j j ƒ  } |  j d | k ƒ |  j d | k ƒ |  j d | k ƒ |  j d | k | ƒ |  j d | k | ƒ |  j d | k | ƒ |  j d | k | ƒ |  j d | k | ƒ Wd | d k	 rÎ| t j d <n t j d ƒ Xd S(   s   xsession_errors()s   .xsession-errorsRK   s&  Loading profile from /etc/profile
gnome-session[1948]: WARNING: standard glib warning
EggSMClient-CRITICAL **: egg_sm_client_set_mode: standard glib assertion
24/02/2012 11:14:46 Sending credentials s3kr1t

** WARNING **: nonstandard warning

WARN  2012-02-24 11:23:47 unity <unknown>:0 some unicode â™¥ â™ª

GNOME_KEYRING_CONTROL=/tmp/keyring-u7hrD6

(gnome-settings-daemon:5115): Gdk-WARNING **: The program 'gnome-settings-daemon' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
  (Details: serial 723 error_code 8 request_code 143 minor_code 22)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)"

GdkPixbuf-CRITICAL **: gdk_pixbuf_scale_simple: another standard glib assertion
Nt   HOMEt   notfoundRC   s   ^\w+-CRITICALi   i    s   EggSMClient-CRITICALi   s   GdkPixbuf-CRITICALs   nonstandard warningt   keyringt   credentialss   WARNING: standard glib warnings,   'gnome-settings-daemon' received an X Windowt   BadMatchs
   serial 723(   R4   RM   RN   RO   R   R   t   environt   getRE   RF   R   R   R   t   xsession_errorst
   splitlinesR+   R   R*   R    Rd   t   unsetenv(   R   R#   t	   orig_homet   patternt   res(    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_xsession_errorsÅ   s2    $c         C   s¹   i  } t  j j | ƒ t  j j | ƒ t  j j | ƒ t  j j | ƒ t  j j | ƒ t  j j | d ƒ t  j j | d ƒ t  j j | d ƒ t  j j | d ƒ t  j j | d ƒ d S(   s%   functions do not crash (very shallow)t   bashR   t   nonexistingN(	   R   R   t   attach_hardwaret   attach_alsat   attach_networkt   attach_wifit   attach_printingt   attach_conffilest   attach_upstart_overrides(   R   R,   (    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_no_crashesÿ   s    c         C   s  t  j j d ƒ } d t  j d <z] t j j d g ƒ } |  j d | k ƒ t j j d g d t ƒ} |  j d | k | ƒ Wd  | d  k	 r› | t  j d <n t  j
 d ƒ Xt j j d g ƒ } |  j | j d ƒ ƒ t j j d g d	 d
 ƒ} |  j | d
 ƒ d  S(   Nt   LC_MESSAGESs   en_US.UTF-8t   envs   LC_MESSAGES=Ct   keep_locales   /non existings   Error: [Errno 2]t   catt   inputt   hello(   RM   Rl   Rm   R   R   t   command_outputR   t   TrueR    Rd   Rp   R*   R   (   R   t   orig_lcmt   out(    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   test_command_output  s    c         C   sY   t  d ƒ G } x= | D]) } | j d ƒ r t | j ƒ  d ƒ Sq Wt d ƒ ‚ Wd QXd S(   s   Get current memory usage in kBs   /proc/self/statuss   VmSize:i   s)   did not find VmSize: in /proc/self/statusN(   R4   R*   t   intt   splitt   SystemError(   t   klassR#   t   line(    (    s-   /usr/share/apport/testsuite/test_hookutils.pyRP   '  s
    N(   t   __name__t
   __module__R   R   R%   R-   R0   R>   R@   RI   R[   t   unittestt   skipIfR   R   Rb   Rc   Rd   Rf   Rt   R~   R‰   t   classmethodRP   (    (    (    s-   /usr/share/apport/testsuite/test_hookutils.pyR       s   			'	
		&			9	:		(   R‘   R   R^   R   RE   R   t   os.pathRM   RQ   t   apport.hookutilsR   t   TestCaseR    t   main(    (    (    s-   /usr/share/apport/testsuite/test_hookutils.pyt   <module>   s   `ÿ -