
    IR-eZ6                         d 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
 ddlmZ ed             Z G d de          Z G d	 d
e
e          ZdS )zImplements the wrapper for the Astropy test runner.

This is for backward-compatibility for other downstream packages and can be removed
once astropy-helpers has reached end-of-life.

    N)contextmanager)Command)logc               #      K   t          t          j        d          5 } t          j        }| t          _        	 dV  |t          _        n# |t          _        w xY w	 ddd           dS # 1 swxY w Y   dS )z
    A context manager to temporarily disable stdout.

    Used later when installing a temporary copy of astropy to avoid a
    very verbose output.
    wN)openosdevnullsysstdout)r
   
old_stdouts     5lib/python3.11/site-packages/astropy/tests/command.py_suppress_stdoutr      s       
bj#		 $'Z

	$EEE#CJJCJ####J$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s'   A'AA'AA''A+.A+c                   "     e Zd ZdZ fdZ xZS )FixRemoteDataOptionau  
    This metaclass is used to catch cases where the user is running the tests
    with --remote-data. We've now changed the --remote-data option so that it
    takes arguments, but we still want --remote-data to work as before and to
    enable all remote tests. With this metaclass, we can modify sys.argv
    before setuptools try to parse the command-line options.
    c                 J   	 t           j                            d          }dt           j        |<   n# t          $ r Y nw xY w	 t           j                            d          }dt           j        |<   n# t          $ r Y nw xY wt	                                          |||          S )Nz--remote-dataz--remote-data=anyz-Rz-R=any)r   argvindex
ValueErrorsuper__init__)clsnamebasesdctidx	__class__s        r   r   zFixRemoteDataOption.__init__.   s    	0(..11C 0CHSMM  	 	 	D	
	%(..&&C %CHSMM  	 	 	D	
 wweS111s   2 
??A2 2
A?>A?)__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r   %   sB         2 2 2 2 2 2 2 2 2    r   c                   J    e Zd ZdZg dZdZd Zd Zd Zd Z	d Z
dd
Zd ZdS )AstropyTestzRun the tests for this package))zpackage=PzThe name of a specific package to test, e.g. 'io.fits' or 'utils'. Accepts comma separated string to specify multiple packages. If nothing is specified, all default tests are run.)z
test-path=taH  Specify a test location by path.  If a relative path to a  .py file, it is relative to the built package, so e.g., a  leading "astropy/" is necessary.  If a relative  path to a .rst file, it is relative to the directory *below* the --docs-path directory, so a leading "docs/" is usually necessary.  May also be an absolute path.)zverbose-resultsVz#Turn on verbose output from pytest.)zplugins=pz&Plugins to enable when running pytest.)z	pastebin=bz8Enable pytest pastebin output. Either 'all' or 'failed'.)zargs=az,Additional arguments to be passed to pytest.)zremote-data=RzZRun tests that download remote data. Should be one of none/astropy/any (defaults to none).)pep88zPEnable PEP8 checking and disable regular tests. Requires the pytest-pep8 plugin.)pdbdz0Start the interactive Python debugger on errors.)coveragecz8Create a coverage report. Requires the coverage package.)z	parallel=jzRun the tests in parallel on the specified number of CPUs.  If "auto", all the cores on the machine will be used.  Requires the pytest-xdist plugin.)z
docs-path=NzThe path to the documentation .rst files.  If not provided, and the current directory contains a directory called "docs", that will be used.)z	skip-docsNz(Don't test the documentation .rst files.)zrepeat=NzPHow many times to repeat each test (can be used to check for sporadic failures).)z
temp-root=NzThe root directory in which to create the temporary testing files. If unspecified the system default is used (e.g. /tmp) as explained in the documentation for tempfile.mkstemp.)zverbose-installNzOTurn on terminal output from the installation of astropy in a temporary folder.)readonlyNz7Make the temporary installation being tested read-only. c                     d | _         d | _        d| _        d | _        d | _        d | _        d| _        d| _        d| _        d| _	        d| _
        d | _        d| _        d | _        d | _        d| _        d| _        d S )NFnoner   )package	test_pathverbose_resultspluginspastebinargsremote_datar-   r/   r1   parallel	docs_path	skip_docsrepeat	temp_rootverbose_installr4   selfs    r   initialize_optionszAstropyTest.initialize_options   s    $	!	$r#   c                     d S N rE   s    r   finalize_optionszAstropyTest.finalize_options   s	     	r#   c                     d}d}| j         r!|                                 \  }}||z  }||z  }d}d}|                    || ||          S )z9
        Build a Python script to run the tests.
        r5   z/import builtins; builtins._ASTROPY_TEST_ = Truea  {cmd_pre}{0}; import {1.package_name}, sys; result = ({1.package_name}.test(package={1.package!r}, test_path={1.test_path!r}, args={1.args!r}, plugins={1.plugins!r}, verbose={1.verbose_results!r}, pastebin={1.pastebin!r}, remote_data={1.remote_data!r}, pep8={1.pep8!r}, pdb={1.pdb!r}, parallel={1.parallel!r}, docs_path={1.docs_path!r}, skip_docs={1.skip_docs!r}, add_local_eggs_to_path=True, repeat={1.repeat!r})); {cmd_post}sys.exit(result))cmd_precmd_post)r1   _generate_coverage_commandsformat)rF   rM   rN   prepostset_flagcmds          r   generate_testing_commandz$AstropyTest.generate_testing_command   sk     = 	88::ICsNGHD 	( zz(D'HzMMMr#   c                    | j         j        r$| j                             | j         j                   | j        | j                             d                              dd          }|Pt          j                            |d                   r+t          j        	                    |d                   | _        nCt          j                            d          r$t          j        	                    d          | _        | 
                                 | j         j        r$| j                             | j         j                   t          j                            d          r8t          j        dt          j                            | j        d                     | j        r*t#          j        d           |                     d	           	 |                                 }t+          j        t.          j        d
|g| j        d          }|                                }nB# t4          $ r5 ddl}|                    |j                   |                                }Y nw xY w| j        r|                     d	           t          j        | j                   n;# | j        r|                     d	           t          j        | j                   w xY wtA          |          )zRun the tests!N
build_docs
source_dir   docsz.eggsz;changing permissions of temporary installation to read-onlyF)writablez-c)cwd	close_fdsr   T)!distributioninstall_requiresfetch_build_eggsr@   get_option_dictgetr	   pathexistsabspath_build_temp_installtests_requireshutilcopytreejointesting_pathr4   r   info _change_permissions_testing_pathrU   
subprocessPopenr   
executablewaitKeyboardInterruptsignalsend_signalSIGINTrmtreetmp_dir
SystemExit)rF   cfg_docs_dirrT   testprocretcoders   s         r   runzAstropyTest.run   s    - 	S..t/@/QRRR >!,<<\JJNNd L 'BGNN<?,K,K'!#a!A!A '' 9!#!8!8 	  """ * 	P..t/@/NOOO 7>>'"" 	OOGRW\\$2CW%M%MNNN = 	BHRSSS1151AAA	(//11C "'s+1Be  H mmooGG  	& 	& 	&MMM   ///mmooGGG	& } E55t5DDDM$,'''' } E55t5DDDM$,''''!!!s+   AH J <IJ IJ 8Kc                 F   t          j        | j        dz   | j                  }t          j                            |          | _        t          j	        d| j                    | 
                    d           | j                            d          }| j        |_        | j        r|                     d           n;t!                      5  |                     d           ddd           n# 1 swxY w Y   |                     d          }|j        | _        | j        ht          j                            | j        t          j                            | j                            }t/          j        | j        |           || _        t/          j        d| j                   dS )a  
        Install the package and to a temporary directory for the purposes of
        testing. This allows us to test the install command, include the
        entry points, and also avoids creating pyc and __pycache__ directories
        inside the build directory.
        z-test-)prefixdirz#installing to temporary directory: installNz	setup.cfg)tempfilemkdtemppackage_namerC   r	   rc   realpathrw   r   rl   reinitialize_commandr^   get_command_objr~   rD   run_commandr   get_finalized_commandinstall_librk   r@   rj   basenamerh   ri   copy)rF   rw   install_cmdnew_docs_paths       r   rf   zAstropyTest._build_temp_install  s    "$x/T^
 
 
 w''00Et|EEFFF
 	!!),,,'77	BB!\ 	,Y''''!## , ,  +++, , , , , , , , , , , , , , ,
 00;;'3
 >%GLL!27#3#3DN#C#C M ODNM:::*DNK!233333s   
C,,C03C0Fc                    |rt           j        t           j        z  }nt           j        }t          j        | j                  D ]\  }}}|D ]B}t          j        t          j                            ||          |t           j	        z             C|D ]5}t          j        t          j                            ||          |           6d S rI   )
statS_IRUSRS_IWUSRr	   walkrk   chmodrc   rj   S_IXUSR)rF   r[   basic_flagsrootdirsfilesdirnamefilenames           r   rm   z,AstropyTest._change_permissions_testing_pathA  s     	',5KK,K!#):!;!; 	D 	DD$ R RdG44kDL6PQQQQ! D DdH55{CCCCD	D 	Dr#   c                    | j         dk    rt          d          	 ddl}n# t          $ r t          d          w xY wt          j                            | j        | j        	                    dd          dd          }t          |          5 }|                                }ddd           n# 1 swxY w Y   |	                    d	| j        	                    dd                    }t          j                            | j        d          }t          |d
          5 }|                    |                    d                     ddd           n# 1 swxY w Y   dt          j                            d           dt          j                            |           d}dt          j                            d           dt          j                            | j                   d}||fS )zg
        This method creates the post and pre commands if coverage is to be
        generated.
        r   z*--coverage can not be used with --parallelNz;--coverage requires that the coverage package is installed../tests
coveragercz{packagename}wbzutf-8z5import coverage; cov = coverage.coverage(data_file=r"z	.coveragez", config_file=r"z"); cov.start();z[cov.stop(); from astropy.tests.helper import _save_coverage; _save_coverage(cov, result, r"z", r"z");)r?   r   r1   ImportErrorr	   rc   rj   rk   r   replacer   readrw   writeencodere   )	rF   r1   r   fdcoveragerc_contenttmp_coveragerctmprM   rN   s	            r   rO   z'AstropyTest._generate_coverage_commandsL  su   
 =AIJJJ	OOOO 	 	 	M  	 W\\%%c3//	
 

 * 	+!#	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 077T.66sC@@
 
 dlLAA.$'' 	:3II(//88999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:P.0gook.J.JP P goon==P P P 	:.0gooc.B.B: :'//$"344: : : 	   s,   ! ;B..B25B2)EEEN)F)r   r   r    descriptionuser_optionsr   rG   rK   rU   r|   rf   rm   rO   rJ   r#   r   r%   r%   @   s        2KF F FLP L  &  
"N "N "NHF" F" F"P.4 .4 .4`	D 	D 	D 	D.! .! .! .! .!r#   r%   )	metaclass)r!   r	   rh   r   rn   r   r   
contextlibr   
setuptoolsr   astropy.loggerr   r   typer   r%   rJ   r#   r   <module>r      s    
			       



  % % % % % %             $ $ $ 2 2 2 2 2$ 2 2 26z! z! z! z! z!'%8 z! z! z! z! z! z!r#   