
    ig                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	\R                  " 5       R                  \R                  " 5       5         S SKrS SKrS SKJr  S SKJr  S SKJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S	r 1 S
kr!\RD                  RG                  SS5      S:H  r$S r%\RL                  " SSS9S 5       r'S r(S r)S r*S r+S r,S r-\R\                  S 5       r/\R\                  S 5       r0\R\                  S 5       r1 " S S5      r2\R\                  " SS9S 5       r3\R\                  " SS /S!9S" 5       r4\R\                  S# 5       r5\R\                  S$\24S% j5       r6g! \ a    Sr GN%f = f)&    N)__main__)	configure)	is_cygwin	is_darwinis_win)initialize_modgraph)pkg_archive_contents)gen_sourcefile)winutils   >   linuxwin32darwinPYI_BUILDER_CLEANUP1c                     [         R                  S U R                  5        5       5      n[        R                  nU(       a   X!;  a  [
        R                  " SU 35        ggg)a)  
Markers to skip tests based on the current platform.
https://pytest.org/en/stable/example/markers.html#marking-platform-specific-tests-with-pytest

Available markers: see pytest.ini markers
    - @pytest.mark.darwin (macOS)
    - @pytest.mark.linux (GNU/Linux)
    - @pytest.mark.win32 (Windows)
c              3   8   #    U  H  oR                   v   M     g 7fN)name).0marks     GC:\des-py\RoboSAPF\venv\Lib\site-packages\PyInstaller/utils/conftest.py	<genexpr>'pytest_runtest_setup.<locals>.<genexpr>B   s     5`L_DiiL_s   zdoes not run on N)SUPPORTED_OSESintersectioniter_markerssysplatformpytestskip)itemsupported_platformsplats      r   pytest_runtest_setupr%   8   sQ     )555`DL]L]L_5``<<Dt>&tf-.  ?    T)tryfirsthookwrapperc              #   h   #    S v nUR                  5       n[        U SUR                   3U5        g 7f)Nrep_)
get_resultsetattrwhen)r"   calloutcomereps       r   pytest_runtest_makereportr1   H   s3      G



C DD
#S)s   02c                 J    U R                   R                  5       R                  $ r   )pathresolveparentrequests    r   _get_base_dirr8   S   s    <<!(((r&   c                     [        U 5      S-  $ )Nscriptsr8   r6   s    r   _get_script_dirr<   X       !I--r&   c                     [        U 5      S-  $ )Nmodulesr;   r6   s    r   _get_modules_dirr@   ]   r=   r&   c                     [        U 5      S-  $ )Nlogsr;   r6   s    r   _get_logs_dirrC   b       !F**r&   c                     [        U 5      S-  $ )Ndatar;   r6   s    r   _get_data_dirrG   g   rD   r&   c                     [        U 5      S-  $ )Nspecsr;   r6   s    r   _get_spec_dirrJ   l   s    !G++r&   c                     [        U 5      $ )z8
Return the directory where the test spec-files reside.
)rJ   r6   s    r   spec_dirrL   p   s    
 !!r&   c                     [        U 5      $ )z5
Return the directory where the test scripts reside.
)r<   r6   s    r   
script_dirrN   x   s    
 7##r&   c                     U R                   R                  SS  n[        U 5      U-  nUS-  n[        R                  " X45        U$ )N   rF   )function__name__rG   shutilcopytree)r7   tmp_path	test_namesource_data_dirtmp_data_dirs        r   data_dirrY      sI       ))!"-I $G,y8Of$L
OOO2r&   c                   \    \ rS rSrS rS rS rS r SS jrS r	S	 r
S
 rS rS rS rSrg)
AppBuilder   c                 j    Xl         X l        X0l        Xl        US-  U l        US-  U l        SU l        g )NdistbuildF)	_tmp_path_request_mode	_spec_dir	_dist_dir
_build_dir_is_spec)selfrU   r7   bundle_modes       r   __init__AppBuilder.__init__   s5    ! 
!!F*"W,r&   c                 p    Sn[        U R                  5      U-  nSU l        U R                  " U/UQ70 UD6$ )zE
Test a Python script that is referenced in the supplied .spec file.
T)rJ   ra   rf   test_script)rg   specfileargskwargs__tracebackhide__s        r   	test_specAppBuilder.test_spec   s?     ! /(::4:6::r&   c                     Sn[        U R                  XR                  S5      5      nUS	 U R                  " U/UQ70 UD6$ )a  
Test a Python script given as source code.

The source will be written into a file named like the test-function. This file will then be passed to
`test_script`. If you need other related file, e.g., as `.toc`-file for testing the content, put it at at the
normal place. Just mind to take the basnename from the test-function's name.

:param script: Source code to create executable from. This will be saved into a temporary file which is then
               passed on to `test_script`.

:param test_id: Test-id for parametrized tests. If given, it will be appended to the script filename, separated
                by two underscores.

All other arguments are passed straight on to `test_script`.
Ttest_id)r
   r`   
setdefaultrl   )rg   sourcern   ro   rp   
scriptfiles         r   test_sourceAppBuilder.test_source   sH      !#DNNF<M<Mi<XY
9
<T<V<<r&   c                 |    [        SU SU 3[        R                  S9  [        SU SU 3[        R                  S9  g )Nz[APP-BUILDER:z] )file)printr   stdoutstderr)rg   	step_namemessages      r   _display_messageAppBuilder._display_message   s:     	i[7)43::Fi[7)43::Fr&   Nc                 N   SnU(       a  [         c  [        R                  " S5        Uc  / nUc  / nU(       a%  U R                  (       d  UR	                  SU/5        O?[
        R                  R                  [
        R                  R                  U5      5      S   n[
        R                  R                  U5      (       d  [        U R                  5      U-  n[        U5      U l        [
        R                  R                  U R                  5      (       d   SU R                  < S35       eU R                  SS	5        U R!                  US
9(       d  [        R"                  " SU S35        U R                  SS5        U R$                  " U4XEUS.UD6  U R                  SS5        g)a  
Main method to wrap all phases of testing a Python script.

:param script: Name of script to create executable from.
:param pyi_args: Additional arguments to pass to PyInstaller when creating executable.
:param app_name: Name of the executable. This is equivalent to argument --name=APPNAME.
:param app_args: Additional arguments to pass to
:param runtime: Time in seconds how long to keep executable running.
:param toc_log: List of modules that are expected to be bundled with the executable.
TNz4Interactive tests require psutil for proper cleanup.z--namer   zScript z not found.zTEST-SCRIPTzStarting build...)rn   zBuilding of  failed.z)Build finished, now running executable...)rn   runtimerun_from_pathzRunning executable finished.)psutilr    r!   rf   extendosr3   splitextbasenameisabsr<   ra   strscriptexistsr   _test_buildingfail_test_executables)	rg   r   pyi_argsapp_nameapp_argsr   r   ro   rp   s	            r   rl   AppBuilder.test_script   sS    ! v~KKNOHH==8 45 ww''(8(8(@A!DH ww}}V$$$T]]3f<F&kww~~dkk**Pgdkk_K,PP*m-@A"""1KK,vhh78m-XYxohWdohnom-KLr&   c                     SnU R                  U5      nU/ :w  d   S5       eU H  n[        R                  R                  [        R                  R	                  U5      5      S   S-   n	[        U R                  5      U	-  n	U	R                  5       (       a0  U R                  X5      (       d  [        R                  " SU S35        U R                  XXC5      n
XR                  SS5      :w  d  M  [        R                  " SU S	U
 S
35        M     g)a0  
Run created executable to make sure it works.

Multipackage-tests generate more than one exe-file and all of them have to be run.

:param args: CLI options to pass to the created executable.
:param runtime: Time in seconds how long to keep the executable running.

:return: Exit code of the executable.
TzNo executable file was found.r   z.toczMatching .toc of r   retcodezRunning exe z failed with return-code .N)_find_executablesr   r3   r   r   rC   ra   r   _examine_executabler    r   _run_executableget)rg   r   rn   r   r   ro   rp   exesexetoc_logr   s              r   r   AppBuilder._test_executables   s     !%%d+rz:::zCgg&&rww'7'7'<=a@6IG#DMM2W<G~~//==KK"3C5 AB**3mMG**Y22l3%/H	QRST r&   c                 
   / n[        U R                  U-  U-  5      n[        U R                  U-  5      nUUUS-   US-   /n[        (       a  U Vs/ s H  ofS-   PM	     nn[        (       a5  [        U R                  U S3-  S-  S-  U-  5      nUR	                  U5        U HW  n[
        R
                  " U5       H:  n	[        R                  R                  U	5      (       d  M)  UR	                  U	5        M<     MY     U$ s  snf )a3  
Search for all executables generated by the testcase.

If the test-case is called e.g. 'test_multipackage1', this is searching for each of 'test_multipackage1.exe'
and 'multipackage1_?.exe' in both one-file- and one-dir-mode.

:param name: Name of the executable to look for.

:return: List of executables
z_?z.exez.appContentsMacOS)	r   rd   r   r   appendglobr   r3   isfile)
rg   r   r   	onedir_pt
onefile_ptpatternsptapp_bundle_ptpatternprogs
             r   r   AppBuilder._find_executables  s     -45	$./

 6.67hVhH79D6 > Kg UX\ \]MOOM*G		'*77>>$''KK% +    8s   D c                    [         R                  " [        R                  5      nSUS'   US	 [        (       a5  [        R
                  R                  [        R                  " 5       5      US'   [        (       a$  [        R
                  R                  SS/5      US'   [        (       a$  [        R
                  R                  / SQ5      US'   UnU(       a  [        U R                  5      n[        R                  R                  U5      n[        R
                  R                  UR                  SS5      [        R                  R!                  U5      /5      US'   Oj[        R                  R!                  U5      n[        R                  R                  [        R"                  [        R                  R                  U5      5      nU/U-   nU R%                  X&XWU5      $ )ze
Run executable created by PyInstaller.

:param args: CLI options to pass to the created executable.
 PATHz/usr/local/bin/usr/bin)r   z/binz	/usr/sbinz/sbin)copydeepcopyr   environr   pathsepjoinr   get_system_pathr   r   r   r`   r3   r   r   dirnamecurdir_run_executable_)	rg   r   rn   r   r   prog_envexe_pathprog_cwd	prog_names	            r   r   AppBuilder._run_executable6  sO    ==,V6!zzx/G/G/IJHV9!zz0@*/MNHV 9  "zz/YZHV 4>>*H((.I!zzVR0H"''//Z^J_/`aHV wwt,HRYY0@0@0FGI{T! $$TXQQr&   c           	         [         c  [        R                  O[         R                  nU R                  SSU< SU< 35        [        R                  " 5       nU" XX4S9nS =p U(       a  UO[
        nUR                  US9u  p[        R                  " 5       U-
  nUR                  nU R                  SSUS SU S	35        U R                  SSU 35        U$ ! [         c  [        R                  O[         R                  [        R                  4 Ga    U(       a  U R                  SS
U S35        SnOU R                  SSW S35        Sn[         c   U R                  SS5        UR                  5         UR                  SS9u  pU R                  SS5         N! [        R                   az     U R                  SS5        UR                  5         UR                  SS9u  pU R                  SS5          GN8! [        R                   a    U R                  SS5           GNcf = ff = fU R                  SS5        [        UR                  SS95       Hr  n[        R                  " [         R                  5         U R                  SSUR                    S35        UR                  5         S S S 5        Mb  ! , (       d  f       Mq  = f    U R                  SSUR                    S35        UR                  SS9u  pU R                  SS5         GNR! [         R                  [        R                  4 a    U R                  SS5        [        R                  " [         R                  5         UR                  5         S S S 5        O! , (       d  f       O= f UR                  SS9u  pU R                  SS5          GN! [         R                  [        R"                  4 a    U R                  SS5           GN:f = ff = ff = f)NzRUN-EXEzRunning z, args: )
executableenvcwd)timeoutz Process exited on its own after z.1fz seconds with return code r   z%Process reached expected run-time of z	 seconds.r   z+Timeout while running executable (timeout: z
 seconds)!   z/Stopping the process using Popen.terminate()...rP   zProcess stopped.z*Stopping the process using Popen.kill()...z6Failed to stop the process (or its child process(es))!zStopping child processes...T)	recursivezStopping child process z...zWaiting for main process (z) to stop...zProcess stopped on its own.zDone! Return code: )r   
subprocessPopenr   time_EXE_TIMEOUTcommunicate
returncodeTimeoutExpired	terminatekilllistchildren
contextlibsuppressNoSuchProcesspidTimeoutExpire)rg   rn   r   r   r   r   popen_implementation
start_timeprocessr}   r~   r   elapsedr   child_processs                  r   r   AppBuilder._run_executable_a  s   39>z//v|| 	i8H<xx)PQYY[
&th] F	s!(glG$000ANFiikJ.G((G!!=gc]JdeldmmnoF 	i+>wi)HIE /5n
))6CXCXZdZsZsBt >	s %%i3XY`Xaaj1kl %%i3^_f^ggq1rs~s)))5fg%%'%,%8%8%8%CNF)))5GH!00 s	s--i9ef *1)<)<Q)<)G--i9KLL%44 s--i9qrrss  %%i1NO%)'*:*:T*:*J%KM#,,V-A-AB--i;RS`SdSdReeh9ij%**, CBBB &Ls)))7QRYR]R]Q^^j5kl%,%8%8%8%CNF)))5RS--z/H/HI 
s)))5ab#,,V-A-AB CBBs)0)<)<Q)<)G--i9KLL"11:3K3KL s--i9qrrs
si>	ss   "AC A;PAFH(/AG84P8&H$H(P#H$$H((AP<1J7-
P7
K
PALAO?,N=	O?
NO?#N?;P?6O;5O?6P:O;;O??Pc                    U R                   (       a/  S[        U R                  5      S[        U R                  5      SS/nOSSS[        U R                  5      S[        U R                  5      S[        U R                  5      S[        [        U R                  5      5      SS/nU R                  S	:X  a  UR                  S
5        O!U R                  S:X  a  UR                  S5        U R                  /UQUQn[        R                  " 5       n[        U R                  5      US'   [        R                  " X45        SnUS:H  $ )z
Run building of test script.

:param args: additional CLI options for PyInstaller.

Return True if build succeeded False otherwise.
z
--distpathz
--workpathz--log-levelINFOz--debug=bootloaderz--noupxz
--specpathz--pathonedirz--onedironefilez	--onefilecachedirr   )rf   r   rd   re   rc   r@   ra   rb   r   r   r   
get_configr`   pyi_mainrun)rg   rn   default_argsr   
PYI_CONFIGr   s         r   r   AppBuilder._test_building  s    ==c$..1c$//2vL %c$..1c$..1c$//2#.t}}=>vL zzX%##J/y(##K0 KK6,66))+
!$T^^!4
:X*!|r&   c           	         U R                  SS[        U5      < 35        [        U5      n[        USSS9 n[	        UR                  5       5      nSSS5        WR                  5         / nU Hk  nU H;  n[        R                  " Xx5      (       d  M   U R                  SSU< SU< 35          MB     UR                  U5        U R                  SS	U< 35        Mm     U(       + $ ! , (       d  f       N= f)
zc
Compare log files (now used mostly by multipackage test_name).

:return: True if .toc files match
zEXAMINE-EXEzMatching against TOC log: rzutf-8)encodingNzEntry found: z --> zEntry MISSING: )
r   r   r	   openevalreadsortrematchr   )	rg   r   r   
fname_listfpattern_listmissingr   fnames	            r   r   AppBuilder._examine_executable  s     	m/I#g,IY-Z[)#.
'31Q>L 2 	#G#88G++))-=SXY^Xa9bc $ w'%%mwk5RS $ {! 21s   C""
C0)re   rd   rf   rb   ra   rc   r`   r   )NNNNF)rR   
__module____qualname____firstlineno__ri   rq   rx   r   rl   r   r   r   r   r   r   __static_attributes__ r&   r   r[   r[      sJ    ;=,G `e,M\U4#J)RVXt)Vr&   r[   session)scopec                  n    SS K Jn   U R                  R                  U R                  5        [        5         g )Nr   )PyInstaller.loglogloggersetLevelDEBUGr   )loggings    r   pyi_modgraphr    s#     &NNGMM*r&   r   r   )paramsc              #     #    UR                  S[        R                  S   5        UR                  S 5        UR	                  U 5        UR                  SS/ 05        [        XUR                  5      v   [        (       ax  UR                  R                  R                  (       aR  UR                  R                  R                  (       a,  U R                  5       (       a  [        R                  " U SS9  g g g g g 7fNr   zPyInstaller.config.CONFpathexT)ignore_errors)setenvr   r   syspath_prependchdirr,   r[   param_PYI_BUILDER_CLEANUPnode	rep_setuppassedrep_callr   rS   rmtree)rU   monkeypatchr7   r  s       r   pyi_builderr    s      vrzz&12%h 1Hb>B
X
66  6 6 = =',,BWBWB^B^??MM($7  C_ =s   C6C8c              #     #    UR                  S[        R                  S   5        UR                  U 5        UR	                  S 5        UR                  SS/ 05        [        XS 5      v   [        (       ax  UR                  R                  R                  (       aR  UR                  R                  R                  (       a,  U R                  5       (       a  [        R                  " U SS9  g g g g g 7fr
  )r  r   r   r  r  r,   r[   r  r  r  r  r  r   rS   r  )rU   r7   r  r  s       r   pyi_builder_specr  "  s      vrzz&12h% 1Hb>B
X
--  6 6 = =',,BWBWB^B^??MM($7  C_ =s   C,C.r  c              #   &   #    S nXl         U v   g7f)z=A pyi_builder equivalent for testing --windowed applications.c                 H    [         R                  " U/U QX#US9R                  $ )N)r   r   r   )r   r   r   )rn   r   r   r   r   s        r   r   .pyi_windowed_builder.<locals>._run_executable_>  s$    ~~x/$/XU\]hhhr&   N)r   )r  r   s     r   pyi_windowed_builderr  6  s     i $4 
s   )7r   r   r   r  r   r   rS   r   r   r   	getLogger
addHandlerNullHandlerr   ModuleNotFoundErrorr    PyInstallerr   r   r   PyInstaller.compatr   r   r   PyInstaller.depend.analysisr   PyInstaller.archive.readersr	   PyInstaller.utils.testsr
   PyInstaller.utils.win32r   r   r   r   r   r  r%   hookimplr1   r8   r<   r@   rC   rG   rJ   fixturerL   rN   rY   r[   r  r  r  r  r   r&   r   <module>r+     s       	 	   
 
      w224 5  , ! ; ; ; < 2 , -zz~~&;SASH /  $D1* 2*)
.
.
+
+
, " " $ $  ,e eT i  ! ),-8 .8( 8 8& j  o  Fs   E7 7FF