a
    3j؅                     @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlZd dlmZ d dl	Z	ddl
mZ edZedZedZed	ZG d
d dZG dd deZejeed\ZZG dd deZejeed\ZZG dd deZejeed\ZZG dd deZejeed\ZZG dd deZejeed\Z Z!G dd deZ"eje"ed\Z#Z$G dd deZ%eje%ed\Z&Z'd[ddZ(G dd dZ)G d d dZG d!d" d"e)Z*ee*\Z+Z,G d#d dZG d$d% d%e)Z-ee-\Z.Z/G d&d' d'Z0G d(d) d)e)Z1ee1\Z2Z3G d*d de0ZG d+d, d,e)Z4ee4\Z5Z6G d-d de0Ze(eZ7G d.d/ d/e)Z8ee8\Z9Z:G d0d deZe(eZ;G d1d2 d2e)Z<ee8\Z=Z>G d3d4 d4Z?G d5d6 d6e)Z@ee@\ZAZBG d7d8 d8ZCejeCeed9\ZDZEG d:d; d;ZFejeFeeed<\ZGZHG d=d> d>ZIejeIeed9\ZJZKG d?d@ d@ZLejeLe7dA\ZMZNG dBdC dCZOejeOe7dA\ZPZQG dDdE dEZRejeRe7eedF\ZSZTG dGdH dHZUejeUe;dI\ZVZWG dJdK dKZXe(eXdZYG dLd deXZ%e(e%eedMZZG dNdO dOZ[G dPdQ dQe[Z\eje\eeYdR\Z]Z^e_ej`dSG dTdU dUe[ZaejeaeeeZdV\ZbZcG dWdX dXZdejedeYdY\ZeZfegdZkreh  dS )\    N)support)mock   )util	importlibzimportlib.abczimportlib.machineryzimportlib.utilc                   @   s0   e Zd ZdZg Zg Zdd Zdd Zdd ZdS )	InheritanceTestszSTest that the specified class is a subclass/superclass of the expected
    classes.c                    sR   fddj D _tdr>jj  fddjD _tjj_	d S )Nc                    s   g | ]}t  j|qS  )getattrabc.0
class_nameselfr   X/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_importlib/test_abc.py
<listcomp>   s   z*InheritanceTests.setUp.<locals>.<listcomp>subclass_namesc                    s   g | ]}t  |qS r   r	   r   )	machineryr   r   r   &   s   )
superclass_namessuperclasseshasattrr
   r   r   
subclassesr	   Z_NAME_InheritanceTests__testr   r   )r   r   r   setUp   s    


zInheritanceTests.setUpc                 C   s.   | j D ]"}| t|| jd|| j qd S )Nz{0} is not a subclass of {1})r   
assertTrue
issubclassr   format)r   subclassr   r   r   test_subclasses+   s    
z InheritanceTests.test_subclassesc                 C   s.   | j D ]"}| t| j|d|| j qd S )Nz{0} is not a superclass of {1})r   r   r   r   r   )r   Z
superclassr   r   r   test_superclasses1   s    
z"InheritanceTests.test_superclassesN)	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r   r      s   r   c                   @   s   e Zd ZdgZg dZdS )MetaPathFinderFinder)BuiltinImporterFrozenImporter
PathFinderWindowsRegistryFinderNr!   r"   r#   r   r   r   r   r   r   r%   8   s   r%   )r
   c                   @   s   e Zd ZdgZdgZdS )PathEntryFinderr&   
FileFinderNr+   r   r   r   r   r,   C   s   r,   c                   @   s   e Zd ZdgZdS )ResourceLoaderLoaderN)r!   r"   r#   r   r   r   r   r   r.   M   s   r.   c                   @   s   e Zd ZdgZg dZdS )InspectLoaderr/   )r'   r(   ExtensionFileLoaderNr+   r   r   r   r   r0   V   s   r0   c                   @   s   e Zd ZdgZdgZdS )ExecutionLoaderr0   r1   Nr+   r   r   r   r   r2   `   s   r2   c                   @   s   e Zd ZddgZddgZdS )
FileLoaderr.   r2   SourceFileLoaderSourcelessFileLoaderNr+   r   r   r   r   r3   j   s   r3   c                   @   s   e Zd ZddgZdgZdS )SourceLoaderr.   r2   r4   Nr+   r   r   r   r   r6   t   s   r6   Fc                    sF   d u r| j fddt D } fddtj| |fi |D S )Nc                    s   i | ]\}}|t | qS r   r   )r   kindZsplitabc)namer   r   
<dictcomp>   s   z'make_abc_subclasses.<locals>.<dictcomp>c                    s   i | ]}|j  r| n|qS r   )_KIND)r   cls)instr   r   r9      s   )r!   r
   items	test_utilZsplit_frozen)Z
base_classr8   r<   kwargsbaser   )r<   r8   r   make_abc_subclasses   s    

rA   c                   @   s   e Zd Zedd ZdS )ABCTestHarnessc                 C   s   | j | j }| }|| j_|S N)SPLITr:   	__class__ins)r   r;   rF   r   r   r   rF      s    zABCTestHarness.insN)r!   r"   r#   propertyrF   r   r   r   r   rB      s   rB   c                       s   e Zd Z fddZ  ZS )r%   c                    s   t  ||S rC   )superfind_module)r   fullnamepathrE   r   r   rI      s    zMetaPathFinder.find_module)r!   r"   r#   rI   __classcell__r   r   rL   r   r%      s   c                   @   s$   e Zd ZeeZdd Zdd ZdS )MetaPathFinderDefaultsTestsc                 C   sF   |  t | jdd }W d    n1 s.0    Y  | | d S NZ	something)assertWarnsDeprecationWarningrF   rI   assertIsNoner   foundr   r   r   test_find_module   s    ,z,MetaPathFinderDefaultsTests.test_find_modulec                 C   s   | j   d S rC   rF   invalidate_cachesr   r   r   r   test_invalidate_caches   s    z2MetaPathFinderDefaultsTests.test_invalidate_cachesN)r!   r"   r#   rA   r%   rD   rU   rX   r   r   r   r   rN      s   rN   c                       s   e Zd Z fddZ  ZS )r,   c                    s   t  |S rC   )rH   find_loaderr   rJ   rL   r   r   rY      s    zPathEntryFinder.find_loader)r!   r"   r#   rY   rM   r   r   rL   r   r,      s   c                   @   s,   e Zd ZeeZdd Zdd Zdd ZdS )PathEntryFinderDefaultsTestsc                 C   sJ   |  t | jd}W d    n1 s,0    Y  | |d g f d S rO   )rP   rQ   rF   rY   assertEqualrS   r   r   r   test_find_loader   s    *z-PathEntryFinderDefaultsTests.test_find_loaderc                 C   s   |  d | jd d S rO   )r\   rF   rI   r   r   r   r   rI      s    z(PathEntryFinderDefaultsTests.find_modulec                 C   s   | j   d S rC   rV   r   r   r   r   rX      s    z3PathEntryFinderDefaultsTests.test_invalidate_cachesN)	r!   r"   r#   rA   r,   rD   r]   rI   rX   r   r   r   r   r[      s   r[   c                       s   e Zd Z fddZ  ZS )r/   c                    s   t  |S rC   )rH   load_modulerZ   rL   r   r   r^      s    zLoader.load_module)r!   r"   r#   r^   rM   r   r   rL   r   r/      s   r/   c                   @   s,   e Zd ZeeZdd Zdd Zdd ZdS )LoaderDefaultsTestsc                 C   s   d}|  | j| d S )Nza spec)rR   rF   create_module)r   specr   r   r   test_create_module   s    z&LoaderDefaultsTests.test_create_modulec                 C   s:   |  t | jd W d    n1 s,0    Y  d S rO   )assertRaisesImportErrorrF   r^   r   r   r   r   test_load_module   s    z$LoaderDefaultsTests.test_load_modulec                 C   sb   t d}| t | j| W d    n1 s60    Y  t|}| j|_| t| d S Nblah)	types
ModuleTyperc   NotImplementedErrorrF   module_reprrepr
__loader__r   )r   modZoriginal_reprr   r   r   test_module_repr   s    
*z$LoaderDefaultsTests.test_module_reprN)	r!   r"   r#   rA   r/   rD   rb   re   ro   r   r   r   r   r_      s   r_   c                       s   e Zd Z fddZ  ZS )r.   c                    s   t  |S rC   )rH   get_datar   rK   rL   r   r   rp      s    zResourceLoader.get_data)r!   r"   r#   rp   rM   r   r   rL   r   r.      s   c                   @   s   e Zd ZeeZdd ZdS )ResourceLoaderDefaultsTestsc                 C   s:   |  t | jd W d    n1 s,0    Y  d S )Nz
/some/path)rc   IOErrorrF   rp   r   r   r   r   test_get_data   s    z)ResourceLoaderDefaultsTests.test_get_dataN)r!   r"   r#   rA   r.   rD   rt   r   r   r   r   rr      s   rr   c                       s(   e Zd Z fddZ fddZ  ZS )r0   c                    s   t  |S rC   )rH   
is_packagerZ   rL   r   r   ru     s    zInspectLoader.is_packagec                    s   t  |S rC   )rH   
get_sourcerZ   rL   r   r   rv     s    zInspectLoader.get_source)r!   r"   r#   ru   rv   rM   r   r   rL   r   r0      s   c                   @   s    e Zd ZeZdd Zdd ZdS )InspectLoaderDefaultsTestsc                 C   s:   |  t | jd W d    n1 s,0    Y  d S rf   )rc   rd   rF   ru   r   r   r   r   test_is_package  s    z*InspectLoaderDefaultsTests.test_is_packagec                 C   s:   |  t | jd W d    n1 s,0    Y  d S rf   )rc   rd   rF   rv   r   r   r   r   test_get_source  s    z*InspectLoaderDefaultsTests.test_get_sourceN)r!   r"   r#   SPLIT_ILrD   rx   ry   r   r   r   r   rw     s   rw   c                       s   e Zd Z fddZ  ZS )r2   c                    s   t  |S rC   )rH   get_filenamerZ   rL   r   r   r{     s    zExecutionLoader.get_filename)r!   r"   r#   r{   rM   r   r   rL   r   r2     s   c                   @   s   e Zd ZeZdd ZdS )ExecutionLoaderDefaultsTestsc                 C   s:   |  t | jd W d    n1 s,0    Y  d S rf   )rc   rd   rF   r{   r   r   r   r   test_get_filename*  s    z.ExecutionLoaderDefaultsTests.test_get_filenameN)r!   r"   r#   SPLIT_ELrD   r}   r   r   r   r   r|   &  s   r|   c                       s@   e Zd Z fddZ fddZ fddZ fddZ  ZS )	ResourceReaderc                    s   t  j|i |S rC   )rH   open_resourcer   argsr?   rL   r   r   r   6  s    zResourceReader.open_resourcec                    s   t  j|i |S rC   )rH   resource_pathr   rL   r   r   r   9  s    zResourceReader.resource_pathc                    s   t  j|i |S rC   )rH   is_resourcer   rL   r   r   r   <  s    zResourceReader.is_resourcec                    s   t  j|i |S rC   )rH   contentsr   rL   r   r   r   ?  s    zResourceReader.contents)r!   r"   r#   r   r   r   r   rM   r   r   rL   r   r   4  s   r   c                   @   s4   e Zd ZeeZdd Zdd Zdd Zdd Z	d	S )
ResourceReaderDefaultsTestsc                 C   s:   |  t | jd W d    n1 s,0    Y  d S NZ
dummy_file)rc   FileNotFoundErrorrF   r   r   r   r   r   test_open_resourceG  s    z.ResourceReaderDefaultsTests.test_open_resourcec                 C   s:   |  t | jd W d    n1 s,0    Y  d S r   )rc   r   rF   r   r   r   r   r   test_resource_pathK  s    z.ResourceReaderDefaultsTests.test_resource_pathc                 C   s:   |  t | jd W d    n1 s,0    Y  d S r   )rc   r   rF   r   r   r   r   r   test_is_resourceO  s    z,ResourceReaderDefaultsTests.test_is_resourcec                 C   s   |  g t| j  d S rC   )r\   listrF   r   r   r   r   r   test_contentsS  s    z)ResourceReaderDefaultsTests.test_contentsN)
r!   r"   r#   rA   r   rD   r   r   r   r   r   r   r   r   r   C  s
   r   c                   @   s8   e Zd Zedd Zdd Zdd Zdd Zd	d
 ZdS )MetaPathFinderFindModuleTestsc                    s   G  fddd| j j}| S )Nc                       s   e Zd Zd fdd	ZdS )z@MetaPathFinderFindModuleTests.finder.<locals>.MetaPathSpecFinderNc                    s   ||f| _  S rC   
called_for)r   rJ   rK   targetra   r   r   	find_specb  s    
zJMetaPathFinderFindModuleTests.finder.<locals>.MetaPathSpecFinder.find_spec)Nr!   r"   r#   r   r   r   r   r   MetaPathSpecFinder`  s   r   )r
   r%   )r;   ra   r   r   r   r   finder^  s    z$MetaPathFinderFindModuleTests.finderc                 C   sZ   |  d }g d}d}| t |||}W d    n1 sB0    Y  | | d S )Nabcrg   )r   rP   rQ   rI   rR   r   r   rK   r8   rT   r   r   r   rU   h  s    
*z.MetaPathFinderFindModuleTests.test_find_modulec                 C   s<   t  }| jd|}| |}|ddd }| || d S rf   )objectr   spec_from_loaderr   r   r\   r   loaderra   r   rT   r   r   r   #test_find_spec_with_explicit_targetp  s
    
zAMetaPathFinderFindModuleTests.test_find_spec_with_explicit_targetc                 C   sV   |  d }g d}d}|||d }| | | ||jd  | ||jd  d S )Nr   rg   r   r   )r   r   rR   r\   r   r   r   r   r   test_no_specw  s    

z*MetaPathFinderFindModuleTests.test_no_specc                 C   s:   t  }| jd|}| |}|dd }| || d S rf   )r   r   r   r   r   assertIsr   r   r   r   	test_spec  s
    
z'MetaPathFinderFindModuleTests.test_specN)	r!   r"   r#   classmethodr   rU   r   r   r   r   r   r   r   r   \  s   
		r   )r
   r   c                   @   s0   e Zd Zedd Zdd Zdd Zdd Zd	S )
PathEntryFinderFindLoaderTestsc                    s   G  fddd| j j}| S )Nc                       s   e Zd Zd fdd	ZdS )zBPathEntryFinderFindLoaderTests.finder.<locals>.PathEntrySpecFinderNc                    s
   || _  S rC   r   )r   rJ   r   r   r   r   r     s    zLPathEntryFinderFindLoaderTests.finder.<locals>.PathEntrySpecFinder.find_spec)Nr   r   r   r   r   PathEntrySpecFinder  s   r   )r
   r,   )r;   ra   r   r   r   r   r     s    z%PathEntryFinderFindLoaderTests.finderc                 C   sr   |  d }d}| t ||}W d    n1 s80    Y  | |d  | g |d  | ||j d S )Nrg   r   r   )r   rP   rQ   rY   rR   r\   r   )r   r   r8   rT   r   r   r   r     s    
(z+PathEntryFinderFindLoaderTests.test_no_specc                 C   sh   t  }| jd|}| |}| t |d}W d    n1 sH0    Y  | |d |j d S )Nrg   r   )	r   r   r   r   rP   rQ   rY   r   r   r   r   r   r   test_spec_with_loader  s    
(z4PathEntryFinderFindLoaderTests.test_spec_with_loaderc                 C   s|   | j dd }g d}||_| |}| t |d}W d    n1 sP0    Y  | |d  | ||d  d S )Nrg   r   r   r   )	r   
ModuleSpecsubmodule_search_locationsr   rP   rQ   rY   rR   r\   )r   ra   pathsr   rT   r   r   r   test_spec_with_portions  s    
(z6PathEntryFinderFindLoaderTests.test_spec_with_portionsN)r!   r"   r#   r   r   r   r   r   r   r   r   r   r     s
   
		r   )r
   r   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )LoaderLoadModuleTestsc                 C   s   G dd d| j j}| S )Nc                   @   s    e Zd ZdZdd Zdd ZdS )z0LoaderLoadModuleTests.loader.<locals>.SpecLoaderNc                 S   s
   || _ d S rC   )rT   r   moduler   r   r   exec_module  s    z<LoaderLoadModuleTests.loader.<locals>.SpecLoader.exec_modulec                 S   s   dS )z.Force some non-default module state to be set.Tr   rZ   r   r   r   ru     s    z;LoaderLoadModuleTests.loader.<locals>.SpecLoader.is_package)r!   r"   r#   rT   r   ru   r   r   r   r   
SpecLoader  s   r   )r
   r/   )r   r   r   r   r   r     s    	zLoaderLoadModuleTests.loaderc                 C   s   |   }d}t|2 || |j}| tj| | W d    n1 sN0    Y  | ||j	 | ||j
j  | ||j | ||j
j | |j | |j|j
j d S rf   )r   r>   uncacher^   rT   r   sysmodulesr\   rm   __spec__r!   r8   ZassertIsNotNone__path__r   )r   r   r8   r   r   r   r   
test_fresh  s    
0z LoaderLoadModuleTests.test_freshc                 C   s   d}|   }t|}| j|||_||_t|N |t	j
|< || |j}| |t	j
|  | |t	j
|  W d    n1 s0    Y  d S rf   )r   rh   ri   r   r   r   rm   r>   r   r   r   r^   rT   r   )r   r8   r   r   rT   r   r   r   test_reload  s    


z!LoaderLoadModuleTests.test_reloadN)r!   r"   r#   r   r   r   r   r   r   r   r     s   r   c                   @   s6   e Zd ZdddZdd Zdd Zdd	 Zd
d ZdS )InspectLoaderSourceToCodeTestsNc                 C   sB   t d}|  }|du r&||}n|||}t||j |S )z!Help with source_to_code() tests.rg   N)rh   ri   InspectLoaderSubclasssource_to_codeexec__dict__)r   datarK   r   r   coder   r   r   source_to_module  s    
z/InspectLoaderSourceToCodeTests.source_to_modulec                 C   s0   d}|  |}| t|d | |jd d S )N	attr = 42attr*   r   r   r   r\   r   r   sourcer   r   r   r   test_source_to_code_source  s    
z9InspectLoaderSourceToCodeTests.test_source_to_code_sourcec                 C   s0   d}|  |}| t|d | |jd d S )Ns	   attr = 42r   r   r   r   r   r   r   test_source_to_code_bytes  s    
z8InspectLoaderSourceToCodeTests.test_source_to_code_bytesc                 C   s*   d}|   }|d|}| |j| d S )Nzpath/to/somewhere r   r   r\   co_filename)r   rK   r   r   r   r   r   test_source_to_code_path	  s    z7InspectLoaderSourceToCodeTests.test_source_to_code_pathc                 C   s$   |   }|d}| |jd d S )Nr   <string>r   )r   r   r   r   r   r   test_source_to_code_no_path  s    
z:InspectLoaderSourceToCodeTests.test_source_to_code_no_path)N)r!   r"   r#   r   r   r   r   r   r   r   r   r   r     s
   
r   )r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )InspectLoaderGetCodeTestsc                 C   sp   t d}tj| jd(}d|_|  }|d}W d    n1 sH0    Y  t||j	 | 
|jd d S )Nrg   rv   r   r   )rh   ri   r   patchr   r   return_valueget_coder   r   r\   r   )r   r   mockedr   r   r   r   r   test_get_code   s    
(z'InspectLoaderGetCodeTests.test_get_codec                 C   sV   t j| jd(}d |_|  }|d}W d    n1 s>0    Y  | | d S )Nrv   rg   )r   r   r   r   r   r   rR   )r   r   r   r   r   r   r   test_get_code_source_is_None*  s
    (z6InspectLoaderGetCodeTests.test_get_code_source_is_Nonec                 C   s@   |   }| t |d W d    n1 s20    Y  d S rf   )r   rc   rd   r   r   r   r   r   r   test_get_code_source_not_found2  s    z8InspectLoaderGetCodeTests.test_get_code_source_not_foundN)r!   r"   r#   r   r   r   r   r   r   r   r     s   
r   c                   @   sD   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dS )InspectLoaderLoadModuleTestsz!Test InspectLoader.load_module().rg   c                 C   s    t | j | t j| j d S rC   )r   Zunloadmodule_nameZ
addCleanupr   r   r   r   r   E  s    z"InspectLoaderLoadModuleTests.setUpc                 C   sV   | j | j|}t * tdt | jj	|W  d    S 1 sH0    Y  d S Nignore)
r   r   r   warningscatch_warningssimplefilterrQ   init
_bootstrap_load_unlocked)r   r   ra   r   r   r   loadI  s    
z!InspectLoaderLoadModuleTests.loadc                 C   s   t j| jdS )Nr   )r   r   r   r   r   r   r   r   mock_get_codeO  s    z*InspectLoaderLoadModuleTests.mock_get_codec              	   C   sn   |   R}t|_| t" |  }| | W d    n1 sB0    Y  W d    n1 s`0    Y  d S rC   )r   rd   side_effectrc   r   r   r   mocked_get_coder   r   r   r   test_get_code_ImportErrorR  s
    
z6InspectLoaderLoadModuleTests.test_get_code_ImportErrorc              	   C   sn   |   R}d |_| t" |  }| | W d    n1 sB0    Y  W d    n1 s`0    Y  d S rC   )r   r   rc   rd   r   r   r   r   r   r   test_get_code_NoneZ  s
    
z/InspectLoaderLoadModuleTests.test_get_code_Nonec                 C   sd   t ddd}|  <}||_|  }| |}| |tj| j  W d    n1 sV0    Y  d S )Nr   r   r   )	compiler   r   r   r   r\   r   r   r   )r   r   r   r   r   r   r   r   test_module_returnedb  s    

z1InspectLoaderLoadModuleTests.test_module_returnedN)r!   r"   r#   r$   r   r   r   r   r   r   r   r   r   r   r   r   ?  s   r   )r   r   r   c                   @   s<   e Zd ZdddddZdd Zdd Zd	d
 Zdd ZdS )ExecutionLoaderGetCodeTestsFrv   r{   c                C   s8   d\}}|rt j| jd}|r0t j| jd}||fS )N)NNrv   r{   )r   r   r   ExecutionLoaderSubclass)r   rv   r{   source_mock_contextfilename_mock_contextr   r   r   mock_methodsw  s    

z(ExecutionLoaderGetCodeTests.mock_methodsc           	   	   C   s   d}| j ddd\}}|R}|.}d|_||_|  }|d}W d    n1 sT0    Y  W d    n1 sr0    Y  | |j| td}t||j	 | |j
d d S )Nzblah.pyTr   r   rg   r   )r   r   r   r   r\   r   rh   ri   r   r   r   )	r   rK   r   r   source_mock	name_mockr   r   r   r   r   r   r     s    
F
z)ExecutionLoaderGetCodeTests.test_get_codec                 C   sZ   | j dd\}}|(}d |_|  }|d}W d    n1 sB0    Y  | | d S )NT)rv   rg   )r   r   r   r   rR   )r   r   _r   r   r   r   r   r   r     s    (z8ExecutionLoaderGetCodeTests.test_get_code_source_is_Nonec                 C   s@   |   }| t |d W d    n1 s20    Y  d S rf   )r   rc   rd   r   r   r   r   r   r     s    z:ExecutionLoaderGetCodeTests.test_get_code_source_not_foundc              	   C   s   | j ddd\}}|R}|.}d|_t|_|  }|d}W d    n1 sP0    Y  W d    n1 sn0    Y  | |jd t	d}t
||j | |jd d S )NTr   r   rg   r   r   )r   r   rd   r   r   r   r\   r   rh   ri   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   test_get_code_no_path  s    
F
z1ExecutionLoaderGetCodeTests.test_get_code_no_pathN)r!   r"   r#   r   r   r   r   r   r   r   r   r   r   u  s
   
	r   )r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )SourceOnlyLoadersN   _ = '::'.join([__name__, __file__, __cached__, __package__, repr(__loader__)])c                 C   s
   || _ d S rC   rK   rq   r   r   r   __init__  s    zSourceOnlyLoader.__init__c                 C   s   || j krt| jS rC   )rK   rs   r   rq   r   r   r   rp     s    
zSourceOnlyLoader.get_datac                 C   s   | j S rC   r   rZ   r   r   r   r{     s    zSourceOnlyLoader.get_filenamec                 C   s   dS )Nz<module>r   r   r   r   r   rk     s    zSourceOnlyLoader.module_reprN)r!   r"   r#   r   r   rp   r{   rk   r   r   r   r   r     s
   r   c                       s>   e Zd ZdZd fdd	Z fddZdd Zd	d
 Z  ZS )r6   r   Nc                    s   t  | | j| j| _t| j| _|d u r8| jj	}t
|}|| jd || j| j || j| j t| j| jddd}|t| t|| _i | _d S )Nr   r   T)dont_inherit)rH   r   r   cache_from_sourcerK   bytecode_pathlenr   source_sizeMAGIC_NUMBER	bytearrayextendr   _pack_uint32source_mtimer   marshaldumpsbytesbytecodewritten)r   rK   magicr   code_objectrL   r   r   r     s    
zSourceLoader.__init__c                    s.   || j krt |S || jkr&| jS td S rC   )rK   rH   rp   r   r  OSErrorrq   rL   r   r   rp     s
    

zSourceLoader.get_datac                 C   s   || j krt| j| jdS )N)mtimesize)rK   rs   r   r   rq   r   r   r   
path_stats  s    
zSourceLoader.path_statsc                 C   s   t || j|< || jkS rC   )r  r  r   )r   rK   r   r   r   r   set_data  s    zSourceLoader.set_data)N)	r!   r"   r#   r   r   rp   r  r  rM   r   r   rL   r   r6     s
   )r   r   c                   @   s*   e Zd ZddddZdd Zdd Zd	S )
SourceLoaderTestHarnessTru   c                K   s   d| _ |r&tj| j d| _| j | _n2d}tj| j dddg| _d| j |g| _| j| j| _| j| jfi || _	d S )NZpkgz__init__.pyrn   .py)
packageosrK   joinr8   r   r   cachedloader_mockr   )r   ru   r?   r   r   r   r   r     s    
zSourceLoaderTestHarness.setUpc                 C   s   |  |j| j |  |j| j |  |j| j |  |j| j |  |j	| j
 |jd}|  |d | j |  |d | j |  |d | j |  |d | j |  |d t| j
 d S )Nz::r   r            )r\   r!   r8   __file__rK   
__cached__r  __package__r  rm   r   r   splitrl   )r   r   valuesr   r   r   verify_module  s    z%SourceLoaderTestHarness.verify_modulec                 C   sL   t | j}| j|_| j|_| j|_| j	|_
g |_t||j | | d S rC   )rh   ri   r8   rK   r  r  r  r  r  r   rm   r   r   r   r  )r   r  r   r   r   r   verify_code  s    z#SourceLoaderTestHarness.verify_codeN)r!   r"   r#   r   r  r  r   r   r   r   r    s   r  c                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )SourceOnlyLoaderTestszTest importlib.abc.SourceLoader for source-only loading.

    Reload testing is subsumed by the tests for
    importlib.util.module_for_loader.

    c                 C   s   | j jd}| | j | j| dd }|| j _| t}| j | j W d    n1 sb0    Y  | |j	j| j d S )Nutf-8c                 S   s   t d S rC   )r  r   r   r   r   raise_OSError*  s    z<SourceOnlyLoaderTests.test_get_source.<locals>.raise_OSError)
r   r   decoder\   rv   r8   rp   rc   rd   	exception)r   Zexpected_sourcer"  cmr   r   r   ry   %  s    ,z%SourceOnlyLoaderTests.test_get_sourcec                 C   s\   | j dd | | j| j | j dd | | j| j | | j| jd  d S )NFr  Tz	.__init__)r   assertFalser   ru   r8   r   r   r   r   r   rx   1  s
    z%SourceOnlyLoaderTests.test_is_packagec                 C   s   | j | j}| | d S rC   r   r   r8   r  r   r  r   r   r   r   9  s    z#SourceOnlyLoaderTests.test_get_codec                 C   s"   | j | j j| j}| | d S rC   )r   r   r   rK   r  )r   r   r   r   r   test_source_to_code>  s    z)SourceOnlyLoaderTests.test_source_to_codec              	   C   s   t | j t * tdt | j| j}W d    n1 sF0    Y  | 	| | 
|jtj| jg | | jtj W d    n1 s0    Y  d S r   )r>   r   r8   r   r   r   rQ   r   r^   r  r\   r   r  rK   dirnameassertInr   r   r   r   r   r   re   C  s    
,
z&SourceOnlyLoaderTests.test_load_modulec              	   C   s   | j dd t| jl t * tdt | j	| j}W d    n1 sR0    Y  | 
| | t|d W d    n1 s0    Y  d S )NFr  r   r   )r   r>   r   r8   r   r   r   rQ   r   r^   r  r&  r   r   r   r   r   test_package_settingsO  s    
,
z+SourceOnlyLoaderTests.test_package_settingsc                 C   s\   d}| d| j_| j| j}| || d}| d| j_| j| j}| || d S )Nu   _ = 'ü'r!  u   # coding: latin-1
_ = ülatin-1)encoder   r   rv   r8   r\   )r   r   returned_sourcer   r   r   test_get_source_encoding[  s    z.SourceOnlyLoaderTests.test_get_source_encodingN)r!   r"   r#   r$   ry   rx   r   r)  re   r,  r0  r   r   r   r   r     s   r   )r   r  zsys.dont_write_bytecode is truec                       s^   e Zd ZdZdd fdd
Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Z  ZS )SourceLoaderBytecodeTestszsTest importlib.abc.SourceLoader's use of bytecode.

    Source-only testing handled by SourceOnlyLoaderTests.

    Fbytecode_writtenc                   s   t  | |r| | j| jj t| jj}|	| j
d |	| j
| jj |	| j
| jj |	t| | | jj| j t| d S )Nr   )rH   r  r+  r  r   r  r   r   r   r   r   r   r   r   r  r  r\   r  )r   r  r3  r   rL   r   r   r  w  s    z%SourceLoaderBytecodeTests.verify_codec                 C   s   | j | j}| | d S rC   r'  r(  r   r   r   test_code_with_everything  s    z3SourceLoaderBytecodeTests.test_code_with_everythingc                 C   sl   d| j _| t* | j| j}| j | W d    n1 sB0    Y  | j | j	}| j
|dd d S )N<does not exist>Tr2  )r   r   rc   r  r   r   rK   rp   r   r8   r  )r   r   r  r   r   r   test_no_bytecode  s    *z*SourceLoaderBytecodeTests.test_no_bytecodec                 C   sV   dD ]L}| j j}|| j _| j jdd  | j _| j | j}| j|dd || j _qd S )N)r   r     Tr2  )r   r   r  r   r8   r  )r   r   Zoriginalr  r   r   r   test_code_bad_timestamp  s    z1SourceLoaderBytecodeTests.test_code_bad_timestampc                 C   s@   | j dd | jjdd  | j_| j| j}| j|dd d S )N   0000r  r7  Tr2  )r   r   r  r   r8   r  r(  r   r   r   test_code_bad_magic  s    z-SourceLoaderBytecodeTests.test_code_bad_magicc                 C   sF   z8dt _d| j_| j| j}| | j| jj W dt _ndt _0 d S )NTr5  F)	r   dont_write_bytecoder   r   r   r8   ZassertNotInr  r  r(  r   r   r   test_dont_write_bytecode  s    z2SourceLoaderBytecodeTests.test_dont_write_bytecodec              	   C   sv   | j dd | jj d j}z>| jj d `| j| j}| | W || jj d _n|| jj d _0 d S )Nr9  r:  r   )r   r   rE   mror  r   r8   r  )r   Zoriginal_set_datar  r   r   r   test_no_set_data  s    z*SourceLoaderBytecodeTests.test_no_set_datac                 C   s<   dd }| j dd |t| j_| j| j}| | d S )Nc                    s    fdd}|S )Nc                     s    d S rC   r   )r   r?   excr   r   closure  s    zcSourceLoaderBytecodeTests.test_set_data_raises_exceptions.<locals>.raise_exception.<locals>.closurer   )rA  rB  r   r@  r   raise_exception  s    zRSourceLoaderBytecodeTests.test_set_data_raises_exceptions.<locals>.raise_exceptionr9  r:  )r   rj   r   r  r   r8   r  )r   rC  r  r   r   r   test_set_data_raises_exceptions  s
    z9SourceLoaderBytecodeTests.test_set_data_raises_exceptions)r!   r"   r#   r$   r  r4  r6  r8  r;  r=  r?  rD  rM   r   r   rL   r   r1  n  s   
r1  )r   r   r  c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	SourceLoaderGetSourceTestsz2Tests for importlib.abc.SourceLoader.get_source().c                 C   s8   d}|  d}d}|d|_||}| || d S )Nrn   mod.fileu   x = "ü"r!  SourceOnlyLoaderMockr.  r   rv   r\   r   r8   r   r   r/  r   r   r   test_default_encoding  s    

z0SourceLoaderGetSourceTests.test_default_encodingc                 C   s8   d}|  d}d}|d|_||}| || d S )Nrn   rF  u   # coding: Latin-1
x='ü'r-  rG  rI  r   r   r   test_decoded_source  s    

z.SourceLoaderGetSourceTests.test_decoded_sourcec                 C   sF   d}|  d}d}|d|_td d|}| ||| d S )Nrn   rF  zx = 42
y = -13
r!  T)rH  r.  r   ioIncrementalNewlineDecoderr#  r\   rv   )r   r8   r   r   expectr   r   r   test_universal_newlines  s    
z2SourceLoaderGetSourceTests.test_universal_newlinesN)r!   r"   r#   r$   rJ  rK  rO  r   r   r   r   rE    s   	
rE  )rH  __main__)NF)irL  r  r  r   testr   rh   Zunittestr   r   r   r   r>   Zimport_importlibr   r
   r   r   r%   Z	test_bothZ%Frozen_MetaPathFinderInheritanceTestsZ%Source_MetaPathFinderInheritanceTestsr,   Z&Frozen_PathEntryFinderInheritanceTestsZ&Source_PathEntryFinderInheritanceTestsr.   Z%Frozen_ResourceLoaderInheritanceTestsZ%Source_ResourceLoaderInheritanceTestsr0   Z$Frozen_InspectLoaderInheritanceTestsZ$Source_InspectLoaderInheritanceTestsr2   Z&Frozen_ExecutionLoaderInheritanceTestsZ&Source_ExecutionLoaderInheritanceTestsr3   Z!Frozen_FileLoaderInheritanceTestsZ!Source_FileLoaderInheritanceTestsr6   Z#Frozen_SourceLoaderInheritanceTestsZ#Source_SourceLoaderInheritanceTestsrA   rB   rN   ZFrozen_MPFDefaultTestsZSource_MPFDefaultTestsr[   ZFrozen_PEFDefaultTestsZSource_PEFDefaultTestsr/   r_   ZFrozen_LDefaultTestsZSourceLDefaultTestsrr   ZFrozen_RLDefaultTestsZSource_RLDefaultTestsrz   rw   ZFrozen_ILDefaultTestsZSource_ILDefaultTestsr~   r|   ZFrozen_ELDefaultTestsZSource_ELDefaultsTestsr   r   ZFrozen_RRDefaultTestsZSource_RRDefaultsTestsr   ZFrozen_MPFFindModuleTestsZSource_MPFFindModuleTestsr   ZFrozen_PEFFindLoaderTestsZSource_PEFFindLoaderTestsr   ZFrozen_LoaderLoadModuleTestsZSource_LoaderLoadModuleTestsr   ZFrozen_ILSourceToCodeTestsZSource_ILSourceToCodeTestsr   ZFrozen_ILGetCodeTestsZSource_ILGetCodeTestsr   ZFrozen_ILLoadModuleTestsZSource_ILLoadModuleTestsr   ZFrozen_ELGetCodeTestsZSource_ELGetCodeTestsr   Z	SPLIT_SOLZSPLIT_SLr  r   ZFrozen_SourceOnlyLoaderTestsZSource_SourceOnlyLoaderTestsZskipIfr<  r1  ZFrozen_SLBytecodeTestsZSourceSLBytecodeTestsrE  Z%Frozen_SourceOnlyLoaderGetSourceTestsZ%Source_SourceOnlyLoaderGetSourceTestsr!   mainr   r   r   r   <module>   s&  



$
		.*
-,/;
&&N[
#
