a
    §ˆcõ  ã                   @   s‚   d dl m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	m
Z
 ddl	mZ ej ej e¡dd¡ZG dd	„ d	ejƒZdS )
é    )ÚSequenceNé   )ÚPyfaceResourceFactory)ÚResourceManagerZimagesúcore.pngc                   @   sD   e 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 )ÚTestPyfaceResourceFactoryc                 C   s   t ƒ | _d S ©N)r   Úresource_factory©Úself© r   úe/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/tests/test_resource_manager.pyÚsetUp   s    zTestPyfaceResourceFactory.setUpc                 C   s   | j  t¡ d S r   )r	   Zimage_from_fileÚ
IMAGE_PATHr
   r   r   r   Útest_image_from_file   s    z.TestPyfaceResourceFactory.test_image_from_filec                 C   sB   t tdƒ�}| ¡ }W d   ƒ n1 s(0    Y  | j |¡ d S )NÚrb)Úopenr   Úreadr	   Zimage_from_data)r   ÚfpÚdatar   r   r   Útest_image_from_data!   s    &z.TestPyfaceResourceFactory.test_image_from_datac                 C   sF   G dd„ dt ƒ}|tj t¡gƒ}tƒ }| d|¡}|  t|j¡ d S )Nc                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )z>TestPyfaceResourceFactory.test_locate_image.<locals>.ASequencec                 S   s
   || _ d S r   ©r   )r   r   r   r   r   Ú__init__(   s    zGTestPyfaceResourceFactory.test_locate_image.<locals>.ASequence.__init__c                 S   s
   | j | S r   r   )r   Úir   r   r   Ú__getitem__+   s    zJTestPyfaceResourceFactory.test_locate_image.<locals>.ASequence.__getitem__c                 S   s
   t | jƒS r   )Úlenr   r
   r   r   r   Ú__len__.   s    zFTestPyfaceResourceFactory.test_locate_image.<locals>.ASequence.__len__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   Ú	ASequence'   s   r    r   )	r   ÚosÚpathÚdirnamer   r   Úlocate_imageÚassertEqualÚfilename)r   r    ÚsequenceÚresource_managerZimg_refr   r   r   Útest_locate_image&   s
    
z+TestPyfaceResourceFactory.test_locate_imagec                 C   s*   t ƒ }| dtg¡}|  t|jƒd¡ d S )Nz	close.pngr   )r   r$   ÚpyfaceZassertGreaterr   r   ©r   r(   Ú	image_refr   r   r   Útest_locate_image_with_module7   s    z7TestPyfaceResourceFactory.test_locate_image_with_modulec                 C   s"   t ƒ }| dtg¡}|  |¡ d S )Nzdoes_not_exist.png)r   r$   r*   ZassertIsNoner+   r   r   r   Ú*test_locate_image_with_module_missing_file>   s
    ÿzDTestPyfaceResourceFactory.test_locate_image_with_module_missing_filec              	   C   s¼   t  ¡ � }t ttj |d¡¡ tj |d¡}t|ddd�� W d   ƒ n1 sR0    Y  t	j
 d|¡}t	j
 |¡}ttƒ d�}| d|g¡}|  |¡ W d   ƒ n1 s®0    Y  d S )Nz
random.pngztmp.pyÚwzutf-8)ÚencodingÚ__main__)r	   )ÚtempfileÚTemporaryDirectoryÚshutilÚcopyfiler   r!   r"   Újoinr   Ú	importlibÚutilÚspec_from_file_locationÚmodule_from_specr   r   Z
load_imageZassertIsNotNone)r   Ztmp_dirZpy_filepathÚspecÚmoduler(   r,   r   r   r   Ú-test_locate_image_with_name_being_dunder_mainF   s    
ÿÿzGTestPyfaceResourceFactory.test_locate_image_with_name_being_dunder_mainN)
r   r   r   r   r   r   r)   r-   r.   r=   r   r   r   r   r      s   r   )Úcollections.abcr   Zimportlib.utilr7   r!   r4   r2   Zunittestr*   r(   r   r   r"   r6   r#   Ú__file__r   ZTestCaser   r   r   r   r   Ú<module>   s   