
    K\h                     f    d Z ddlZddlZddlZddlZddlZ G d d          Z G d d          ZdS )zdevelop tests    Nc                   6    e Zd Zd Zed             Zd Zd ZdS )TestSandboxc                     t           j                            t          |                    5  |                     t
          j                   d d d            d S # 1 swxY w Y   d S N)
setuptoolssandboxDirectorySandboxstr_file_writerosdevnull)selftmpdirs     U/opt/python-3.11.14/usr/lib/python3.11/site-packages/setuptools/tests/test_sandbox.pytest_devnullzTestSandbox.test_devnull   s    00V== 	* 	*bj)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s    AA!Ac                       fd}|S )Nc                      t          dd          5 } |                     d           d d d            d S # 1 swxY w Y   d S )Nwutf-8encodingxxx)openwrite)fpaths    r   do_writez*TestSandbox._file_writer.<locals>.do_write   s    dC'222 a                 s   7;; )r   r   s   ` r   r   zTestSandbox._file_writer   s#    	 	 	 	 	     c                     t          j        t          d          }t          j        d          }t
          j                            |t          |                     |j	        dk    sJ dS )zT
        It should be possible to execute a setup.py with a Byte Order Mark
        zscript-with-bom.py	namespacepassedN)
pkg_resourcesresource_filename__name__types
ModuleTyper   r   	_execfilevarsresult)r   targetr!   s      r   test_setup_py_with_BOMz"TestSandbox.test_setup_py_with_BOM   s`     0;OPP$[11	$$VT)__===8++++++r   c                    |dz  }|                     d          5 }|                    d           d d d            n# 1 swxY w Y   t          j                            t          |          t                                 d S )Nzsetup.pywbs   "degenerate script"
)r   r   r   r   r(   r
   globals)r   r   setup_pystreams       r   test_setup_py_with_CRLFz#TestSandbox.test_setup_py_with_CRLF"   s    J&]]4   	5FLL3444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5$$S]]GII>>>>>s   =AAN)r%   
__module____qualname__r   staticmethodr   r,   r2   r   r   r   r   r      s\        * * *   \, , ,? ? ? ? ?r   r   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	TestExceptionSaverc                 x    t           j                                        5  t          d          # 1 swxY w Y   d S Ndetails)r   r   ExceptionSaver
ValueErrorr   s    r   test_exception_trappedz)TestExceptionSaver.test_exception_trapped*   sa    ..00 	( 	(Y'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   /33c                 n   t           j                                        5 }t          d          # 1 swxY w Y   t	          j        t                    5 }|                                 d d d            n# 1 swxY w Y   t          |j        t                    sJ t          |j                  dk    sJ d S r9   )
r   r   r;   r<   pytestraisesresume
isinstancevaluer
   )r   	saved_exccaughts      r   test_exception_resumedz)TestExceptionSaver.test_exception_resumed.   s   ..00 	(IY'''	( 	( 	( 	( 	( 	( 	( 	( ]:&& 	&	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 &,
333336<  I------s   /33A44A8;A8c                 T   t          d          }t          j                                        5 }|# 1 swxY w Y   t	          j        t                     5 }|                                 d d d            n# 1 swxY w Y   t          |j        t                     sJ |j        |usJ d S r9   )	r<   r   r   r;   r@   rA   rB   rC   rD   )r   orig_excrE   rF   s       r   test_exception_reconstructedz/TestExceptionSaver.test_exception_reconstructed8   s   i((..00 	IN	 	 	 	 	 	 	 	 ]:&& 	&	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 &,
33333|8++++++s   155A66A:=A:c                     t           j                                        5 }	 d d d            n# 1 swxY w Y   |                                 d S r   )r   r   r;   rB   )r   rE   s     r    test_no_exception_passes_quietlyz3TestExceptionSaver.test_no_exception_passes_quietlyD   s    ..00 	I	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   -11c                 h    G d dt                     }t          j                                        5 } |d          # 1 swxY w Y   t	          j        t          j        j                  5 }|                                 d d d            n# 1 swxY w Y   t          |j	                  dk    sJ d S )Nc                       e Zd ZdZdefdZdS )FTestExceptionSaver.test_unpickleable_exception.<locals>.CantPickleThisz:This Exception is unpickleable because it's not in globalsreturnc                     d| j         S )NCantPickleThis)argsr=   s    r   __repr__zOTestExceptionSaver.test_unpickleable_exception.<locals>.CantPickleThis.__repr__N   s    5	555r   N)r%   r3   r4   __doc__r
   rT   r   r   r   rR   rO   K   s5        HH6# 6 6 6 6 6 6r   rR   detailzCantPickleThis('detail',))
	Exceptionr   r   r;   r@   rA   UnpickleableExceptionrB   r
   rD   )r   rR   rE   rF   s       r   test_unpickleable_exceptionz.TestExceptionSaver.test_unpickleable_exceptionJ   s"   	6 	6 	6 	6 	6Y 	6 	6 	6 ..00 	+I .***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ ]:-CDD 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 6<  $???????s!   >AA,BBBc                 d    G d dt                     }t          j        t          j        j                  5 }t          j                                        5  t          j                                         |# 1 swxY w Y   	 ddd           n# 1 swxY w Y   |j        j	        \  }|dk    sJ dS )z
        As revealed in #440, an infinite recursion can occur if an unpickleable
        exception while setuptools is hidden. Ensure this doesn't happen.
        c                       e Zd ZdZdS )aTestExceptionSaver.test_unpickleable_exception_when_hiding_setuptools.<locals>.ExceptionUnderTestzE
            An unpickleable exception (not in globals).
            N)r%   r3   r4   rU   r   r   r   ExceptionUnderTestr\   _   s           r   r]   NzExceptionUnderTest())
rW   r@   rA   r   r   rX   save_moduleshide_setuptoolsrD   rS   )r   r]   rF   msgs       r   2test_unpickleable_exception_when_hiding_setuptoolszETestExceptionSaver.test_unpickleable_exception_when_hiding_setuptoolsY   s#   	 	 	 	 	 	 	 	
 ]:-CDD 	)#0022 ) )"22444(() ) ) ) ) ) ) ) )	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)
 ",,,,,,,s/   B!A77A;	;B>A;	?BBBc                 f   d }t          j        t          j        j                  5 }t          j                                        5  t          j                                         t          j                            t          |                    5   |             ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |j	        j
        \  }}}|dk    sJ |dk    sJ |ddik    sJ t          |j	                  }d|v sJ d|v sJ d|v sJ dS )	z
        When in a sandbox with setuptools hidden, a SandboxViolation
        should reflect a proper exception and not be wrapped in
        an UnpickleableException.
        c                  ^    t          ddd          5  	 ddd           dS # 1 swxY w Y   dS )z9Trigger a SandboxViolation by writing outside the sandbox/etc/foor   r   r   N)r   r   r   r   
write_filezVTestExceptionSaver.test_sandbox_violation_raised_hiding_setuptools.<locals>.write_files   s~    j#888                   s   "&&Nr   )rd   r   r   r   z('/etc/foo', 'w')z{'encoding': 'utf-8'})r@   rA   r   r   SandboxViolationr^   r_   r	   r
   rD   rS   )r   r   re   rF   cmdrS   kwargsr`   s           r   /test_sandbox_violation_raised_hiding_setuptoolszBTestExceptionSaver.test_sandbox_violation_raised_hiding_setuptoolsl   s   	 	 	
 ]:->?? 	!6#0022 ! !"22444'88VEE ! !JLLL! ! ! ! ! ! ! ! ! ! ! ! ! ! !! ! ! ! ! ! ! ! ! ! ! ! ! ! !	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! #L-T6f}}}}(((((*g.....&,}}}}"c))))&#------sZ   CAB?B(B?(B,,B?/B,0B?3C?C	CC	CCCN)
r%   r3   r4   r>   rG   rJ   rL   rY   ra   ri   r   r   r   r7   r7   )   s        ( ( (. . .
, 
, 
,  @ @ @- - -&. . . . .r   r7   )	rU   r   r&   r@   r#   setuptools.sandboxr   r   r7   r   r   r   <module>rk      s      				          ? ? ? ? ? ? ? ?:]. ]. ]. ]. ]. ]. ]. ]. ]. ].r   