ó
[³XMc        	   @   s¸   d  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
 d d l m Z d Z d	 Z d d d d d d d d d
 „ Z d „  Z d e f d „  ƒ  YZ d S(   s'   
Tests for L{twisted.scripts.tap2rpm}.
iÿÿÿÿN(   t   TestCaset   SkipTest(   t	   procutils(   t   Failure(   t   utils(   t   tap2rpms   s   c   
      C   s"  g  } |  s; d }  t  |  d ƒ }	 |	 j d ƒ |	 j ƒ  n  | j d d |  g ƒ | rm | j d | g ƒ n  | r‰ | j d | g ƒ n  | r¥ | j d | g ƒ n  | rÁ | j d	 | g ƒ n  | rÝ | j d
 | g ƒ n  | rù | j d | g ƒ n  | r| j d | g ƒ n  t j | ƒ S(   sF   
    Helper function to invoke tap2rpm with the given parameters.
    s   dummy-tap-filet   ws   # Dummy TAP file
s   --quiets	   --tapfiles   --maintainers
   --protocols   --descriptions   --long_descriptions   --set-versions	   --rpmfiles   --type(   t   opent   writet   closet   extendR   t   run(
   t   tapfilet
   maintainert   protocolt   descriptiont   longDescriptiont
   setVersiont   rpmfilet   type_t   argst   handle(    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt	   _makeRPMs   s,    c            sy   t  j g  ˆ  D] } d | t f ^ q ƒ } ‡  f d †  } d „  } t j d d d | d |  f ƒ } | j | | ƒ | S(   s  
    Helper function to read the given header tags from the given RPM file.

    Returns a Deferred that fires with dictionary mapping a tag name to a list
    of the associated values in the RPM header. If a tag has only a single
    value in the header (like NAME or VERSION), it will be returned as a 1-item
    list.

    Run "rpm --querytags" to see what tags can be queried.
    s
   [%%{%s}%s]c            sU   i  } xH t  ˆ  |  j t ƒ ƒ D]. \ } } | j t ƒ j t ƒ } | | | <q W| S(   N(   t   zipt   splitt   RECORD_SEPARATORt   stript   UNIT_SEPARATOR(   t   outputt   rest   tagt   values(   t   taglist(    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   parseTagValuesK   s
    %c            sf   |  j  t ƒ t |  j ƒ j d ƒ r: t t d ƒ ƒ ‰  n |  ‰  |  j j } | j ‡  f d †  ƒ | S(   Ns   got stderr: 'error: sR   rpm is missing its package database. Run 'sudo rpm -qa > /dev/null' to create one.c            s   ˆ  S(   N(    (   t   _(   t
   newFailure(    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   <lambda>o   s    (	   t   trapt   IOErrort   strt   valuet
   startswithR   R   t   processEndedt   addBoth(   t   failuret   d(    (   R#   sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   checkErrorResultT   s    t   rpms   -qs   --queryformats   -p(   R   t   joinR   R   t   getProcessOutputt   addCallbacks(   R   R    R   t   queryFormatR!   R.   R-   (    (   R    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   _queryRPMTags8   s    &			t   TestTap2RPMc           B   s’   e  Z d  „  Z d „  Z d 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(   c         C   s
   |  j  ƒ  S(   N(   t   _checkForRpmbuild(   t   self(    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   setUp|   s    c         C   s"   t  j d ƒ s t d ƒ ‚ n  d S(   sS   
        tap2rpm requires rpmbuild; skip tests if rpmbuild is not present.
        t   rpmbuilds(   rpmbuild must be present to test tap2rpmN(   R   t   whichR   (   R7   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyR6   €   s    t   dummyc         C   s4   | d } t  | d ƒ } | j d ƒ | j ƒ  | S(   sK   
        Make a temporary .tap file and returns the absolute path.
        s   .tapR   s   # Dummy .tap file(   R   R   R	   (   R7   t   basenamet   pathR   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   _makeTapFileˆ   s
    

c         K   s,   t  | | j ƒ  ƒ } | j |  j | ƒ | S(   sR   
        Check the given file has the given tags set to the given values.
        (   R4   t   keyst   addCallbackt   assertEquals(   R7   R   t   tagsR-   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   _verifyRPMTags“   s    c         C   sù   t  j ƒ  } | j g  ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d	 d
 ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d t ƒ |  j | d d ƒ |  j | d d ƒ d S(   s®   
        Commandline options should default to sensible values.

        "sensible" here is defined as "the same values that previous versions
        defaulted to".
        R   s
   twistd.tapR   R   R   t   twistdR   s   A TCP server for twistdt   long_descriptions    Automatically created by tap2rpms   set-versions   1.0R   s   twisted-twistdt   typet   tapt   quiett   twistd_optiont   files   release-names   twisted-twistd-1.0N(   R   t	   MyOptionst   parseOptionsRA   t   False(   R7   t   config(    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   test_optionDefaults   s    c         C   sK   t  j ƒ  } | j d d g ƒ |  j | d d ƒ |  j | d d ƒ d S(   sS   
        The protocol name defaults to a value based on the tapfile value.
        s	   --tapfiles   pancakes.tapR   R   t   pancakesN(   R   RK   RL   RA   (   R7   RN   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt"   test_protocolCalculatedFromTapFileµ   s    c         C   s  t  j ƒ  } | j d d d d g ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d	 d
 ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d t ƒ |  j | d d ƒ |  j | d d ƒ d S(   sT   
        Many options default to a value calculated from the protocol name.
        s	   --tapfiles   sausages.taps
   --protocolt   eggsR   R   R   R   R   s   A TCP server for eggsRE   s    Automatically created by tap2rpms   set-versions   1.0R   s   twisted-eggsRF   RG   RH   RI   RJ   s   release-names   twisted-eggs-1.0N(   R   RK   RL   RA   RM   (   R7   RN   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt"   test_optionsDefaultToProtocolValueÀ   s     c         C   s=   t  j ƒ  } | j d d d d g ƒ |  j | d d ƒ d S(   sU   
        The release-name option is calculated from rpmfile and set-version.
        s	   --rpmfilet   beanss   --set-versions   1.2.3s   release-names   beans-1.2.3N(   R   RK   RL   RA   (   R7   RN   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt&   test_releaseNameDefaultsToRpmfileValueØ   s
    c            sŽ   d ‰  t  d ˆ j ˆ  ƒ ƒ \ } ‰ ˆ j | d d ˆ  f g d d g d d g d	 d
 ˆ  f g d d g ƒ} | j ‡ ‡ ‡  f d †  ƒ | S(   sW   
        Calling tap2rpm should produce an RPM and SRPM with default metadata.
        t   frenchtoastR   t   NAMEs
   twisted-%st   VERSIONs   1.0t   RELEASEt   1t   SUMMARYs   A TCP server for %st   DESCRIPTIONs    Automatically created by tap2rpmc            sH   ˆ  j  ˆ d d ˆ f g d d g d d g d d ˆ f g d	 d
 g ƒS(   NRW   s
   twisted-%sRX   s   1.0RY   RZ   R[   s   A TCP server for %sR\   s    Automatically created by tap2rpm(   RC   (   R"   (   R7   t   srpmR<   (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyR$   ö   s
   		(   R   R>   RC   R@   (   R7   R/   R-   (    (   R<   R7   R]   sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   test_basicOperationå   s    		c            s   d } d ‰  t  d ˆ j | ƒ d ˆ  ƒ \ } ‰ ˆ j | d d ˆ  f g d d ˆ  f g ƒ} | j ‡ ‡  ‡ f d	 †  ƒ | S(
   sU   
        Setting 'protocol' should change the name of the resulting package.
        t   acornt   bananaR   R   RW   s
   twisted-%sR[   s   A TCP server for %sc            s-   ˆ  j  ˆ d d ˆ f g d d ˆ f g ƒS(   NRW   s
   twisted-%sR[   s   A TCP server for %s(   RC   (   R"   (   R7   R   R]   (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyR$     s   (   R   R>   RC   R@   (   R7   R<   R/   R-   (    (   R   R7   R]   sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   test_protocolOverride  s    c            s{   d ‰  d ‰ t  d ˆ j ˆ  ƒ d ˆ ƒ \ } ‰ ˆ j | d ˆ g d d ˆ  f g ƒ} | j ‡ ‡ ‡ ‡  f d †  ƒ | S(	   sT   
        Setting 'rpmfile' should change the name of the resulting package.
        t   cherryt   donutR   R   RW   R[   s   A TCP server for %sc            s&   ˆ  j  ˆ d ˆ g d d ˆ f g ƒS(   NRW   R[   s   A TCP server for %s(   RC   (   R"   (   R7   R   R]   R<   (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyR$   )  s   	(   R   R>   RC   R@   (   R7   R/   R-   (    (   R<   R7   R   R]   sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   test_rpmfileOverride  s    	c            s_   d ‰  t  d ˆ j ƒ  d ˆ  ƒ \ } ‰ ˆ j | d ˆ  g ƒ} | j ‡ ‡ ‡  f d †  ƒ | S(   sF   
        Setting 'description' should change the SUMMARY tag.
        t   eggplantR   R   R[   c            s   ˆ  j  ˆ d ˆ g ƒS(   NR[   (   RC   (   R"   (   R7   R]   R   (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyR$   ?  s   (   R   R>   RC   R@   (   R7   R/   R-   (    (   R   R7   R]   sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   test_descriptionOverride1  s    c            s_   d ‰ t  d ˆ  j ƒ  d ˆ ƒ \ } ‰ ˆ  j | d ˆ g ƒ} | j ‡  ‡ ‡ f d †  ƒ | S(   sN   
        Setting 'longDescription' should change the DESCRIPTION tag.
        t   figR   R   R\   c            s   ˆ  j  ˆ d ˆ g ƒS(   NR\   (   RC   (   R"   (   R7   R]   R   (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyR$   T  s   (   R   R>   RC   R@   (   R7   R/   R-   (    (   R7   R   R]   sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   test_longDescriptionOverrideF  s    c            se   d } t  d ˆ  j ƒ  d | ƒ \ } ‰ ˆ  j | d d g d d g ƒ} | j ‡  ‡ f d †  ƒ | S(   sL   
        Setting 'setVersion' should change the RPM's version info.
        s   123.456R   R   RX   RY   RZ   c            s   ˆ  j  ˆ d d g d d g ƒS(   NRX   s   123.456RY   RZ   (   RC   (   R"   (   R7   R]   (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyR$   j  s   	(   R   R>   RC   R@   (   R7   t   versionR/   R-   (    (   R7   R]   sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   test_setVersionOverride[  s    	c         C   sH   |  j  ƒ  } t j | ƒ |  j t j j | d ƒ ƒ } t d | ƒ d S(   sI   
        tap2rpm handles tapfiles outside the current directory.
        t   baconR   N(   t   mktempt   ost   mkdirR>   R=   R0   R   (   R7   t   tempdirR   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   test_tapInOtherDirectoryr  s    (   t   __name__t
   __module__R8   R6   R>   RC   RO   RQ   RS   RU   R^   Ra   Rd   Rf   Rh   Rj   Rp   (    (    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyR5   y   s   			
										(   t   __doc__Rm   t   twisted.trial.unittestR    R   t   twisted.pythonR   t   twisted.python.failureR   t   twisted.internetR   t   twisted.scriptsR   R   R   t   NoneR   R4   R5   (    (    (    sE   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_tap2rpm.pyt   <module>   s   !	A