
    HR-ef                         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Zd dlmZ  ej	        g dg d          d             Z
 ej	        g dg d          d             Z G d d	          ZdS )
    N)fits)Fstrpathlib) home_is_datazhome_is_data, pathlib)paramsidsc                     | j         rJ|| j        _        | j                                         | j                            | j         dk               dS dS )a  
    Pytest fixture to run a test case both with and without tilde paths.

    In the tilde-path case, calls like self.data('filename.fits') will
    produce '~/filename.fits', and environment variables will be temporarily
    modified so that '~' resolves to the data directory.
    r   N)paraminstancemonkeypatchset_home_as_dataset_paths_via_pathlibrequestr   s     >lib/python3.11/site-packages/astropy/io/fits/tests/conftest.pyr   r      s_     } K'2$))+++..w}	/IJJJJJK K    c                     | j         rJ|| j        _        | j                                         | j                            | j         dk               dS dS )a  
    Pytest fixture to run a test case both with and without tilde paths.

    In the tilde-path case, calls like self.temp('filename.fits') will
    produce '~/filename.fits', and environment variables will be temporarily
    modified so that '~' resolves to the temp directory. These files will also
    be tracked so that, after the test case, we can verify no files were written
    to a literal tilde path.
    r   N)r   r   r   set_home_as_tempr   r   s     r   home_is_tempr   #   s_     } K'2$))+++..w}	/IJJJJJK Kr   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
FitsTestCasec                    t           j                            t           j                            t                    d          | _        t          j        d          | _        d| _	        d| _
        t                      | _        d| _        dt          j        _        dt          j        _        dt          j        _        dt          j        _        d S )Ndataz
fits-test-)prefixFT)ospathjoindirname__file__data_dirtempfilemkdtemptemp_dirr   r   settemp_files_useduse_pathlibr   conf"enable_record_valued_keyword_cardsextension_name_case_sensitivestrip_header_whitespace
use_memmapselfs    r   setup_methodzFitsTestCase.setup_method:   s    RW__X%>%>GG (===!!"uu 
 8<	427	/,0	)#	r   c                    | j         rO| j        D ]G\  }}t          j                            |          rJ t          j                            |          sJ Ht          | d          rnt          j                            | j                  rJd}|rF	 t          j        | j                   n+# t          $ r t          j        d           |dz  }Y nw xY w|Ft          j                            d           t          j                            d           t          j                            d           t          j                            d           d S )	Nr$      g      ?   r)   r*   r+   r,   )r   r&   r   r   existshasattrr$   shutilrmtreeOSErrortimesleepr   r(   reset)r.   	temp_filetemp_file_no_tildetriess       r   teardown_methodzFitsTestCase.teardown_methodK   sI    	:151E : :-	-7>>)44444w~~&89999994$$ 	)F)F 	E 	M$-000    JsOOOQJEEE	  	 		<===	7888	1222	%%%%%s   B* *#CCc                    t          j        t          j                            |                     |                    t          j                            |                     |                               t          j        t          j                            |                     |                    t          j	        t          j
        z             dS )zdCopies a backup of a test data file to the temp dir and sets its
        mode to writeable.
        N)r5   copyr   r   
expanduserr   tempchmodstatS_IREADS_IWRITE)r.   filenames     r   	copy_filezFitsTestCase.copy_filed   s     	Gtyy2233Gtyy2233	
 	
 	
 	##DIIh$7$788$,:VWWWWWr   c                     | j         rd}n| j        }| j        rt          j        ||          S t
          j                            ||          S )z%Returns the path to a test data file.~)r   r!   r'   r   Pathr   r   r   )r.   rG   r   s      r   r   zFitsTestCase.datan   sN     	#FF]F 	2<111w||FH---r   c                 Z   t           j                            | j        |          }| j        r=d}| j                            t           j                            ||          |f           n| j        }| j        rt          j	        ||          S t           j                            ||          S )z5Returns the full path to a file in the test temp dir.rJ   )
r   r   r   r$   r   r&   addr'   r   rK   )r.   rG   real_targetr   s       r   rB   zFitsTestCase.tempy   s    gll4=(;; 	#F  $$bgll68&D&Dk%RSSSS]F 	2<111w||FH---r   c                     d| _         | j                            d| j                   | j                            d| j                   dS )z
        This overrides the HOME environment variable, so that paths beginning
        with '~/' expand to the data directory. Used by the `home_is_data`
        fixture.
        THOMEUSERPROFILEN)r   r   setenvr!   r-   s    r   r   zFitsTestCase.set_home_as_data   sH     !666t}=====r   c                     d| _         | j                            d| j                   | j                            d| j                   dS )az  
        This overrides the HOME environment variable, so that paths beginning
        with '~/' expand to the temp directory. In conjunction with
        self.temp(), temporary files are tracked as they are created, so we can
        verify they end up in the temporary directory and not unexpected places
        in the filesystem. Used by the `home_is_temp` fixture.
        TrP   rQ   N)r   r   rR   r$   r-   s    r   r   zFitsTestCase.set_home_as_temp   sH     !666t}=====r   c                     || _         d S )N)r'   )r.   r'   s     r   r   z"FitsTestCase.set_paths_via_pathlib   s    &r   N)__name__
__module____qualname__r/   r>   rH   r   rB   r   r   r    r   r   r   r   9   s        $ $ $"& & &2X X X	. 	. 	.. . .
> 
> 
>> > >' ' ' ' 'r   r   )r   r   r5   rD   r"   r8   pytest
astropy.ior   fixturer   r   r   rX   r   r   <module>r\      s    
			             $$$*W*W*W  K K K" $$$*W*W*W  K K K&j' j' j' j' j' j' j' j' j' j'r   