
    XPjL                     Z    d Z ddlZddlmc mZ ddlZd Zd Z	d Z
d Zd Zd Zd	 Zd
 Zy)z?SentenceRegrouper: streamed token deltas -> complete sentences.    Nc                     g }|D ]"  }|j                  | j                  |             $ | j                         }|r|j                  |       |S N)extendpushflushappend)	regrouperdeltasoutdtails        J/Users/ahmed/devFolder/Ultron/claude-voice/gateway/tests/test_sentences.py_feedr      sF    
C

9>>!$% ??D

4J    c                     t        j                         } t        | g d      }g d}||k(  }|st        j                  d|fd||f      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}}y )	N)zHello, sir. zHow are you today? 	All good.)zHello, sir.zHow are you today?r   ==z%(py0)s == %(py3)sgotpy0py3assert %(py5)spy5)brainSentenceRegrouperr   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationrr   @py_assert2@py_assert1@py_format4@py_format6s         r   #test_splits_on_sentence_punctuationr,      sy    !A
G
HCDD3DDDDD3DDDDDDD3DDD3DDDDDDDDDDDr   c                  b   t        j                         } | j                  d      }dg}||k(  }|st        j                  d|fd||f      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}}| j                  }d	} ||      }g }||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                  |      dz  }
dd|
iz  }t        t        j                  |            d x}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                  |      t        j                  |      dz  }dd|iz  }
t        t        j                  |
            d x}x}x}}y )NzRight away, sir. And thenzRight away, sir.r   r   firstr   r   r   z I will do it.zJ%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.push
}(%(py4)s)
} == %(py9)sr'   r   py2py4py6py9assert %(py11)spy11zAnd then I will do it.)zD%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.flush
}()
} == %(py7)s)r   r1   r2   py7zassert %(py9)sr4   )r   r   r   r   r   r    r!   r"   r#   r$   r%   r   )r'   r.   r(   r)   r*   r+   @py_assert3@py_assert5@py_assert8@py_assert7@py_format10@py_format12@py_assert6@py_format8s                 r   3test_streams_first_sentence_before_the_rest_arrivesr@      s   !AFF./E'((5(((((5(((((((5(((5(((((((((((66)")6"#)r)#r))))#r))))))1)))1)))6)))")))#)))r)))))))7707900090000090000000100010007000900000000000r   c                     t        j                         } d}| j                  |      }|s{t        j                  d      dz   ddt        j                         v st        j                  |      rt        j                  |      ndiz  }t        t        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}}y )
Na,  word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word z1a long punctuation-less run must be force-flushedz
>assert %(py0)sr   r   c              3   T   K   | ]   }t        |      t        j                  k   " y wr   )lenr   
_MAX_CHUNK).0ss     r   	<genexpr>zAtest_hard_flush_on_runaway_without_punctuation.<locals>.<genexpr>#   s      73as1v)))3s   &(z,assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}all)r   r1   r2   )r   r   r   r   _format_assertmsgr    r!   r"   r#   r$   r%   rH   )r'   long_runr   @py_format1r)   r8   @py_format5s          r   .test_hard_flush_on_runaway_without_punctuationrM      s    !AH
&&
CCCCCCCCCC3CCC3CCCCC737737777777773777377777777777777r   c                  *   t        j                         } | j                  }d} ||      }dg}||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                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}x}}y )	Nu   ما اسمك؟ u   ما اسمك؟r   r/   r'   r0   r5   r6   r   r   r   r   r   r    r!   r"   r#   r$   r%   r'   r)   r8   r9   r:   r;   r<   r=   s           r   test_arabic_sentence_endrQ   &   s    !A66<$<6$%<*;)<<%)<<<<<%)<<<<<<<1<<<1<<<6<<<$<<<%<<<)<<<<<<<<<r   c                  *   t        j                         } | j                  }d} ||      }dg}||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                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}x}}y )	NzLine one
Line two.zLine oner   r/   r'   r0   r5   r6   rO   rP   s           r   test_newline_flushesrS   +   s    !A668'86'(8ZL8(L8888(L888888188818886888'888(888L88888888r   c                     t        j                         } | j                  d      }dg}||k(  }|st        j                  d|fd||f      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}}y )	Nz[warm] *Well* done, sir. z[warm] Well done, sir.r   r   r   r   r   r   rO   r&   s         r   "test_emotion_tag_survives_cleaningrU   0   s~    !A
&&,
-C+,,3,,,,,3,,,,,,,3,,,3,,,,,,,,,,,r   c                  ,   t         j                  } d} | |      }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                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x} x}x}x}}t         j                  } d	} | |      }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                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x} x}x}x}}y )
Nz**bold** and `code`zbold and coder   )zS%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.clean_for_tts
}(%(py4)s)
} == %(py9)sr   r0   r5   r6   z[excited] go!)
r   clean_for_ttsr   r   r    r!   r"   r#   r$   r%   )r)   r8   r9   r:   r;   r<   r=   s          r   1test_clean_for_tts_strips_markdown_keeps_bracketsrX   7   s:   H4H45HH5HHHH5HHHHHH5HHH5HHHHHH4HHH5HHHHHHHHHHBB/B?B/?BBBB/?BBBBBB5BBB5BBBBBBBBB/BBB?BBBBBBBBr   )__doc__builtinsr    _pytest.assertion.rewrite	assertionrewriter   r   r   r,   r@   rM   rQ   rS   rU   rX    r   r   <module>r_      s9    E   E18=
9
-Cr   