
    "j                     j   d Z ddlZddlmZ ddlZddlZddlZddlmZm	Z	 ej                  j                  dd       ddlmZ ddlmZ ddlmZ d	d
lmZ d	dlmZmZmZmZ dZedd dz   edd z   ZdZ G d dej8                        Z G d dej8                        Zedk(  r ej@                          yy)z)Unit tests for the `DeviceAsync` class.

    N)asynccontextmanager)	mock_openpatchz..)ClientAsync)Protocol)	SyncAsync   )awaiter)FakeStreamReaderFakeStreamWriterasync_mock_openasync_patchsl   PNG

   IHDR   
   
   2Ͻ   sBIT|d   	pHYs  a  a?i   IDATc`   i    IENDB`      !   Ohayou sekai.
Good morning world!c                       e Zd Zed        Zed        Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zy
)
TestDevicec                 T  K   t               | _        t        dt               t	               f      5  t        dj                  t              g d      5  | j                  j                  d       d {   | _        d d d        d d d        y 7 # 1 sw Y   xY w# 1 sw Y   y xY ww)Nasyncio.open_connectionreturn_value{}.FakeStreamReader.read)   OKAYs   000bs   serial testside_effectserial)r   clientr   r   r   format__name__deviceselfs    `/var/www/oz-panel.ru/ozpay-pub/venv/lib/python3.12/site-packages/test_async/test_device_async.pysetUpzTestDevice.setUp   s     !m2BRBTVfVhAij 	A7>>xHVxy A$(KK$6$6x$@@A	A 	A@A A	A 	AsF   /B(#BB3B4	B=B	B(BB	BB%!B(c                 L  K   t        dt               t               f      5  t        dj                  t              g d      5  | j                  | j                  j                  d       d {   d       d d d        d d d        y 7 # 1 sw Y   xY w# 1 sw Y   y xY ww)Nr   r   r   )r   r   s   test    r   r   TESTtest)r   r   r   r   r   assertEqualr    shellr!   s    r#   
test_shellzTestDevice.test_shell'   s     2BRBTVfVhAij 	J7>>xHV  A J  t{{'8'8'@!@&IJ	J 	J!@J J	J 	JsF    B$#B*B/B
0	B9B	B$
BB	BB!B$c                   K   t        dt               t               f      5  t        dj                  t              d      5  | j                  t              5  | j                  | j                  j                  d       d {   d       d d d        d d d        d d d        y 7 "# 1 sw Y   xY w# 1 sw Y    xY w# 1 sw Y   y xY ww)Nr   r   r      FAILr'   r(   )
r   r   r   r   r   assertRaisesRuntimeErrorr)   r    r*   r!   s    r#   test_shell_errorzTestDevice.test_shell_error-   s     2BRBTVfVhAij 	N7>>xHW^_ N&&|4 N$$4;;+<+<V+D%DfMNN	N 	N &EN NN N	N 	Ns^    C!C B4*B(B&	B(B4C 	C&B((B1-B44B=	9C  C	Cc           	        K   t        dt               t               f      5  t        dj                  t              ddt
        ddg      5  | j                  | j                  j                          d {   t
               d d d        d d d        t        dt               t               f      5  t        dj                  t              ddt        ddg      5  | j                  | j                  j                          d {   t
               d d d        d d d        y 7 # 1 sw Y   xY w# 1 sw Y   xY w7 8# 1 sw Y   .xY w# 1 sw Y   y xY ww)Nr   r   r   r   r&   r   )
r   r   r   r   r   	PNG_IMAGEr)   r    	screencapPNG_IMAGE_NEEDS_REPLACINGr!   s    r#   test_screencapzTestDevice.test_screencap4   sW    2BRBTVfVhAij 	K7>>xHW^`girtw  zA  WB  C K  t{{'<'<'>!>	JK	K 2BRBTVfVhAij 	K7>>xHW^`g  jC  EH  JQ  WR  S K  t{{'<'<'>!>	JK	K 	K "?K K	K 	K "?K K	K 	Ks    E*D2)D&5D$6D&D2'E2*E)E D>E E	E$D&&D/	+D22D;7E>E  E		EEEc                   K   t        dd      5  | j                  t              5  | j                  j	                  dd       d {    d d d        | j                  t              5  t        d      }|j	                  ddd       d {    d d d        d d d        y 7 Y# 1 sw Y   XxY w7 ## 1 sw Y   "xY w# 1 sw Y   y xY ww)Nos.path.existsFr   srcdestUnusedmode)r   r.   FileNotFoundErrorr    pushr   )r"   syncs     r#   test_push_file_not_foundz#TestDevice.test_push_file_not_found>   s     #%8 	7""#45 6kk&&uf5556 ""#45 7 *iivv6667		7 	756 6
 77 7		7 	7so   CB< B"B B"B<("B0
B.B0B<	C B""B+	'B<.B00B9	5B<<CCc                   K   d }d}t        dd      5  t        dd      5  t        dt        j                  d            5  t        d	t        t                    5  t        d
t               t               f      5  t        dj                  t              dddt        ddg      5  | j                  j                  dd|       d {    d d d        d d d        d d d        d d d        d d d        d d d        y 7 5# 1 sw Y   4xY w# 1 sw Y   8xY w# 1 sw Y   <xY w# 1 sw Y   @xY w# 1 sw Y   DxY w# 1 sw Y   y xY ww)Nc                       y )N )argskwargss     r#   progressz&TestDevice.test_push.<locals>.progressJ   s    r&   r   r7   Tr   os.path.isfilezos.stat)
{   rG   rG   rG   rG   rG   rG   rG   rG   rG   ppadb.sync_async.aiofiles.openr   r   r   r&   r   r8   r9   )rE   )r   osstat_resultr   FILEDATAr   r   r   r   r   r4   r    r=   )r"   rE   filedatas      r#   	test_pushzTestDevice.test_pushH   s    	 9#$7 	M?O^b9c 	Mejkt  DF  DR  DR  S^  D_  f` 	M  bg  hH  JY  Zb  Jc  bd 	M6FVFXZjZlEmn M !;!B!B8!L[bdkmt  wP  RU  W^  [_  ` M++**5&8*LLLMM	M 	M 	M 	M 	M MM MM M	M 	M 	M 	M 	M 	M 	M 	Ms   ED?!D3D' D	>+D)"DDDDD	 D'(D30D?8	EDDDDD	D$ D''D0,D33D<	8D??EEc                   K   t        dd      5  t        dd      5  t        dd      5  t        ddd	g      5  t        d
      5  t        d      5  | j                  j                  dd       d {    d d d        d d d        d d d        d d d        d d d        d d d        y 7 5# 1 sw Y   4xY w# 1 sw Y   8xY w# 1 sw Y   <xY w# 1 sw Y   @xY w# 1 sw Y   DxY w# 1 sw Y   y xY ww)Nr7   Tr   rF   Fzos.path.isdirzos.walk)root1dirs1files1)root2dirs2files2z$ppadb.device_async.DeviceAsync.shellz$ppadb.device_async.DeviceAsync._pushr8   r9   )r   r   r    r=   r!   s    r#   test_push_dirzTestDevice.test_push_dirS   s    #$7 	6?O^c9d 	6fkl{  KO  gP 	6  RW  Xa  qM  Ok  pl  Rm 	6CD 6kRxFy 6kk&&uf5556 6	6 	6 	6 	6 	656 6 6 6	6 	6 	6 	6 	6 	6 	6 	6s   C4C(CCC	B8 B,4B*5B,9B8C		CCC(!	C4*B,,B51B88C=C	C	CCCC%	!C((C1-C4c                   K   t        dt               t               f      5  t        dj                  t              dddt        j                  d      dddg	      5  t        d
t        t                    5  | j                  j                  dd       d {    d d d        d d d        d d d        y 7 # 1 sw Y   xY w# 1 sw Y    xY w# 1 sw Y   y xY ww)Nr   r   r   r   s   DATA      TEST   DONEr   rH   r8   r9   r   r   r   r   r   r   _little_endianr   r   rK   r    pullr!   s    r#   	test_pullzTestDevice.test_pullY        2BRBTVfVhAij 	:7>>xHW^`gipr{  sK  sK  LM  sN  PW  Y`  bi  Wj  k :;_X=VW :++**5&999::	: 	: :: :: :	: 	:^    C;CC7 B7B5
B7C$C,	C5B77C <CC	CCCc                   K   t        dt               t               f      5  t        dj                  t              dddt        j                  d      dddg	      5  t        d
t        t                    5  | j                  j                  dd       d {    d d d        d d d        d d d        y 7 # 1 sw Y   xY w# 1 sw Y    xY w# 1 sw Y   y xY ww)Nr   r   r   r   r-   rW   rX   rY   r   rH   r8   r9   rZ   r!   s    r#   test_pull_failzTestDevice.test_pull_fail`   r^   r_   N)r   
__module____qualname__r
   r$   r+   r0   r5   r?   rM   rU   r]   ra   rB   r&   r#   r   r      s    A A J J
 N N K K 7 7 M M 6 6
 : : : :r&   r   c                       e Zd Zd Zy)TestProtocolc           	          t        d      D ]:  }| j                  |t        j                  t        j                  |                   < y )N   )ranger)   r   decode_lengthencode_length)r"   is     r#   test_encode_decode_lengthz&TestProtocol.test_encode_decode_lengthi   s=    w 	SAQ 6 6x7M7Ma7P QR	Sr&   N)r   rb   rc   rl   rB   r&   r#   re   re   h   s    Sr&   re   __main__)!__doc__asyncio
contextlibr   rI   sysunittestunittest.mockr   r   pathinsertppadb.client_asyncr   ppadb.protocolr   ppadb.sync_asyncr   async_wrapperr
   patchersr   r   r   r   r2   r4   rK   TestCaser   re   r   mainrB   r&   r#   <module>r}      s   
  * 	 
  * 4  * # & " V V I	%bqME1IabMA 0G:"" G:TS8$$ S zHMMO r&   