
    g[                        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Zd dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlmZ d dlZd dlZddlmZmZ dd	lmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 d
 Z5 e5            \  Z6Z7Z8de9fdZ: e:e7d          Z;dTdZ< e<dd          Z=d Z>d Z?d Z@d ZAd ZBd ZCd ZDd ZEd ZFd ZGd ZHd ZId ZJd  ZKd! ZLd" ZMd# ZNd$ ZOd% ZPd& ZQd' ZRd( ZSd) ZTd* ZUd+ ZVd, ZWd- ZXd. ZYdUd/ZZd0 Z[d1 Z\d2 Z]d3 Z^d4 Z_d5 Z`d6 Zad7 Zbd8 Zc ed e2             e)            g          o
 e             Zed9 Zfd: Zg G d; d<ejh                  Zi G d= d>ejh                  Zj G d? d@ejh                  ZkdA Zl G dB dC          ZmdD ZndVdemfdEZodWdHe9demfdIZp G dJ dKeq          ZrdXdLees         fdMZtdNesdefdOZue
dYdPeqdQesdevfdR            ZwdS ZxdS )Z    N)contextmanager)partial)Path)ListUnion)mock   )AcceleratorStatePartialState)gatheris_bnb_availableis_clearml_availableis_comet_ml_availableis_cuda_availableis_datasets_availableis_deepspeed_availableis_dvclive_availableis_import_timer_availableis_mlu_availableis_mps_availableis_musa_availableis_npu_availableis_pandas_availableis_pippy_availableis_schedulefree_availableis_tensorboard_availableis_timm_availableis_torch_versionis_torch_xla_available*is_torchdata_stateful_dataloader_availableis_torchvision_availableis_transformer_engine_availableis_transformers_availableis_triton_availableis_wandb_availableis_xpu_availablestr_to_boolc                  f   t                      r0dt          j                                        t          j        j        fS t                      r0dt          j                                        t          j        j        fS t          d          rddt          j        j        fS t                      rddd fS t                      r0dt          j
                                        t          j
        j        fS t                      r0d	t          j                                        t          j        j        fS t                      r0d
t          j                                        t          j        j        fS t                      r0dt          j                                        t          j        j        fS ddd fS )Nxlacudaz2.0)min_versionmps   c                      dS Nr    r0       Y/var/www/html/ai-engine/env/lib/python3.11/site-packages/accelerate/test_utils/testing.py<lambda>zget_backend.<locals>.<lambda>K        r1   mlumusanpuxpucpuc                      dS r/   r0   r0   r1   r2   r3   zget_backend.<locals>.<lambda>U   r4   r1   )r   torchr*   device_countmemory_allocatedr   r   r,   current_allocated_memoryr   r5   r   r6   r   r7   r&   r8   r0   r1   r2   get_backendr?   C   sg    #ej--//1LLL			 #uz..00%*2MMM	e	,	,	, #a;;;			 #a""			 	#ei,,..	0JJJ			 #uz..00%*2MMM			 #ei,,..	0JJJ			 #ei,,..	0JJJa""r1   returnc                      ddg}|                                  D ]R\  }}t          |t                    r|r|                    d|            5||                    d| d|            S|S )z
    Wraps around `kwargs` to help simplify launching from `subprocess`.

    Example:
    ```python
    # returns ['accelerate', 'launch', '--num_processes=2', '--device_count=2']
    get_launch_command(num_processes=2, device_count=2)
    ```
    
acceleratelaunchz--N=)items
isinstanceboolappend)kwargscommandkvs       r2   get_launch_commandrM   [   s     X&G ) )1a 	)1 	)NN888$$$$]NN<<<A<<(((Nr1   g?)num_processesmonitor_intervalFc                     	 t           j        |          }	 t          |          }n3# t          $ r t          d|  d          w xY w# t          $ r |}Y nw xY w|S )NzIf set, z must be yes or no.)osenvironr'   
ValueErrorKeyError)keydefaultvalue_values       r2   parse_flag_from_envrY   q   s    B
3	B ''FF 	B 	B 	B@@@@AAA	B     Ms   A % AAARUN_SLOW)rV   c                 <     t          j        d          |           S )z+Decorator that skips a test unconditionallyzTest was skipped)unittestskip	test_cases    r2   r]   r]      s    ,8=+,,Y777r1   c                 H     t          j        t          d          |           S )z
    Decorator marking a test as slow. Slow tests are skipped by default. Set the RUN_SLOW environment variable to a
    truthy value to run them.
    ztest is slow)r\   
skipUnless_run_slow_testsr^   s    r2   slowrc      s"    
 @8??	JJJr1   c                 P     t          j        t          dk    d          |           S )zu
    Decorator marking a test that must be only ran on the CPU. These tests are skipped when a GPU is available.
    r9   ztest requires only a CPUr\   ra   torch_devicer^   s    r2   require_cpurg      s)     R8|u46PQQR[\\\r1   c                 P     t          j        t          dk    d          |           S )z
    Decorator marking a test that requires a hardware accelerator backend. These tests are skipped when there are no
    hardware accelerator available.
    r9   test requires a GPUre   r^   s    r2   require_non_cpurj      s(    
 M8|u46KLLYWWWr1   c                 t     t          j        t                      ot                       d          |           S )z
    Decorator marking a test that requires CUDA. These tests are skipped when there are no GPU available or when
    TorchXLA is available.
    ri   )r\   ra   r   r   r^   s    r2   require_cudarl      s:    
 l8022S;Q;S;S7SUjkkluvvvr1   c                 V     t          j        t                      d          |           S )zn
    Decorator marking a test that requires XPU. These tests are skipped when there are no XPU available.
    test requires a XPU)r\   ra   r&   r^   s    r2   require_xpuro      s*     J8/113HII)TTTr1   c                 P     t          j        t          dk    d          |           S )zB
    Decorator marking a test that should be skipped for XPU.
    r8   ztest requires a non-XPUre   r^   s    r2   require_non_xpurq      s)     Q8|u46OPPQZ[[[r1   c                 V     t          j        t                      d          |           S )zn
    Decorator marking a test that requires MLU. These tests are skipped when there are no MLU available.
    ztest require a MLU)r\   ra   r   r^   s    r2   require_mlurs      *     I8/113GHHSSSr1   c                 V     t          j        t                      d          |           S )zp
    Decorator marking a test that requires MUSA. These tests are skipped when there are no MUSA available.
    ztest require a MUSA)r\   ra   r   r^   s    r2   require_musarv      s*     K80224IJJ9UUUr1   c                 V     t          j        t                      d          |           S )zn
    Decorator marking a test that requires NPU. These tests are skipped when there are no NPU available.
    ztest require a NPU)r\   ra   r   r^   s    r2   require_npurx      rt   r1   c                 V     t          j        t                      d          |           S )z
    Decorator marking a test that requires MPS backend. These tests are skipped when torch doesn't support `mps`
    backend.
    z0test requires a `mps` backend support in `torch`)r\   ra   r   r^   s    r2   require_mpsrz      s+    
 g8/113effgpqqqr1   c                 r     t          j        t                      ot                      d          |           S )zv
    Decorator marking a test that requires transformers and datasets. These tests are skipped when they are not.
    z$test requires the Hugging Face suite)r\   ra   r#   r   r^   s    r2   require_huggingface_suiter|      sB    8!##?(=(?(?.    r1   c                 V     t          j        t                      d          |           S )zi
    Decorator marking a test that requires transformers. These tests are skipped when they are not.
    z&test requires the transformers library)r\   ra   r#   r^   s    r2   require_transformersr~      +     f88::<deefopppr1   c                 V     t          j        t                      d          |           S )za
    Decorator marking a test that requires timm. These tests are skipped when they are not.
    ztest requires the timm library)r\   ra   r   r^   s    r2   require_timmr      s+     V80224TUUV_```r1   c                 V     t          j        t                      d          |           S )zh
    Decorator marking a test that requires torchvision. These tests are skipped when they are not.
    z%test requires the torchvision library)r\   ra   r!   r^   s    r2   require_torchvisionr      s+     d8799;bccdmnnnr1   c                 V     t          j        t                      d          |           S )zc
    Decorator marking a test that requires triton. These tests are skipped when they are not.
    z test requires the triton library)r\   ra   r$   r^   s    r2   require_tritonr      s+     Z82446XYYZcdddr1   c                 V     t          j        t                      d          |           S )zi
    Decorator marking a test that requires schedulefree. These tests are skipped when they are not.
    z&test requires the schedulefree library)r\   ra   r   r^   s    r2   require_schedulefreer      r   r1   c                 V     t          j        t                      d          |           S )zi
    Decorator marking a test that requires bitsandbytes. These tests are skipped when they are not.
    z&test requires the bitsandbytes library)r\   ra   r   r^   s    r2   require_bnbr      s+     ]8/113[\\]fgggr1   c                 Z     t          j        t          d          d          |           S )zp
    Decorator marking a test that requires TPUs. These tests are skipped when there are no TPUs available.
    T)check_is_tpuztest requires TPUr\   ra   r   r^   s    r2   require_tpur     s0     _854HHHJ]^^_hiiir1   c                 X     t          j        t                       d          |           S )z
    Decorator marking a test as requiring an environment without TorchXLA. These tests are skipped when TorchXLA is
    available.
    z%test requires an env without TorchXLAr   r^   s    r2   require_non_torch_xlar     s.    
 f8#9#;#;;=deefopppr1   c                 f     t          j        t          dk    o
t          dk    d          |           S )z
    Decorator marking a test that requires a single device. These tests are skipped when there is no hardware
    accelerator available or number of devices is more than one.
    r9   r-   z$test requires a hardware accelerator)r\   ra   rf   r<   r^   s    r2   require_single_devicer     s9    
 t8|u4J9JLrss  r1   c                 ~     t          j        t          j                                        dk    d          |           S )z
    Decorator marking a test that requires CUDA on a single GPU. These tests are skipped when there are no GPU
    available or number of GPUs is more than one.
    r-   ri   r\   ra   r;   r*   r<   r^   s    r2   require_single_gpur      s7    
 V8uz6688A=?TUUV_```r1   c                 ~     t          j        t          j                                        dk    d          |           S )z
    Decorator marking a test that requires CUDA on a single XPU. These tests are skipped when there are no XPU
    available or number of xPUs is more than one.
    r-   rn   r\   ra   r;   r8   r<   r^   s    r2   require_single_xpur   (  s7    
 U8uy55771<>STTU^___r1   c                 P     t          j        t          dk    d          |           S )z
    Decorator marking a test that requires a multi-device setup. These tests are skipped on a machine without multiple
    devices.
    r-   z,test requires multiple hardware accelerators)r\   ra   r<   r^   s    r2   require_multi_devicer   0  s)    
 a8|a/1_``ajkkkr1   c                 ~     t          j        t          j                                        dk    d          |           S )z
    Decorator marking a test that requires a multi-GPU setup. These tests are skipped on a machine without multiple
    GPUs.
    r-   ztest requires multiple GPUsr   r^   s    r2   require_multi_gpur   8  s7    
 ]8uz66881<>[\\]fgggr1   c                 ~     t          j        t          j                                        dk    d          |           S )z
    Decorator marking a test that requires a multi-XPU setup. These tests are skipped on a machine without multiple
    XPUs.
    r-   ztest requires multiple XPUsr   r^   s    r2   require_multi_xpur   @  s7    
 \8uy5577!;=Z[[\efffr1   c                 V     t          j        t                      d          |           S )z|
    Decorator marking a test that requires DeepSpeed installed. These tests are skipped when DeepSpeed isn't installed
    ztest requires DeepSpeed)r\   ra   r   r^   s    r2   require_deepspeedr   H  s+     T85779RSST]^^^r1   c                 Z     t          j        t          dd          d          |           S )zr
    Decorator marking a test that requires FSDP installed. These tests are skipped when FSDP isn't installed
    >=z1.12.0z%test requires torch version >= 1.12.0)r\   ra   r   r^   s    r2   require_fsdpr   O  s/     j8/h??Ahiijstttr1   c                     | t          t          |          S  t          j        t	          d|          d|           |           S )z
    Decorator marking that a test requires a particular torch version to be tested. These tests are skipped when an
    installed torch version is less than the required one.
    N)versionr   ztest requires torch version >= )r   require_torch_min_versionr\   ra   r   )r_   r   s     r2   r   r   V  sQ    
 0'BBBBl8/g>>@kbi@k@kllmvwwwr1   c                 V     t          j        t                      d          |           S )z
    Decorator marking a test that requires tensorboard installed. These tests are skipped when tensorboard isn't
    installed
    ztest requires Tensorboard)r\   ra   r   r^   s    r2   require_tensorboardr   `  s+    
 X8799;VWWXabbbr1   c                 V     t          j        t                      d          |           S )zt
    Decorator marking a test that requires wandb installed. These tests are skipped when wandb isn't installed
    ztest requires wandb)r\   ra   r%   r^   s    r2   require_wandbr   h  *     L81335JKKIVVVr1   c                 V     t          j        t                      d          |           S )zz
    Decorator marking a test that requires comet_ml installed. These tests are skipped when comet_ml isn't installed
    ztest requires comet_ml)r\   ra   r   r^   s    r2   require_comet_mlr   o  s+     R84668PQQR[\\\r1   c                 V     t          j        t                      d          |           S )zx
    Decorator marking a test that requires clearml installed. These tests are skipped when clearml isn't installed
    ztest requires clearml)r\   ra   r   r^   s    r2   require_clearmlr   v  +     P83557NOOPYZZZr1   c                 V     t          j        t                      d          |           S )zx
    Decorator marking a test that requires dvclive installed. These tests are skipped when dvclive isn't installed
    ztest requires dvclive)r\   ra   r   r^   s    r2   require_dvcliver   }  r   r1   c                 V     t          j        t                      d          |           S )zv
    Decorator marking a test that requires pandas installed. These tests are skipped when pandas isn't installed
    ztest requires pandas)r\   ra   r   r^   s    r2   require_pandasr     s*     N82446LMMiXXXr1   c                 V     t          j        t                      d          |           S )zt
    Decorator marking a test that requires pippy installed. These tests are skipped when pippy isn't installed
    ztest requires pippy)r\   ra   r   r^   s    r2   require_pippyr     r   r1   c                 V     t          j        t                      d          |           S )z
    Decorator marking a test that requires tuna interpreter installed. These tests are skipped when tuna isn't
    installed
    ztest requires tuna interpreter)r\   ra   r   r^   s    r2   require_import_timerr     s+    
 ^88::<\]]^ghhhr1   c                 V     t          j        t                      d          |           S )z
    Decorator marking a test that requires transformers engine installed. These tests are skipped when transformers
    engine isn't installed
    z!test requires transformers engine)r\   ra   r"   r^   s    r2   require_transformer_enginer     s+    
 g8>@@Beffgpqqqr1   c                 H     t          j        t          d          |           S )z
    Decorator marking that a test requires at least one tracking library installed. These tests are skipped when none
    are installed
    zYtest requires at least one tracker to be available and for `comet_ml` to not be installed)r\   ra   _atleast_one_tracker_availabler^   s    r2   require_trackersr     s0    
8&c    r1   c                 V     t          j        t                      d          |           S )z
    Decorator marking a test that requires torchdata.stateful_dataloader.

    These tests are skipped when torchdata with stateful_dataloader module isn't installed.

    z+test requires torchdata.stateful_dataloader)r\   ra   r    r^   s    r2   %require_torchdata_stateful_dataloaderr     s4    82446c   r1   c                   H    e Zd ZdZdZed             Zed             Zd ZdS )TempDirTestCasea  
    A TestCase class that keeps a single `tempfile.TemporaryDirectory` open for the duration of the class, wipes its
    data at the start of a test, and then destroyes it at the end of the TestCase.

    Useful for when a class or API requires a single constant folder throughout it's use, such as Weights and Biases

    The temporary directory location will be stored in `self.tmpdir`
    Tc                 P    t          t          j                              | _        dS )zECreates a `tempfile.TemporaryDirectory` and stores it in `cls.tmpdir`N)r   tempfilemkdtemptmpdirclss    r2   
setUpClasszTempDirTestCase.setUpClass  s      (*,,--


r1   c                     t           j                            | j                  rt	          j        | j                   dS dS )z1Remove `cls.tmpdir` after test suite has finishedN)rQ   pathexistsr   shutilrmtreer   s    r2   tearDownClasszTempDirTestCase.tearDownClass  s>     7>>#*%% 	&M#*%%%%%	& 	&r1   c                     | j         rn| j                            d          D ]U}|                                r|                                 +|                                rt          j        |           TdS dS )z<Destroy all contents in `self.tmpdir`, but not `self.tmpdir`z**/*N)clear_on_setupr   globis_fileunlinkis_dirr   r   )selfr   s     r2   setUpzTempDirTestCase.setUp  s     	(((00 ( (<<>> (KKMMMM[[]] (M$'''	( 	(( (r1   N)	__name__
__module____qualname____doc__r   classmethodr   r   r   r0   r1   r2   r   r     sh          N. . [. & & [&
( ( ( ( (r1   r   c                   "     e Zd ZdZ fdZ xZS )AccelerateTestCasez
    A TestCase class that will reset the accelerator state at the end of every test. Every test that checks or utilizes
    the `AcceleratorState` class should inherit from this to avoid silent failures due to state being shared between
    tests.
    c                     t                                                       t          j                     t	          j                     d S N)supertearDownr
   _reset_stater   )r   	__class__s    r2   r   zAccelerateTestCase.tearDown  s=    %'''!#####r1   )r   r   r   r   r   __classcell__)r   s   @r2   r   r     sB         $ $ $ $ $ $ $ $ $r1   r   c                   N    e Zd ZdZdeej        eej                 f         fdZdS )MockingTestCasea  
    A TestCase class designed to dynamically add various mockers that should be used in every test, mimicking the
    behavior of a class-wide mock when defining one normally will not do.

    Useful when a mock requires specific information available only initialized after `TestCase.setUpClass`, such as
    setting an environment variable with that information.

    The `add_mocks` function should be ran at the end of a `TestCase`'s `setUp` function, after a call to
    `super().setUp()` such as:
    ```python
    def setUp(self):
        super().setUp()
        mocks = mock.patch.dict(os.environ, {"SOME_ENV_VAR", "SOME_VALUE"})
        self.add_mocks(mocks)
    ```
    mocksc                     t          |t          t          f          r|n|g| _        | j        D ]0}|                                 |                     |j                   1dS )aQ  
        Add custom mocks for tests that should be repeated on each test. Should be called during
        `MockingTestCase.setUp`, after `super().setUp()`.

        Args:
            mocks (`mock.Mock` or list of `mock.Mock`):
                Mocks that should be added to the `TestCase` after `TestCase.setUpClass` has been run
        N)rF   tuplelistr   start
addCleanupstop)r   r   ms      r2   	add_mockszMockingTestCase.add_mocks  sc     )>>KUUUG
 	$ 	$AGGIIIOOAF####	$ 	$r1   N)	r   r   r   r   r   r   Mockr   r   r0   r1   r2   r   r     sK         "$uTYTY%?@ $ $ $ $ $ $r1   r   c                 r   t                      }| d                                                              |j                  } t	          |                                           }| d                                         } t          |j        d                   D ] }t          j	        ||         |           s dS !dS )Nr   FT)
r
   clonetodevicer   r9   rangeshaper;   equal)tensorstatetensorsis       r2   are_the_same_tensorsr     s    ED\!!$$U\22FVnn  ""GAY]]__F7=#$$  {71:v.. 	55	4r1   c                       e Zd Zd ZdS )
_RunOutputc                 0    || _         || _        || _        d S r   )
returncodestdoutstderr)r   r   r   r  s       r2   __init__z_RunOutput.__init__  s    $r1   N)r   r   r   r  r0   r1   r2   r   r     s#            r1   r   c                 ^   K   	 |                                   d {V }|r ||           nd S +r   )readline)streamcallbacklines      r2   _read_streamr     sM      __&&&&&&&& 	HTNNNNEr1   c           
      2  	K   |r#t          dd                    |                      t          j        | d         g| dd          R |t          j        j        t          j        j        |d d {V }g g dfd		t          j        t          j        t          |j	        	fd                    t          j        t          |j
        	fd	                    g|
           d {V  t          |                                 d {V           S )Nz

Running:  r   r-   )stdinr   r  env c                     |                      d                                          } |                    |            st          || |           d S d S )Nutf-8)file)decoderstriprH   print)r  sinkpipelabelquiets       r2   teez_stream_subprocess.<locals>.teeA  s_    {{7##**,,D 	*%D))))))	* 	*r1   c                 6     | t           j        d          S )Nzstdout:r  )sysr   )loutr  s    r2   r3   z$_stream_subprocess.<locals>.<lambda>J      QSZ_hAiAiAi r1   c                 6     | t           j        d          S )Nzstderr:r  )r  r  )r  errr  s    r2   r3   z$_stream_subprocess.<locals>.<lambda>K  r  r1   )timeout)r  )r  joinasynciocreate_subprocess_exec
subprocessPIPEwaitcreate_taskr  r   r  r   )
cmdr  r  r!  r  echopr   r  r  s
       `  @@@r2   _stream_subprocessr,  )  s      ,mSXXc]]+++,A	QRR  !&!&   	 	 	 	 	 	A" C
C* * * * * * ,QX7i7i7i7i7i j jkkQX7i7i7i7i7i j jkk	
           AFFHHnnnnnnc3///r1      Tr)  c           
         t          |           D ],\  }}t          |t                    rt          |          | |<   -t	          j                    }|                    t          | |||||                    }	d                    |           }
|	j	        dk    r7d                    |	j
                  }t          d|
 d|	j	         d|           |	S )N)r  r  r!  r  r*  r
  r   
'z' failed with returncode z,

The combined stderr from workers follows:
)	enumeraterF   r   strr#  get_event_looprun_until_completer,  r"  r   r  RuntimeError)r)  r  r  r!  r  r*  r   cloopresultcmd_strr  s               r2   execute_subprocess_asyncr:  R  s    #  1a 	VVCF!##D$$3CugUY]^^^ F hhsmmG16=))C C C&2C C C:@C C
 
 	

 Mr1   c                       e Zd ZdS )SubprocessCallExceptionN)r   r   r   r0   r1   r2   r<  r<  g  s        Dr1   r<  rJ   c                    t          |           D ],\  }}t          |t                    rt          |          | |<   -|t          j                                        }	 t          j        | t          j	        |          }|r't          |d          r|                    d          }|S dS # t          j        $ rE}t          dd                    |            d|j                                                   |d}~ww xY w)z
    Runs `command` with `subprocess.check_output` and will potentially return the `stdout`. Will also properly capture
    if an error occured while running `command`
    N)r  r  r  r  z	Command `r
  z$` failed with the following error:

)r1  rF   r   r2  rQ   rR   copyr%  check_outputSTDOUThasattrr  CalledProcessErrorr<  r"  output)rJ   return_stdoutr  r   r6  rC  es          r2   run_commandrF  k  s    '""    1a 	 QGAJ
{joo	(9JPSTTT 	vx(( 0w//M	 	 (   %d))ddQRQYQ`Q`QbQbdd
 
	s   A	B* *C>9A C99C>
componentsc                  l    t          t          j        t                              j        } |j        |  S )z
    Get a path within the `accelerate` package's directory.

    Args:
        *components: Components of the path to join after the package directory.

    Returns:
        `Path`: The path to the requested file or directory.
    )r   inspectgetfilerB   parentjoinpath)rG  accelerate_package_dirs     r2   path_in_accelerate_packagerN    s0     "'/*"="=>>E*!*J77r1   exception_classmsgc              #   2  K   d}	 dV  d}nu# t           $ rh}t          ||           sJ d|  dt          |                       |/|t          |          v sJ d| dt          |           d            Y d}~nd}~ww xY w|rt	          d|  d	          dS )
z
    Context manager to assert that the right `Exception` class was raised.

    If `msg` is provided, will check that the message is contained in the raised exception.
    FNTzExpected exception of type z	 but got zExpected message 'z' to be in exception but got 'r0  z but ran without issue.)	ExceptionrF   typer2  AssertionError)rO  rP  was_ranrE  s       r2   assert_exceptionrV    s       Gd d d d!_--pp/p_/p/pgklmgngn/p/pppp?#a&&==="cs"c"cZ]^_Z`Z`"c"c"c===d  ec?cccddde es    
A?AA::A?c                     t          j                    }t          j        }	 |t          _         | |i | n# t          $ r}|d}~ww xY w	 |t          _        n# |t          _        w xY w|                                S )z`
    Takes in a `func` with `args` and `kwargs` and returns the captured stdout as a string
    N)ioStringIOr  r   rR  getvalue)funcargsrI   captured_outputoriginal_stdoutrE  s         r2   capture_call_outputr_    s     kmmOjO%$
df    	 %

_
$$$$##%%%s&   6 A 
A AAA A&)F)NN)NNNFF)NNr-  FT)FNr   )yr#  rI  rX  rQ   r   r%  r  r   r\   
contextlibr   	functoolsr   pathlibr   typingr   r   r   r;   rB   r   r
   r   utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r?   rf   r<   memory_allocated_funcr   rM   DEFAULT_LAUNCH_COMMANDrY   rb   r]   rc   rg   rj   rl   ro   rq   rs   rv   rx   rz   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   anyr   r   r   TestCaser   r   r   r   r   r  r,  r:  rR  r<  r2  rF  rN  rG   rV  r_  r0   r1   r2   <module>ri     s     				 				      



   % % % % % %                                2 2 2 2 2 2 2 2                                                           @# # #* 5@KMM 1l1D    & ,+,Y\]]]      &%j%@@@8 8 8
K K K] ] ]X X Xw w wU U U\ \ \T T TV V VT T Tr r r  q q qa a ao o oe e eq q qh h hj j jq q q  a a a` ` `l l lh h hg g g_ _ _u u ux x x xc c cW W W] ] ][ [ [[ [ [Y Y YW W Wi i ir r r C				7799:;;[DYDYD[D[@[ 
  	 	 	( ( ( ( (h' ( ( (B$ $ $ $ $* $ $ $$ $ $ $ $h' $ $ $B           &0 &0bl &0 &0 &0 &0R $ fp    *	 	 	 	 	i 	 	 	 c    .8C 8D 8 8 8 8 e ei ec eT e e e e$& & & & &r1   