
    }e                         d Z ddlZddlZddlZddlmZ ddlmZ ddlm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  e ej*                               Zedz  Zedz  Zd Zd Z G d de      Zd Zd Zd Zy)a  Tests for profile-related functions.

Currently only the startup-dir functionality is tested, but more tests should
be added for:

    * ipython profile create
    * ipython profile list
    * ipython profile create --parallel
    * security dir permissions

Authors
-------

* MinRK

    N)Path)TestCase)TemporaryDirectory)list_bundled_profileslist_profiles_in)
ProfileDir)
decorators)tools)	getoutputhome_test_dirz.ipythonc                  Z    t        j                         t        z  j                  d       y)zSSetup test environment for the module:

            - Adds dummy home dir tree
    TparentsN)r   cwdIP_TEST_DIRmkdir     A/usr/lib/python3/dist-packages/IPython/core/tests/test_profile.pysetup_moduler   0   s      
XXZ+$$T$2r   c                  6    t        j                  t               y)zXTeardown test environment for the module:

            - Remove dummy home dir tree
    N)shutilrmtreeTMP_TEST_DIRr   r   r   teardown_moduler   :   s     MM,r   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)ProfileStartupTestc                 |    t        j                  t        d      | _        dt        ddg| _        t
        dz  | _        y )Ntestz--ipython-dirz	--profileztest.py)r   create_profile_dir_by_namer   pdoptionsr   fnameselfs    r   setUpzProfileStartupTest.setUpI   s2    77VL'k6J!I-
r   c                 V    t        j                  | j                  j                         y N)r   r   r!   locationr$   s    r   tearDownzProfileStartupTest.tearDownO   s     	dgg&&'r   c                 (   t        t        | j                  j                        |z  dd      5 }|j	                  |       d d d        t        | j
                  dd      5 }|j	                  |       d d d        y # 1 sw Y   <xY w# 1 sw Y   y xY w)Nwutf-8encoding)openr   r!   startup_dirwriter#   )r%   startup_filestartupr   fs        r   initzProfileStartupTest.initT   s    $tww**+l:C'R 	VWGGG	 $**cG4 	GGDM	 		 		 	s   A<!B<BBc                 ^    t        j                  | j                  |d| j                         y )N )r"   )ttipexec_validater#   r"   )r%   outputs     r   validatezProfileStartupTest.validate\   s    
4::vr4<<Hr   c                 L    | j                  ddd       | j                  d       y )Nz00-start.pyzzzz=123
zprint(zzz)
123r6   r<   r$   s    r   test_startup_pyz"ProfileStartupTest.test_startup_py_   s    		-n=er   c                 L    | j                  ddd       | j                  d       y )Nz00-start.ipyz%xmode plain
r8   zException reporting mode: Plainr?   r$   s    r   test_startup_ipyz#ProfileStartupTest.test_startup_ipyc   s     		."2B778r   N)	__name__
__module____qualname__r&   r*   r6   r<   r@   rB   r   r   r   r   r   H   s!    .(
I9r   r   c                  `   t        t        j                  t                    } dD ]   }t        | |z        j	                  d       " t
        j                  rt        | dz        j	                  d       t        | dz  dd	      5 }|j                  d
       d d d        t        |       }d}t        |      D ]>  }|j                  d      st        j                  | |      }|j                  |       d} n t
        j                  r|du sJ t        |      ddhk(  sJ y # 1 sw Y   xY w)N)dir)profile_fooprofile_hellonot_a_profileTr   u   profile_ünicodeprofile_filer,   r-   r.   zI am not a profile directoryFnicodefoohello)r   tempfilemkdtempr   r   decunicode_pathsr0   r2   r   listendswithr   find_profile_dir_by_nameremoveset)tdnamer5   profilesfound_unicodepr!   s          r   test_list_profiles_inr]   h   s!    
h<0	1BA ,R$Yd+,
R$$%++D+9	b>!3	9 0Q	./0#H
 M(^ ::h44R;BOOA M $$$x=UG,,,,!0 0s   D$$D-c                  8    t        t                     } | g k(  sJ y r(   )sortedr   )bundleds    r   test_list_bundled_profilesra      s    *,-Gb==r   c                     t               5 } t        t        j                  dddddd| z  g       t	        |       dz  }t	        |      j                         sJ |dz  }t	        |      j                         sJ 	 d	d	d	       y	# 1 sw Y   y	xY w)
z-ipython profile create respects --ipython-dirz-mIPythonprofilecreaterM   z--ipython-dir=%srH   zipython_config.pyN)r   r   sys
executabler   exists)rX   profile_diripython_configs      r   test_profile_create_ipython_dirrk      s    		 -"R'
	
 2h.K '')))$'::N#**,,,- - -s   A-BB)__doc__r   rf   rO   pathlibr   unittestr   r   IPython.core.profileappr   r   IPython.core.profiledirr   IPython.testingr	   rQ   r
   r9   IPython.utils.processr   rP   r   HOME_TEST_DIRr   r   r   r   r]   ra   rk   r   r   r   <module>rt      s   *  
    ' K . - ' +
 $H$$&'.j(3 9 9@-8-r   