ó
‹wÛjc           @   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 m Z m Z m	 Z	 d  d l
 m Z m Z m Z m Z m Z m Z d  d l m Z m Z m Z m Z d e  j f d „  ƒ  YZ d e  j f d „  ƒ  YZ d	 e  j f d
 „  ƒ  YZ d „  Z e d k re ƒ  n  d S(   iÿÿÿÿN(   t   verboset   run_unittestt   forget(   t   temp_dirt   make_scriptt   compile_scriptt   make_pkgt   make_zip_scriptt   make_zip_pkg(   t	   _run_codet   _run_module_codet
   run_modulet   run_patht   RunModuleCodeTestc           B   s2   e  Z d  Z d d g Z d Z d „  Z d „  Z RS(   s9   Unit tests for runpy._run_code and runpy._run_module_codes   Top level assignments   Lower level references§  # Check basic code execution
result = ['Top level assignment']
def f():
    result.append('Lower level reference')
f()
# Check the sys module
import sys
run_argv0 = sys.argv[0]
run_name_in_sys_modules = __name__ in sys.modules
if run_name_in_sys_modules:
   module_in_sys_modules = globals() is sys.modules[__name__].__dict__
# Check nested operation
import runpy
nested = runpy._run_module_code('x=1\n', mod_name='<run>')
c         C   sÅ   t  j d } t |  j i  ƒ } |  j | d |  j ƒ |  j | d d  ƒ |  j | d d  ƒ |  j | d d  ƒ |  j | d d  ƒ |  j | d | ƒ |  j d | ƒ |  j t  j d | ƒ d  S(	   Ni    t   resultt   __name__t   __file__t
   __loader__t   __package__t	   run_argv0t   run_name(	   t   syst   argvR	   t   test_sourcet   assertEqualt   expected_resultt   assertIst   Nonet   assertNotIn(   t   selft   saved_argv0t   d(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_run_code*   s    c   	      C   sb  t  ƒ  } d } d } d } d } t d | ƒ } t j d } t |  j | | | | | ƒ } |  j d | ƒ |  j | d | ƒ |  j | d |  j	 ƒ |  j | d d	 d
 ƒ |  j | d | ƒ |  j
 | d ƒ |  j
 | d ƒ |  j | d | ƒ |  j | d | ƒ |  j | d | ƒ |  j | d | ƒ |  j t j d | ƒ |  j | t j ƒ d  S(   Ns
   <Nonsense>s   Some other nonsenses   Now you're just being sillyt    t   initiali    R   t   nestedt   xi   R   t   run_name_in_sys_modulest   module_in_sys_modulesR   R   R   R   (   t   objectt   dictR   R   R
   R   R   R   R   R   t
   assertTruet   modules(	   R   R"   t   namet   filet   loadert   packaget   d1R   t   d2(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_run_module_code6   s4    			(   R   t
   __module__t   __doc__R   R   R    R1   (    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyR      s
   	t   RunModuleTestc           B   s›   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   Unit tests for runpy.run_modulec         C   s7   y t  | ƒ Wn t k
 r! n X|  j d | ƒ d  S(   Ns   Expected import error for (   R   t   ImportErrort   fail(   R   t   mod_name(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   expect_import_errorV   s
    c         C   s_   |  j  d ƒ |  j  d ƒ |  j  d ƒ |  j  d ƒ |  j  d ƒ |  j  d ƒ |  j  d ƒ d  S(   NR   s   sys.imp.erics   os.path.halfs   a.bees   .howards   ..eatent   multiprocessing(   R8   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_invalid_names^   s    c         C   s   t  d ƒ d  S(   Nt   runpy(   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_library_modulej   s    c         C   sJ   t  j | ƒ t  j j | d t  j d ƒ } t | d ƒ } | j ƒ  | S(   Nt   __init__t   pyt   w(   t   ost   mkdirt   patht   joint   extsept   opent   close(   R   t   pkg_dirt	   pkg_fnamet   pkg_file(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   _add_pkg_dirm   s
     
t
   runpy_testc         C   s0  d } | t  j d } t j ƒ  } } t r9 d G| GHn  t j j d | ƒ t re d Gt j d GHn  x\ t | ƒ D]N } t  j j	 | | ƒ } |  j
 | ƒ }	 t r® d G| GHn  t rr d G|	 GHqr qr Wt  j j	 | | ƒ }
 t |
 d ƒ } | j | ƒ | j ƒ  t rd G|
 GHn  | d	 | | } | |
 | f S(
   Nt   __runpy_pkg__R>   s     Package tree in:i    s     Updated sys.path:s     Next level in:s
     Created:R?   t   .(   R@   RD   t   tempfilet   mkdtempR    R   RB   t   insertt   rangeRC   RJ   RE   t   writeRF   (   R   t   sourcet   deptht   mod_baset   pkg_namet
   test_fnameRG   t   sub_dirt   iRH   t	   mod_fnamet   mod_fileR7   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt	   _make_pkgt   s.        
 c         C   s|  x3 t  t j ƒ D]" } | j d ƒ r t j | =q q Wt rD d GHn  t j d =t r\ d GHn  xÖ t j | d t ƒD]¿ \ } } } xR | D]J } y  t j	 t j j
 | | ƒ ƒ Wqˆ t k
 rÑ }	 t rÒ |	 GHqÒ qˆ Xqˆ WxX | D]P } t j j
 | | ƒ }
 y t j |
 ƒ WqÝ t k
 r,}	 t r-|	 GHq-qÝ XqÝ Wqr Wy t j | ƒ t rSd GHn  Wn! t k
 rw}	 t rx|	 GHqxn Xd  S(   NRL   s     Removed sys.modules entriesi    s     Removed sys.path entryt   topdowns     Removed package tree(   t   listR   R*   t
   startswithR    RB   R@   t   walkt   Falset   removeRC   t   OSErrort   rmdir(   R   t   topRT   R7   t   entryt   roott   dirst   filesR+   t   ext   fullname(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   _del_pkgˆ   s:     
 %     c         C   s  |  j  d | ƒ \ } } } t | ƒ z· t r: d G| GHn  t | ƒ } |  j d | ƒ |  j | d d k ƒ ~ t | ƒ t j | ƒ t	 j
 sÛ t r¢ d G| GHn  t | ƒ } |  j d | ƒ |  j | d d k ƒ ~ n  Wd  |  j | | | ƒ Xt rd GHn  d  S(   Ns   x=1
s   Running from source:R$   i   s   Running from compiled:s   Module executed successfully(   R\   R   R    R   t   assertInR)   t
   __import__R@   Rb   R   t   dont_write_bytecodeRl   (   R   RT   RG   RZ   R7   R/   R0   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   _check_module¡   s*    
 
	 
 c   	      C   s   |  j  d | d ƒ \ } } } | j d ƒ \ } } } t | ƒ z· t rU d G| GHn  t | ƒ } |  j d | ƒ |  j | d d k ƒ ~ t | ƒ t j	 | ƒ t
 j sö t r½ d G| GHn  t | ƒ } |  j d | ƒ |  j | d d k ƒ ~ n  Wd  |  j | | | ƒ Xt rd GHn  d  S(	   Ns   x=1
t   __main__RM   s   Running from source:R$   i   s   Running from compiled:s   Package executed successfully(   R\   t
   rpartitionR   R    R   Rm   R)   Rn   R@   Rb   R   Ro   Rl   (	   R   RT   RG   RZ   R7   RV   t   _R/   R0   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   _check_package·   s,    
 
	 
 c         C   s[  | d k r t  d ƒ ‚ n  d } | } x/ t | ƒ D]! } | } t j j | | ƒ } q4 Wt j j | d t j d ƒ } t | d ƒ }	 |	 j ƒ  t r¤ d G| GHn  t j j | d ƒ }
 |  j	 |
 ƒ t rØ d	 G|
 GHn  t j j |
 d
 ƒ } |  j	 | ƒ t rd G| GHn  t j j | d t j d ƒ } t | d ƒ } | j ƒ  t rWd G| GHn  d  S(   Ni   s$   Relative module test needs depth > 1RL   t   siblingR>   R?   s     Added sibling module:t   uncles     Added uncle package:t   cousins     Added cousin package:t   nephews     Added nephew module:(
   t
   ValueErrorRQ   R@   RB   RC   RD   RE   RF   R    RJ   (   R   t   base_dirRS   RT   RV   t
   module_dirRY   t
   parent_dirt   sibling_fnamet   sibling_filet	   uncle_dirt
   cousin_dirt   nephew_fnamet   nephew_file(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   _add_relative_modulesÎ   s2     
    
 c   
      C   ss  d } |  j  | | ƒ \ } } } z)|  j | | | ƒ | j d ƒ d } t r\ d G| GHn  t | d | ƒ} |  j d | ƒ |  j | d | k ƒ |  j d | ƒ |  j d | ƒ ~ t | ƒ t j	 | ƒ t
 j sIt rê d	 G| GHn  t | d | ƒ}	 |  j d |	 ƒ |  j |	 d | k ƒ |  j d |	 ƒ |  j d |	 ƒ ~	 n  Wd  |  j | | | ƒ Xt rod
 GHn  d  S(   Nsa   \
from __future__ import absolute_import
from . import sibling
from ..uncle.cousin import nephew
RM   i    s   Running from source:R   R   Ru   Rx   s   Running from compiled:s   Module executed successfully(   R\   Rƒ   Rr   R    R   Rm   R)   Rn   R@   Rb   R   Ro   Rl   (
   R   RT   R   t   contentsRG   RZ   R7   RV   R/   R0   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   _check_relative_importsç   s6     
	 
 c         C   s:   x3 t  d ƒ D]% } t r% d G| GHn  |  j | ƒ q Wd  S(   Ni   s   Testing package depth:(   RQ   R    Rp   (   R   RT   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_run_module  s     c         C   s=   x6 t  d d ƒ D]% } t r( d G| GHn  |  j | ƒ q Wd  S(   Ni   i   s   Testing package depth:(   RQ   R    Rt   (   R   RT   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_run_package  s     c         C   s#  t  t t t f } x
| D]} | j } d j | ƒ } |  j d d d ƒ } | \ } } } | j d d ƒ } z— t j	 j
 | d d ƒ }	 t |	 d ƒ � }
 |
 j | ƒ Wd  QXy t | ƒ Wn/ | k
 rì } d	 } |  j | t | ƒ ƒ n X|  j d
 j | ƒ ƒ Wd  |  j | d | ƒ Xq Wd  S(   Ns    raise {0}('{0} in __init__.py.')R!   i   Rq   s	   .__main__RL   s   __init__.pyt   wts   cannot be directly executeds   Nothing raised; expected {}(   R5   t   AttributeErrort	   TypeErrorRy   R   t   formatR\   t   replaceR@   RB   RC   RE   RR   R   R   R6   Rl   (   R   t
   exceptionst	   exceptionR+   RS   R   RG   Rs   R7   t   initR[   t   errt   msg(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt    test_run_package_init_exceptions  s$    	c         C   s=   x6 t  d d ƒ D]% } t r( d G| GHn  |  j | ƒ q Wd  S(   Ni   i   s"   Testing relative imports at depth:(   RQ   R    R…   (   R   RT   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_explicit_relative_import)  s     c         C   s@   x9 t  d d ƒ D]( } t r( d G| GHn  |  j | d ƒ q Wd  S(   Ni   i   s'   Testing main relative imports at depth:Rq   (   RQ   R    R…   (   R   RT   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_main_relative_import.  s     N(   R   R2   R3   R8   R:   R<   RJ   R\   Rl   Rp   Rt   Rƒ   R   R…   R†   R‡   R’   R“   R”   (    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyR4   S   s    								 				t   RunPathTestc           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 RS(   s   Unit tests for runpy.run_pathsX  # Script may be run with optimisation enabled, so don't rely on assert
# statements being executed
def assertEqual(lhs, rhs):
    if lhs != rhs:
        raise AssertionError('%r != %r' % (lhs, rhs))
def assertIs(lhs, rhs):
    if lhs is not rhs:
        raise AssertionError('%r is not %r' % (lhs, rhs))
# Check basic code execution
result = ['Top level assignment']
def f():
    result.append('Lower level reference')
f()
assertEqual(result, ['Top level assignment', 'Lower level reference'])
# Check the sys module
import sys
assertIs(globals(), sys.modules[__name__].__dict__)
argv0 = sys.argv[0]
c         C   s(   | d  k r |  j } n  t | | | ƒ S(   N(   R   R   R   (   R   t
   script_dirt   script_basenameRS   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   _make_test_scriptM  s    c         C   sp   t  | ƒ } |  j | d | ƒ |  j | d | ƒ |  j d | ƒ |  j | d | ƒ |  j | d | ƒ d  S(   NR   R   t   argv0R   (   R   R   Rm   (   R   t   script_namet   expected_namet   expected_filet   expected_argv0t   expected_packageR   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   _check_scriptR  s    c         C   s)   t  j | ƒ } |  j t | t | ƒ d  S(   N(   t   ret   escapet   assertRaisesRegexpR5   R   (   R   Rš   R‘   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   _check_import_error[  s    c      
   C   sG   t  ƒ  �8 } d } |  j | | ƒ } |  j | d | | d  ƒ Wd  QXd  S(   Nt   scripts
   <run_path>(   R   R˜   RŸ   R   (   R   R–   R7   Rš   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_basic_script_  s
    c      
   C   s`   t  ƒ  �Q } d } |  j | | ƒ } t | ƒ } t j | ƒ |  j | d | | d  ƒ Wd  QXd  S(   NR¤   s
   <run_path>(   R   R˜   R   R@   Rb   RŸ   R   (   R   R–   R7   Rš   t   compiled_name(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_script_compiledf  s    c      
   C   sG   t  ƒ  �8 } d } |  j | | ƒ } |  j | d | | d ƒ Wd  QXd  S(   NRq   s
   <run_path>R!   (   R   R˜   RŸ   (   R   R–   R7   Rš   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_directoryo  s
    c      
   C   s`   t  ƒ  �Q } d } |  j | | ƒ } t | ƒ } t j | ƒ |  j | d | | d ƒ Wd  QXd  S(   NRq   s
   <run_path>R!   (   R   R˜   R   R@   Rb   RŸ   (   R   R–   R7   Rš   R¦   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_directory_compiledv  s    c         C   sH   t  ƒ  �9 } d } |  j | | ƒ } d | } |  j | | ƒ Wd  QXd  S(   Nt   not_mains"   can't find '__main__' module in %r(   R   R˜   R£   (   R   R–   R7   Rš   R‘   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_directory_error  s
    
c      
   C   s_   t  ƒ  �P } d } |  j | | ƒ } t | d | ƒ \ } } |  j | d | | d ƒ Wd  QXd  S(   NRq   t   test_zips
   <run_path>R!   (   R   R˜   R   RŸ   (   R   R–   R7   Rš   t   zip_namet   fname(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_zipfile†  s
    c      
   C   sk   t  ƒ  �\ } d } |  j | | ƒ } t | ƒ } t | d | ƒ \ } } |  j | d | | d ƒ Wd  QXd  S(   NRq   R¬   s
   <run_path>R!   (   R   R˜   R   R   RŸ   (   R   R–   R7   Rš   R¦   R­   R®   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_zipfile_compiled�  s    c         C   s`   t  ƒ  �Q } d } |  j | | ƒ } t | d | ƒ \ } } d | } |  j | | ƒ Wd  QXd  S(   NRª   R¬   s"   can't find '__main__' module in %r(   R   R˜   R   R£   (   R   R–   R7   Rš   R­   R®   R‘   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_zipfile_error•  s    
c   	      C   s�   t  ƒ  �r } t  ƒ  �` } d } d | } |  j | | | ƒ } t | d | ƒ \ } } d } |  j t | t | ƒ Wd  QXWd  QXd  S(   NRq   s    import runpy
runpy.run_path(%r)
R¬   s   recursion depth exceeded(   R   R˜   R   R¢   t   RuntimeErrorR   (	   R   R–   t	   dummy_dirR7   RS   Rš   R­   R®   R‘   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   test_main_recursion_error�  s     N(   R   R2   R3   R   R   R˜   RŸ   R£   R¥   R§   R¨   R©   R«   R¯   R°   R±   R´   (    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyR•   4  s   													c           C   s   t  t t t ƒ d  S(   N(   R   R   R4   R•   (    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt	   test_main©  s    Rq   (   t   unittestR@   t   os.pathR   R    RN   t   test.test_supportR    R   R   t   test.script_helperR   R   R   R   R   R   R;   R	   R
   R   R   t   TestCaseR   R4   R•   Rµ   R   (    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_runpy.pyt   <module>   s   .">áu	