o
    5ti5                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlZ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 G dd dejZedkrIe  dS dS )z%Tests for rouge input/output library.    )absolute_import)division)print_functionN)absltest)io)rouge_scorer)scoring)	test_utilc                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )IoTestc              	   C   s   t  U}|j}tdgd}ttjtj	||t
  t|}| }W d    n1 s/w   Y  tdd |D }| |d d | |dd  g d W d    d S 1 s\w   Y  d S )	Nrouge1Fc                 s       | ]
}| d d V  qdS ,r   Nsplit.0line r   G/home/ubuntu/.local/lib/python3.10/site-packages/rouge_score/io_test.py	<genexpr>*       z1IoTest.testProducesValidOutput.<locals>.<genexpr>r   
score_type   )zrouge1-Pzrouge1-Rzrouge1-F)tempfileNamedTemporaryFilenamer   RougeScorerr   compute_scores_and_write_to_csvr	   TARGETS_FILEPREDICTIONS_FILEr   BootstrapAggregatoropen	readlinestupleassertEqualassertSameElements)selfoutput_fileoutput_filenamescorerf	csv_linesoutput_typesr   r   r   testProducesValidOutput    s"   


"zIoTest.testProducesValidOutputc              	   C   s   t  M}|j}tdgd}ttjtj	||d  t
|}| }W d    n1 s-w   Y  tdd |D }| |d d | |d W d    d S 1 sTw   Y  d S )Nr   Fc                 s   r   r   r   r   r   r   r   r   8   r   z*IoTest.testUnAggregated.<locals>.<genexpr>r   id   )r   r   r   r   r   r   r   r	   r   r    r"   r#   r$   r%   	assertLenr'   r(   r)   r*   r+   r,   idsr   r   r   testUnAggregated/   s   


"zIoTest.testUnAggregatedc              	   C   s   t  O}|j}tdgd}tjtjtj||d dd t	|}|
 }W d    n1 s/w   Y  tdd |D }| |d d | |d	 W d    d S 1 sVw   Y  d S )
Nr   F:)	delimiterc                 s   r   r   r   r   r   r   r   r   I   r   z+IoTest.testDelimitedFile.<locals>.<genexpr>r   r/      )r   r   r   r   r   r   r   r	   DELIMITED_FILEr"   r#   r$   r%   r1   r2   r   r   r   testDelimitedFile<   s$   


"zIoTest.testDelimitedFilec              	   C   sT   t dgd}| t tddd|t  W d    d S 1 s#w   Y  d S )Nr   Fzinvalid*invalid)r   r   assertRaises
ValueErrorr   r   r   r!   r'   r*   r   r   r   testAssertsOnInvalidInputFilesM   s   
"z%IoTest.testAssertsOnInvalidInputFilesc              	   C   sX   t dgd}| t ttjtjd|t	
  W d    d S 1 s%w   Y  d S )NrougexF )r   r   r;   r<   r   r   r	   r   r    r   r!   r=   r   r   r   testAssertsOnInvalidRougeTypesS   s   "z%IoTest.testAssertsOnInvalidRougeTypesN)__name__
__module____qualname__r.   r4   r9   r>   rA   r   r   r   r   r
      s    r
   __main__)__doc__
__future__r   r   r   r   absl.testingr   rouge_scorer   r   r   r	   TestCaser
   rB   mainr   r   r   r   <module>   s   =