
    |hz                         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
  G d dej                        Zej                  d        Zej                  Zej                   Zej"                  Zy)	z"Utilities for Python Fire's tests.    N)mock)core)tracec                   \    e Zd ZdZej
                  dd       Zej
                  dd       Zy)BaseTestCasez'Shared test case for Python Fire tests.c              #     K   t        j                         }t        j                         }	 t        j                  j	                  t
        d|      5  t        j                  j	                  t
        d|      5  d ddd       ddd       |s[t
        j                  j                  |j                                t
        j                  j                  |j                                	 d||fd||ffD ]t  \  }}}|j                         }	||	st        |d|	      t        j                  ||	t        j                  t        j                  z        rct        |d|	d|       y# 1 sw Y   xY w# 1 sw Y   xY w# |s[t
        j                  j                  |j                                t
        j                  j                  |j                                w w xY ww)a  Asserts that the context generates stdout and stderr matching regexps.

    Note: If wrapped code raises an exception, stdout and stderr will not be
      checked.

    Args:
      stdout: (str) regexp to match against stdout (None will check no stdout)
      stderr: (str) regexp to match against stderr (None will check no stderr)
      capture: (bool, default True) do not bubble up stdout or stderr

    Yields:
      Yields to the wrapped context.
    stdoutstderrNz: Expected no output. Got: z: Expected z
 to match )ioStringIOr   patchobjectsysr	   writegetvaluer
   AssertionErrorresearchDOTALL	MULTILINE)
selfr	   r
   capture	stdout_fp	stderr_fpnameregexpfpvalues
             M/var/www/html/test/engine/venv/lib/python3.12/site-packages/fire/testutils.pyassertOutputMatchesz BaseTestCase.assertOutputMatches    s     II/::S(I6 ZZsHi8 	
	 

++-.

++-.&	:&	:< 
6fbkkme	 $e - . . yy		BLL(@A $eV 5 6 6
6	 	  

++-.

++-. s[   )G%%F &E77E+<E7F BG%AG%G%+E4	0E77F <F AG""G%c           	   #     K   | j                  |      5  | j                  t        j                        5  	 d 	 ddd       ddd       y# t        j                  $ rZ}|j                  |k7  rt        d|j                  d|      | j                  |j                  t        j                          d}~ww xY w# 1 sw Y   xY w# 1 sw Y   yxY ww)a^  Asserts that a FireExit error is raised in the context.

    Allows tests to check that Fire's wrapper around SystemExit is raised
    and that a regexp is matched in the output.

    Args:
      code: The status code that the FireExit should contain.
      regexp: stdout must match this regex.

    Yields:
      Yields to the wrapped context.
    )r
   NzIncorrect exit code: z != )	r    assertRaisesr   FireExitcoder   assertIsInstancer   	FireTrace)r   r$   r   excs       r   assertRaisesFireExitz!BaseTestCase.assertRaisesFireExitF   s      
	!	!	!	0 	T]]+ 	
	 	 }} 	XX "%((D"2 3 3


		5??
;
	 	 	sP   C C	B=AC		CB: AB55B::B==C	C		CCN).*r)   T)r)   )__name__
__module____qualname____doc__
contextlibcontextmanagerr    r(        r   r   r      s8    /#6 #6J  r1   r   c              #      K   t        j                         }t        j                  |        	 |  t        j                  |       y# t        j                  |       w xY ww)z>Context manager to mock a directory change and revert on exit.N)osgetcwdchdir)	directorycwdirs     r   ChangeDirectoryr8   `   s?      ))+%((9
OHHUOBHHUOs   *A!A A!AA!)r-   r.   r   r3   r   r   unittestr   firer   r   TestCaser   r/   r8   mainskipskipIfr0   r1   r   <module>r?      sq    )  	 	 	 
    @8$$ @F   }}}}	r1   