
    *j=                        d Z ddlmZ ddlZddlmc mZ ddl	m
Z
 ddlmZ ddlmZmZmZmZ e
 G d d                      Z G d	 d
          ZddZd Zd Zd Zd Zd Zd ZdS )uN   Tests for compiler/stages/transcribe.py — offline via fake downloader/model.    )annotationsN)	dataclass)Path)_resolve_audio_urlis_audio_sourcetranscribe_alltranscribe_sourcec                  <    e Zd ZU ded<   ded<   ded<   dZded<   dS )	_Segmentfloatstartendstrtext
SPEAKER_01speakerN)__name__
__module____qualname____annotations__r        G/Users/jameslopez/projects/MentorCore/tests/compiler/test_transcribe.pyr   r      s>         LLLJJJIIIGr   r   c                      e Zd ZddZd	dZdS )

_FakeModelreturnNonec                    d| _         d S )Nr   )calls)selfs    r   __init__z_FakeModel.__init__   s    


r   audior   c                   | xj         dz  c_         |j        }d} ||          }|sddt          j                    v st	          j        |          rt	          j        |          ndt	          j        |          t	          j        |          t	          j        |          d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}}t          ddd          t          ddd          gddifS )N   .m4azJassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.endswith
}(%(py4)s)
}r"   )py0py2py4py6languageen==)z%(py1)s == %(py4)s)py1r(   zassert %(py6)sr)   g        g      ?zHello from the archive.g      ?g      @zThis is the second turn.)r   endswith@py_builtinslocals
@pytest_ar_should_repr_global_name	_safereprAssertionError_format_explanation_call_reprcomparer   )
r    r"   kwargs@py_assert1@py_assert3@py_assert5@py_format7@py_assert0@py_assert2@py_format5s
             r   
transcribez_FakeModel.transcribe   s   

a

~%f%~~f%%%%%%%%%%%%%%%u%%%%%u%%%%%%~%%%%f%%%%%%%%%%%%%%%%%%%%%%%%%%j!)T)!T))))))))))!T)))))!))))T))))))))))))))))))))))))))) d$=>>c#=>> 
 	
r   N)r   r   )r"   r   )r   r   r   r!   r@   r   r   r   r   r      s<           

 

 

 

 

 

r   r   srcdict	media_dirr   r   c                z    |                     dd           || d          dz  }|                    d           |S )NT)parentsexist_okidr%   s
   fake audio)mkdirwrite_bytes)rA   rC   paths      r   _fake_downloaderrK   )   sH    OOD4O000#d)))))D]###Kr   c                    d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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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
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} x}}d S )Nxyoutube)rG   
fetch_typez,assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}r   )r&   r'   r(   rss	interview)rG   typeurlarticle)rG   rO   rR   z0assert not %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
})r   r0   r1   r2   r3   r4   r5   r6   )r9   r:   r?   r;   @py_format6s        r   ?test_is_audio_source_matches_audio_fetch_types_and_source_typesrV   0   s   "%Y??@??@@@@@@@@@@@@@@@?@@@@@?@@@@@@?@@@@@@@@@@@@@@@@@@@@@@@@"%U;;<?;<<<<<<<<<<<<<<<?<<<<<?<<<<<<;<<<<<<<<<<<<<<<<<<<<<<<<"%{;;<?;<<<<<<<<<<<<<<<?<<<<<?<<<<<<;<<<<<<<<<<<<<<<<<<<<<<<<&)	RRSRSSSSSSSSSSSSSSSSSSSSSSSSSSSSSRSSSSSSSSSSSSSSSSSSSSSSSSSSSSr   c                   t                      }dddddd}t          || dz  t          |          }d}| |z  }d	}||z  }||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t          j        |          t          j        |          dz  }	dd|	iz  }
t          t          j
        |
                    d x}x}x}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}}|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 S )Ninterview-1rQ   rN   zhttps://example.com/watch?v=1r+   )rG   rR   rO   rS   r*   raw
downloadermodelinterview-1.txtr,   )z*%(py0)s == ((%(py2)s / %(py4)s) / %(py7)s)resulttmp_pathr&   r'   r(   py7zassert %(py10)spy10zC[00:00:00.000 --> 00:00:01.250] SPEAKER_01: Hello from the archive.)in)z%(py1)s in %(py3)s
transcript)r.   py3zassert %(py5)spy5zD[00:00:01.500 --> 00:00:03.000] SPEAKER_01: This is the second turn.r$   z-%(py2)s
{%(py2)s = %(py0)s.calls
} == %(py5)sr\   r&   r'   rf   assert %(py7)sra   )r   r	   rK   r2   r7   r0   r1   r3   r4   r5   r6   	read_textr   )r_   r\   rA   r^   r:   r;   @py_assert6@py_assert8r9   @py_format9@py_format11rd   r=   r>   @py_format4rU   @py_assert4@py_format8s                     r   Btest_transcribe_source_downloads_and_writes_timestamped_transcriptrr   7   s   LLE. C 5#	  F !&9X%9(99%(9996999999999996999999999999969999969999999999999X99999X9999999999(99999999999999999999999999999999!!##JP^PT^^^^^^^^^^^PT^^^^^^P^^^^^^^^^^^T^^^^^^T^^^^^^^^^^^^^^^^^^^^^^^^^^^^Q_QU___________QU______Q___________U______U____________________________;!;!;!55;!r   c                   t                      }| dz  }|                                 |dz  }|                    d           dddd}t          ||t          |          }||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  }dd|iz  }t          t          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}||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 S )NrY   r]   zcached transcript
rX   rQ   rN   rG   rR   rO   rZ   r,   )z%(py0)s == %(py2)sr^   cached)r&   r'   zassert %(py4)sr(   )zH%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.read_text
}()
} == %(py7)sr`   assert %(py9)spy9r   rg   r\   rh   ri   ra   )r   rH   
write_textr	   rK   r2   r7   r0   r1   r3   r4   r5   r6   rj   r   )r_   r\   raw_dirru   rA   r^   r9   @py_format3r?   r:   rk   r;   rq   @py_format10rp   rU   s                   r   -test_transcribe_source_uses_cached_transcriptr|   O   s8   LLEGMMOOO((F
+,,,9
M
MCsG8HPUVVVFV6V66VV66!66!66666666666!6666666666666666666666666666666666!666666666666666666666666666666;!;!;!55;!r   c                   t                      }ddddddddd	g}t          || d
z  t          |          }t          |          }dg}||k    }|st	          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	        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}|d         }	|	j        } |            }|s`dt	          j	        |	          t	          j	        |          t	          j	        |          dz  }
t          t	          j        |
                    d x}	x}}|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 S )Nz	article-1rT   rS   rt   	podcast-1podcastrP   zhttps://x.test/rss)rG   rR   rO   rss_urlrY   rZ   r,   )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)slistresults)r&   r.   re   r)   zassert %(py8)spy8zAassert %(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.exists
}()
})r.   re   rf   r$   rg   r\   rh   ri   ra   )r   r   rK   r   r2   r7   r0   r1   r3   r4   r5   r6   existsr   )r_   r\   sourcesr   r>   r;   rp   r<   rm   r=   rU   r9   r:   rq   s                 r   &test_transcribe_all_skips_text_sourcesr   ^   s   LLEIUCCIUOcddG
 5#	  G ==)[M)=M))))))))))=M))))))))))))4)))))4))))))))))))))))))))))))=))))M)))))))))))))))))))))))))));(&(&&((((((((((((&((((((((((((((((((((((((((;!;!;!55;!r   c                    ddddd} t          |           }d}||k    }|st          j        d|fd||f          dt          j                    v st          j        t                     rt          j        t                     ndt          j        |           t          j        |          t          j        |          d	z  }d
d|iz  }t          t          j        |                    d x} x}x}}d S )Nr~   rP   zhttps://example.com/feed.xmlz#https://cdn.example.com/episode.mp3)rG   rO   r   episode_urlr,   z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)sr   r`   rv   rw   )	r   r2   r7   r0   r1   r3   r4   r5   r6   )r9   r:   rk   r;   rq   r{   s         r   *test_resolve_audio_url_prefers_episode_urlr   q   s    "#9D	 
	
 	

 1
	
 1	1
 
 
 

 
 
 
	
 1
 
 
 
 

 
 
 
 
 	
 
 
 
 	
 
 
 
 

 
 
	

 
 
 1
 
 
 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
r   c                0   | dz  }|                     d           ddt          |          d}t          |          }d}||k    }|st          j        d|fd||f          d	t          j                    v st          j        t                    rt          j        t                    nd	t          j        |          t          j        |          t          j        |          d
z  }dd|iz  }t          t          j
        |                    d x}x}x}}d S )Nzfeed.xmlz<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <item>
      <title>Episode 1</title>
      <enclosure url="https://cdn.example.com/episode-1.mp3" type="audio/mpeg"/>
    </item>
  </channel>
</rss>
r~   rP   )rG   rO   r   z%https://cdn.example.com/episode-1.mp3r,   r   r   r`   rv   rw   )rx   r   r   r2   r7   r0   r1   r3   r4   r5   r6   )r_   feedr9   r:   rk   r;   rq   r{   s           r   )test_resolve_audio_url_from_rss_enclosurer      s   j DOO		    "#t99 		
 	
	 3		
 3	3	 	 	 		 	 	 		
 3	 	 	 	 		 	 	 	 	 		 	 	 	 		 	 	 	 		 	 		
	 	 	 3	 	 	 	 	 	 	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r   )rA   rB   rC   r   r   r   )__doc__
__future__r   builtinsr0   _pytest.assertion.rewrite	assertionrewriter2   dataclassesr   pathlibr   compiler.stages.transcriber   r   r   r	   r   r   rK   rV   rr   r|   r   r   r   r   r   r   <module>r      so   T T " " " " " "               ! ! ! ! ! !                                 
 
 
 
 
 
 
 
"   T T T  0    &      r   