
    )j10                     x    d dl Zd dlmc mZ d dlZd dlZd dlZd dl	m
Z
 d	dZd Z G d d      Z G d d      Zy)
    N)Pathc                 \   t        j                         }t        t        |      | z        }|d}d}d}d}t	        ||z        }g }	t        |      D ]e  }
t	        t        j                  dt        j                  z  dz  |
z  |z        dz  d	z        }|	j                  t        j                  d
|             g dj                  |	      }t        |      }d|z   }t               }|dz  }|t        j                  d|      z  }|dz  }|dz  }|t        j                  dd      z  }|t        j                  dd      z  }|t        j                  d|      z  }|t        j                  d|      z  }|t        j                  d||z  |z  dz        z  }|t        j                  d||z  dz        z  }|t        j                  d|      z  }|dz  }|t        j                  d|      z  }||z  }t        |      }t!        |d      5 }|j#                  |       ddd       |S # 1 sw Y   |S xY w)z;Create a temporary WAV file for testing. Name is preserved.ND        g      ?   i  g333333?i  z<h    $   s   RIFFz<Is   WAVEs   fmt z<H   s   datawb)tempfile
gettempdirstrr   intrangemathsinpiappendstructpackjoinlen	bytearraybytesopenwrite)namecontenttmpdirpathsrbitschannelsdurationnum_samplessamplesivaldata	data_size	file_sizebuffs                    5/home/david/assistant/kitmaker/tests/test_kitmaker.pycreate_test_wav_filer0      s	     "FtF|d"#D"x-({#Adhhq477{S014r9:S@5HICNN6;;tS12 $ xx I	N	kwv{{4++wwv{{4$$v{{4##v{{4**v{{4$$v{{4h!5!:;;v{{4DA!566v{{4&&wv{{4++t*	dD	Q	 
K 
Ks   H!!H+c                 V    	 t        |       j                          y# t        $ r Y yw xY w)zClean up temporary WAV file.N)r   unlinkFileNotFoundError)r!   s    r/   cleanup_test_wav_filer4   1   s)    T
 s    	((c                   X    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)TestFrontendz-Playwright interaction tests for Kitmaker UI.c                 ^   |j                  d      }|j                  } |       }d}||k(  }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}}|j                  d	      }	|	j                  } |       }|sd
dt	        j
                         v st        j                  |	      rt        j                  |	      ndt        j                  |      t        j                  |      dz  }
t        t        j                  |
            d x}}y )Nh1zRazzmatazz Kitmaker==)zK%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.text_content
}()
} == %(py7)sheaderpy0py2py4py7assert %(py9)spy9z.empty-cardzEassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.is_visible
}()
}pingr=   r>   r?   )locatortext_content
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation
is_visible)selfpager;   @py_assert1@py_assert3@py_assert6@py_assert5@py_format8@py_format10rC   @py_format5s              r/   test_page_loadszTestFrontend.test_page_loads<   s   d#""="$=(==$(=====$(=======v===v==="===$===(========||M*         t   t             r	   c                    |j                  d      }|j                  } |       }d}||k(  }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}}y )	Nz.padr   r9   )zD%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.count
}()
} == %(py7)spadsr<   rA   rB   )
rE   countrG   rH   rI   rJ   rK   rL   rM   rN   )	rP   rQ   r[   rR   rS   rT   rU   rV   rW   s	            r/   test_pad_grid_rendersz"TestFrontend.test_pad_grid_rendersC   s    ||F#zz z| q |q    |q      t   t   z   |   q       r	   c                    |j                  d      }|j                  d      }t        |j                               D cg c]!  }|j                  |      j	                         # }}d}||v }|st        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }dd	|iz  }	t        t        j                  |	            d x}}d
D ]  }
|
|v }|st        j                  d|fd|
|f      dt        j                         v st        j                  |
      rt        j                  |
      nddt        j                         v st        j                  |      rt        j                  |      nddz  }dd|iz  }t        t        j                  |            d } y c c}w )N#genrePresetoptionu   — Select —inz%(py1)s in %(py3)stextspy1py3assert %(py5)spy5)808909HouseTechnozHip-Hopz%(py0)s in %(py2)spresetr=   r>   assert %(py4)sr?   )rE   r   r\   nthrF   rG   rH   rL   rI   rJ   rK   rM   rN   )rP   rQ   selectoptionsr(   rd   @py_assert0@py_assert2@py_format4@py_format6ro   rR   @py_format3rX   s                 r/   test_preset_dropdown_populatedz+TestFrontend.test_preset_dropdown_populatedG   s$   n-..*8=gmmo8NO8N1Q,,.8NO(5((((5(((((((((5(((5(((((((BFU?"""6U""""""6"""6""""""U"""U""""""" C Ps   &G!c           
         |\  }}t        ||      }	 |j                         5 }|j                  d      j                          d d d        j                  }|j                  |g       |j                  d      j                  d       |j                  }d}	 ||	      }
|
j                  } |       }d}||k\  }|st        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      t        j                  |
      t        j                  |      t        j                  |      t        j                  |      d	z  }d
d|iz  }t        t        j                  |            d x}x}	x}
x}x}x}}t!        |       y # 1 sw Y   xY w# t!        |       w xY w)N#fileBtn.sample-card  timeoutr   >=z%(py10)s
{%(py10)s = %(py8)s
{%(py8)s = %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.locator
}(%(py4)s)
}.count
}()
} >= %(py13)srQ   r=   r>   r?   py6py8py10py13assert %(py15)spy15)r0   expect_file_chooserrE   clickvalue	set_fileswait_forr\   rG   rH   rI   rJ   rK   rL   rM   rN   r4   rP   rQ   
sample_wavr   r*   	temp_filefc_infofile_chooserrR   rS   rU   @py_assert7@py_assert9@py_assert12@py_assert11@py_format14@py_format16s                    r/   test_upload_single_filez$TestFrontend.test_upload_single_fileO   sX   
d(t4			-))+wZ(..0 ,"==L""I;/LL(11$1?<<<<</</55<57<1<71<<<<71<<<<<<4<<<4<<<<<<<<<</<<<5<<<7<<<1<<<<<<<<!), ,+ "),s#   G   GFG  GG   G-c           
      .   dd l }dd l}|\  }}|\  }}	 |j                         }
|j                  j	                  |
|      }|j                  j	                  |
|      }t        |d      5 }|j                  |       d d d        t        |d      5 }|j                  |	       d d d        	 |j                         5 }|j                  d      j                          d d d        j                  }|j                  |
g       |j                  d      j                  j                  d       |j                  d       |j                  }d} ||      }|j                  } |       }d}||k(  }|st!        j"                  d	|fd
||f      dt%        j&                         v st!        j(                  |      rt!        j*                  |      ndt!        j*                  |      t!        j*                  |      t!        j*                  |      t!        j*                  |      t!        j*                  |      t!        j*                  |      dz  }dd|iz  }t-        t!        j.                  |            d x}x}x}x}x}x}}|j                  d      j1                         }d}||v }|st!        j"                  d|fd||f      t!        j*                  |      dt%        j&                         v st!        j(                  |      rt!        j*                  |      nddz  }dd|iz  }t-        t!        j.                  |            d x}}dd l}|j5                  |
d       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# dd l}|j5                  |
d       w xY w)Nr   r   z
#folderBtnr}   r~   r     r   r9   z%(py10)s
{%(py10)s = %(py8)s
{%(py8)s = %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.locator
}(%(py4)s)
}.count
}()
} == %(py13)srQ   r   r   r   z#sampleCountz	2 samplesra   rc   
count_textre   rh   ri   T)ignore_errors)r   osmkdtempr!   r   r   r   r   rE   r   r   r   firstr   wait_for_timeoutr\   rG   rH   rI   rJ   rK   rL   rM   rN   rF   shutilrmtree)rP   rQ   r   sample_wav_kickr   r   name1data1name2data2r    tmp1tmp2r.   r   r   rR   rS   rU   r   r   r   r   r   r   r   ru   rv   rw   rx   r   s                                  r/   test_folder_uploadzTestFrontend.test_folder_upload_   su   !u&u!!!#ww||FE*ww||FE*$GGEN $GGEN 	6))+w\*002 ,"==L""F8,LL(..777E!!#&<<<<</</55<57<1<71<<<<71<<<<<<4<<<4<<<<<<<<<</<<<5<<<7<<<1<<<<<<<<n5BBDJ,;*,,,,;*,,,;,,,,,,*,,,*,,,,,,,MM&M5%  ,+ MM&M5s=   (MM!)M; 9 M.I#M; M!M+.M83M; ;Nc           
      B   |\  }}|\  }}t        ||      }t        ||      }		 |j                         5 }
|j                  d      j                          d d d        
j                  }|j                  ||	g       |j                  d      j                  j                  d       |j                  d       |j                  }d} ||      }|j                  } |       }d}||k(  }|st        j                  d|fd||f      d	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      d
z  }dd|iz  }t!        t        j"                  |            d x}x}x}x}x}x}}|j                  d      j%                  d       |j                  d       |j                  }d} ||      }|j                  } |       }d}||k(  }|st        j                  d|fd||f      d	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      d
z  }dd|iz  }t!        t        j"                  |            d x}x}x}x}x}x}}t'        |       t'        |	       y # 1 sw Y   'xY w# t'        |       t'        |	       w xY w)Nr|   r}   r~   r   r   r   r9   r   rQ   r   r   r   z#searchInputkick   r   )r0   r   rE   r   r   r   r   r   r   r\   rG   rH   rI   rJ   rK   rL   rM   rN   fillr4   )rP   rQ   r   r   r   r   r   r   
temp_file1
temp_file2r   r   rR   rS   rU   r   r   r   r   r   r   s                        r/   test_search_filterzTestFrontend.test_search_filter|   s~   !u&u)%7
)%7
	.))+wZ(..0 ,"==L""J
#;<LL(..777E!!#&<<<<</</55<57<1<71<<<<71<<<<<<4<<<4<<<<<<<<<</<<<5<<<7<<<1<<<<<<<<LL(--f5!!#&<<<<</</55<57<1<71<<<<71<<<<<<4<<<4<<<<<<<<<</<<<5<<<7<<<1<<<<<<<<!*-!*- ,+ "*-!*-s#   N  M9LN 9N>N Nc           
      $   |\  }}t        ||      }	 |j                         5 }|j                  d      j                          d d d        j                  }|j                  |g       |j                  d       |j                  d      j                  }|j                          |j                  d       |j                  d      }	|	j                  }
 |
       }d}||k\  }|st        j                  d|fd||f      d	t        j                         v st        j                  |	      rt        j                  |	      nd	t        j                  |
      t        j                  |      t        j                  |      d
z  }dd|iz  }t        t        j                   |            d x}
x}x}}|j                  }
d} |
|      }|j                  } |       }d}||k\  }|st        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |
      t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                   |            d x}
x}x}x}x}x}}t#        |       y # 1 sw Y   xY w# t#        |       w xY w)Nr|   r   .sel,  .pad.filledr   r   )zD%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.count
}()
} >= %(py7)sfilled_padsr<   rA   rB   z.sel.onr   rQ   r   r   r   r0   r   rE   r   r   r   r   r   r\   rG   rH   rI   rJ   rK   rL   rM   rN   r4   )rP   rQ   r   r   r*   r   r   r   selr   rR   rS   rT   rU   rV   rW   r   r   r   r   r   r   s                         r/   "test_assign_sample_to_pad_by_clickz/TestFrontend.test_assign_sample_to_pad_by_click   s   
d(t4		-))+wZ(..0 ,"==L""I;/!!#&,,v&,,CIIK!!#&,,}5K$$+$&+!+&!++++&!++++++;+++;+++$+++&+++!+++++++<<7	7<	*7*007027a72a77772a77777747774777<777	777*77707772777a77777777!), ,+ "),s#   L  K5J&L 5K?:L Lc           
         |\  }}t        ||      }	 |j                         5 }|j                  d      j                          d d d        j                  }|j                  |g       |j                  d       |j                  d      j                  j                          |j                  d       |j                  d      j                  j                          |j                  d       |j                  }d}	 ||	      }
|
j                  } |       }d}||k(  }|st        j                  d	|fd
||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      t        j                  |
      t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                   |            d x}x}	x}
x}x}x}}t#        |       y # 1 sw Y   xY w# t#        |       w xY w)Nr|   r   r   r   z.remover   r   r   r9   r   rQ   r   r   r   r   r   s                    r/   test_remove_sample_from_padz(TestFrontend.test_remove_sample_from_pad   s   
d(t4		-))+wZ(..0 ,"==L""I;/!!#&LL &&,,.!!#&LL#))//1!!#&<<;;<.;.44;46;!;6!;;;;6!;;;;;;4;;;4;;;<;;;;;;.;;;4;;;6;;;!;;;;;;;;!), ,+ "),s#   I  H7G(I 7I<I Ic                 `   |j                  d      j                  d       |j                  d       |j                  d      }g d}||k(  }|st	        j
                  d|fd||f      dt        j                         v st	        j                  |      rt	        j                  |      ndd	t        j                         v st	        j                  |      rt	        j                  |      nd	d
z  }t	        j                  d|       dz   d|iz  }t        t	        j                  |            d }y )Nr_   rm   r   z() => pads.map(p => p.type))r   clap	closedHatopenHattomrimpercslicer9   )z%(py0)s == %(py2)s	pad_typesexpectedrp   zPad types: z
>assert %(py4)sr?   )rE   select_optionr   evaluaterG   rH   rI   rJ   rK   rL   _format_assertmsgrM   rN   )rP   rQ   r   r   rR   ry   rX   s          r/   test_apply_presetzTestFrontend.test_apply_preset   s    ^$228<c"MM"?@	ZH$???yH??????y???y??????H???H????I;&???????r	   c                    |\  }}t        ||      }	 |j                         5 }|j                  d      j                          d d d        j                  }|j                  |g       |j                  d       |j                  d      j                  }|j                         r!|j                          |j                  d       t        |       y # 1 sw Y   xY w# t        |       w xY w)Nr|   r   z.analyze-btni  )
r0   r   rE   r   r   r   r   r   rO   r4   )	rP   rQ   r   r   r*   r   r   r   analyze_btns	            r/   test_analyze_single_samplez'TestFrontend.test_analyze_single_sample   s    
d(t4		-))+wZ(..0 ,"==L""I;/!!#&,,~6<<K%%'!!#%%d+!), ,+ "),s#   C  CBC CC C+c           
      4   |\  }}t        ||      }	 |j                         5 }|j                  d      j                          d d d        j                  }|j                  |g       |j                  d       |j                  d      j                  j                          |j                  d       |j                  }d}	 ||	      }
|
j                  } |       }d}||k\  }|st        j                  d|fd||f      d	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      t        j                  |	      t        j                  |
      t        j                  |      t        j                  |      t        j                  |      d
z  }dd|iz  }t        t        j                   |            d x}x}	x}
x}x}x}}t#        |       y # 1 sw Y   xY w# t#        |       w xY w)Nr|   r   r   r   r   r   r   r   rQ   r   r   r   r   r   s                    r/    test_upload_and_assign_drag_dropz-TestFrontend.test_upload_and_assign_drag_drop   su   
d(t4		-))+wZ(..0 ,"==L""I;/!!#&LL &&,,.!!#&<<;;<.;.44;46;!;6!;;;;6!;;;;;;4;;;4;;;<;;;;;;.;;;4;;;6;;;!;;;;;;;;!), ,+ "),s#   H
  G=F.H
 =HH
 
Hc                    |\  }}t        ||      }	 |j                         5 }|j                  d      j                          d d d        j                  }|j                  |g       |j                  d       |j                  d      j                  j                          |j                  d       |j                  d      j                  }|j                  d       |j                  d       |j                  }	 |	       }
d}|
|k(  }|st        j                  d|fd	|
|f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |	      t        j                  |
      t        j                  |      dz  }dd|iz  }t!        t        j"                  |            d x}	x}
x}}t%        |       y # 1 sw Y   xY w# t%        |       w xY w)Nr|   r   r   r   z.pad.filled selectsnared   r9   )zJ%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.input_value
}()
} == %(py7)stype_selectr<   rA   rB   )r0   r   rE   r   r   r   r   r   r   input_valuerG   rH   rI   rJ   rK   rL   rM   rN   r4   )rP   rQ   r   r   r*   r   r   r   r   rR   rS   rT   rU   rV   rW   s                  r/   test_change_pad_typez!TestFrontend.test_change_pad_type   sh   
d(t4		-))+wZ(..0 ,"==L""I;/!!#&LL &&,,.!!#&,,';<BBK%%g.!!#&**7*,77,7777,777777;777;777*777,7777777777!), ,+ "),s#   G/  G"FG/ "G,'G/ /G<N)__name__
__module____qualname____doc__rY   r]   rz   r   r   r   r   r   r   r   r   r    r	   r/   r6   r6   9   sB    7!!#- 6:.0-*-(@-$-"-r	   r6   c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestAPIzAPI-level validation tests.c                    dd l }|j                  | d      }|j                  }|syddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        t        j                  |            d }|j                  } |       }ddi}||k(  }|st        j                  d|fd	||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      d
z  }	dd|	iz  }
t        t        j                  |
            d x}x}x}}y )Nr   z	/api/ping&assert %(py2)s
{%(py2)s = %(py0)s.ok
}resprp   okTr9   )zC%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.json
}()
} == %(py7)sr<   rA   rB   )requestsgetr   rI   rJ   rG   rK   rL   rM   rN   jsonrH   )rP   serverr   r   rR   ry   rS   rT   rU   rV   rW   s              r/   	test_pingzTestAPI.test_ping  s    ||vhi01wwwttwyy*y{*tTl*{l****{l******t***t***y***{***l*******r	   c                 ~   dd l }|\  }}|j                  | dd||dfi      }|j                  }|syddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        t        j                  |            d }|j                         }	|	d	   }
d
}|
|k(  }|slt        j                  d|fd|
|f      t        j                  |
      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}
x}}|	d   }
d}|
|k(  }|slt        j                  d|fd|
|f      t        j                  |
      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}
x}}|	d   }
d}|
|k(  }|slt        j                  d|fd|
|f      t        j                  |
      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}
x}}|	d   }
d}|
|k(  }|slt        j                  d|fd|
|f      t        j                  |
      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}
x}}|	d   }
d}|
|kD  }|slt        j                  d|fd|
|f      t        j                  |
      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}
x}}y )Nr   
/api/probefile	audio/wavfilesr   r   rp   r$   r   r9   z%(py1)s == %(py4)srf   r?   assert %(py6)sr   
sampleRater   bitDepthr   ext.wavr%   >)z%(py1)s > %(py4)sr   postr   rI   rJ   rG   rK   rL   rM   rN   r   rH   )rP   r   r   r   r   r*   r   rR   ry   metaru   rS   rv   rX   @py_format7s                  r/   test_probe_wavzTestAPI.test_probe_wav  s   
d}}xz26D$P[C\:]}^wwwttwyy{J$1$1$$$$1$$$$$$1$$$$$$$L!*U*!U****!U***!***U*******J%2%2%%%%2%%%%%%2%%%%%%%E{$f${f$$$${f$$${$$$f$$$$$$$J#!#!####!######!#######r	   c                    dd l }|\  }}|j                  | dd||dfi      }|j                  }|syddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        t        j                  |            d }|j                         }	d	}
|
|	v }|st        j                  d
|fd|
|	f      t        j                  |
      dt        j                         v st        j                  |	      rt        j                  |	      nddz  }dd|iz  }t        t        j                  |            d x}
}d}
|
|	v }|st        j                  d
|fd|
|	f      t        j                  |
      dt        j                         v st        j                  |	      rt        j                  |	      nddz  }dd|iz  }t        t        j                  |            d x}
}d}
|
|	v }|st        j                  d
|fd|
|	f      t        j                  |
      dt        j                         v st        j                  |	      rt        j                  |	      nddz  }dd|iz  }t        t        j                  |            d x}
}d}
|
|	v }|st        j                  d
|fd|
|	f      t        j                  |
      dt        j                         v st        j                  |	      rt        j                  |	      nddz  }dd|iz  }t        t        j                  |            d x}
}d}
|
|	v }|st        j                  d
|fd|
|	f      t        j                  |
      dt        j                         v st        j                  |	      rt        j                  |	      nddz  }dd|iz  }t        t        j                  |            d x}
}d}
|
|	v }|st        j                  d
|fd|
|	f      t        j                  |
      dt        j                         v st        j                  |	      rt        j                  |	      nddz  }dd|iz  }t        t        j                  |            d x}
}d}
|
|	v }|st        j                  d
|fd|
|	f      t        j                  |
      dt        j                         v st        j                  |	      rt        j                  |	      nddz  }dd|iz  }t        t        j                  |            d x}
}d}
|
|	v }|st        j                  d
|fd|
|	f      t        j                  |
      dt        j                         v st        j                  |	      rt        j                  |	      nddz  }dd|iz  }t        t        j                  |            d x}
}y )Nr   /api/analyzer   r   r   r   r   rp   bpmra   rc   resultre   rh   ri   sample_typeloop_oneshotkeypitchloudness_db	dc_offset_cachedr   )rP   r   r   r   r   r*   r   rR   ry   r   ru   rv   rw   rx   s                 r/   test_analyze_wavzTestAPI.test_analyze_wav  s8   
d}}x|4VdDR]E^<_}`wwwttwuuu&}&&&&}&&&}&&&&&&&&&&&&&&&&'~''''~'''~''''''''''''''''uuu w&    w&   w      &   &       &}&&&&}&&&}&&&&&&&&&&&&&&&&${f$$$${f$$${$$$$$$f$$$f$$$$$$$"yF""""yF"""y""""""F"""F"""""""r	   c                    dd l }|\  }}|j                  | dd||dfi      }|j                  }|syddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        t        j                  |            d }|j                  | dd||dfi      }	|	j                  }|sydd	t        j                         v st        j                  |	      rt        j                  |	      nd	t        j                  |      dz  }t        t        j                  |            d }|	j                         d
   }
d}|
|u }|slt        j                  d|fd|
|f      t        j                  |
      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}
x}}y )Nr   r   r   r   r   r   resp1rp   resp2r  T)is)z%(py1)s is %(py4)sr   r   r   r   )rP   r   r   r   r   r*   r
  rR   ry   r  ru   rS   rv   rX   r   s                  r/   test_analyze_caches_resultz"TestAPI.test_analyze_caches_result"  s   
d5ftTS^F_=`axxxuux5ftTS^F_=`axxxuuxzz|I&.$.&$....&$...&...$.......r	   c                    dd l }dd l}|\  }}|j                  | dd||dfi       |j                  |      j	                         }|j                  ||z   j                               j	                         }|j                  | dd|gi      }	|	j                  }
|
syd	d
t        j                         v st        j                  |	      rt        j                  |	      nd
t        j                  |
      dz  }t        t        j                  |            d }
|	j                         }||v }
|
st        j                  d|
fd||f      dt        j                         v st        j                  |      rt        j                  |      nddt        j                         v st        j                  |      rt        j                  |      nddz  }dd|iz  }t        t        j                  |            d }
y )Nr   r   r   r   r   z/api/lookuphashes)r   r   r   rp   ra   rn   	cache_keyresultsrq   r?   )r   hashlibr   sha256	hexdigestencoder   rI   rJ   rG   rK   rL   rM   rN   r   rH   )rP   r   r   r   r  r   r*   	file_hashr  r   rR   ry   r  rX   s                 r/   test_lookup_bulkzTestAPI.test_lookup_bulk-  s8   
d-ftT;>W5XY NN4(224	NNI$4#<#<#>?IIK	}}x{38i[:Q}Rwwwttw))+G####yG######y###y######G###G#######r	   c                    dd l }|\  }}|j                  | dd||dfi      }|j                  }|syddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        t        j                  |            d }|j                  d	   }	d}
|	|
k(  }|slt        j                  d
|fd|	|
f      t        j                  |	      t        j                  |
      dz  }dd|iz  }t        t        j                  |            d x}	x}}
|j                  }t        |      }d}||kD  }|s
t        j                  d|fd||f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}}y )Nr   z/api/convertr   r   r   r   r   rp   content-typer9   r   r   r   r   ,   r   )zL%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.content
})
} > %(py8)sr   )r=   rf   rg   ri   r   zassert %(py10)sr   )r   r   r   rI   rJ   rG   rK   rL   rM   rN   headersrH   r   r   )rP   r   r   r   r   r*   r   rR   ry   ru   rS   rv   rX   r   @py_assert4r   rT   @py_format9@py_format11s                      r/   test_convert_wavzTestAPI.test_convert_wav<  sa   
d}}x|4VdDR]E^<_}`wwwttw||N+:{:+{::::+{:::+:::{:::::::<<%s< %2% 2%%%% 2%%%%%%s%%%s%%%%%%4%%%4%%%<%%% %%%2%%%%%%%r	   c                 \   dd l }|j                  | dddd      }|j                  }d}||k(  }|st        j                  d|fd	||f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}d}	|j                  }|	|v }
|
st        j                  d|
fd|	|f      t        j                  |	      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}	x}
}y )Nr   /api/exportTestKitz[]kitNameconfig)r*     r9   z3%(py2)s
{%(py2)s = %(py0)s.status_code
} == %(py5)sr   r=   r>   ri   assert %(py7)sr@   z
No samplesra   )z,%(py1)s in %(py5)s
{%(py5)s = %(py3)s.text
})rf   rg   ri   )r   r   status_coderG   rH   rI   rJ   rK   rL   rM   rN   text)rP   r   r   r   rR   r  rS   rx   rV   ru   rv   s              r/   test_export_empty_failszTestAPI.test_export_empty_failsD  s
   }}x{3 ;
}  &3&3&&&&3&&&&&&t&&&t&&&&&&3&&&&&&&(tyy(|y((((|y(((|((((((t(((t(((y(((((((r	   c                    dd l }|\  }}ddddd|dg}|j                  | ddt        d      j                  |      dd	||d
fi      }|j                  }|syddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }	t        t        j                  |	            d }|j                  d   }
d}|
|k(  }|slt        j                  d|fd|
|f      t        j                  |
      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}
x}}dd l}dd l}|j!                  |j#                  |j$                              }|j'                         }d |D        }t)        |      }|sddt        j                         v st        j                  t(              rt        j                  t(              ndt        j                  |      t        j                  |      dz  }t        t        j                  |            d x}}d |D        }t)        |      }|sddt        j                         v st        j                  t(              rt        j                  t(              ndt        j                  |      t        j                  |      dz  }t        t        j                  |            d x}}y )Nr   r   Kick)	slotIndextypelabelvolumepanfilenamer!  r"  r   r#  r   r   )r*   r   r   r   rp   r  zapplication/zipr9   r   r   r   r   c              3   >   K   | ]  }|j                  d         yw)r   Nendswith.0ns     r/   	<genexpr>z3TestAPI.test_export_with_samples.<locals>.<genexpr>^       5u!1::f%u   z,assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}anyrD   c              3   >   K   | ]  }|j                  d         yw)z.nnrNr6  r8  s     r/   r;  z3TestAPI.test_export_with_samples.<locals>.<genexpr>_  r<  r=  )r   r   
__import__dumpsr   rI   rJ   rG   rK   rL   rM   rN   r  rH   zipfileioZipFileBytesIOr   namelistr>  )rP   r   r   r   r   r*   r%  r   rR   ry   ru   rS   rv   rX   r   rB  rC  zfnamess                      r/   test_export_with_samplesz TestAPI.test_export_with_samplesM  s   
dVfRSaef
 }}hk"&*V2D2J2J62RST456  

 wwwttw||N+@/@@+/@@@@@+/@@@@+@@@/@@@@@@@@__RZZ565u55s555555555s555s555555555555555u55s555555555s555s55555555555555r	   c                    dd l }|j                  | dddi      }|j                  }d}||k(  }|st        j                  d|fd||f      d	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      t        j                  |      d
z  }dd|iz  }t        t        j                  |            d x}x}}y )Nr   r   r   )ztest.txts	   not audioz
text/plainr   r&  r9   r'  r   r(  r)  r@   )r   r   r*  rG   rH   rI   rJ   rK   rL   rM   rN   )	rP   r   r   r   rR   r  rS   rx   rV   s	            r/    test_unsupported_format_rejectedz(TestAPI.test_unsupported_format_rejecteda  s    }}xz26Ck:l}m&3&3&&&&3&&&&&&t&&&t&&&&&&3&&&&&&&r	   N)r   r   r   r   r   r   r  r  r  r  r,  rI  rK  r   r	   r/   r   r      s2    %+
$#	/$&)6('r	   r   )N)builtinsrI   _pytest.assertion.rewrite	assertionrewriterG   r   r   r   pathlibr   r0   r4   r6   r   r   r	   r/   <module>rQ     s9         'TB- B-Jf' f'r	   