o
    i                     @   sn   d dl Z d dlmZ d dlmZ d dlmZmZ dd Zdd Z	d	d
 Z
e jdg ddd Zdd ZdS )    N)Mock)Language)get_attr_infovalidate_attrsc                  C   s  t jdddgddd } t jdddgd	dgd
dd }t jdd	gdgd
dd }t ds2J t ds9J t ds@J t  }|d |d | d }|d dgks\J |d t|dd ddgksnJ |jddd |d}|jdksJ |jg dksJ t drJ |j	d dksJ |j	d dksJ t|dd g dksJ t|dd dgksJ |dsJ d S )Nc1	token.tagz
doc.tensorassignsc                 S      | S N docr   r   V/home/ubuntu/.local/lib/python3.10/site-packages/spacy/tests/pipeline/test_analysis.pytest_component1	      z9test_component_decorator_assigns.<locals>.test_component1c2	token.posztoken.lemma)requiresr	   c                 S   r
   r   r   r   r   r   r   test_component2      z9test_component_decorator_assigns.<locals>.test_component2c3ztoken._.custom_lemmac                 S   r
   r   r   r   r   r   r   test_component3   r   z9test_component_decorator_assigns.<locals>.test_component3problemsr	   c4)name)r   r   r   r   )r   r   r   r   hello world)
r   	componenthas_factoryadd_pipeanalyze_pipesr   get_pipe_metafactory
pipe_namespipe_factories)r   r   r   nlpr   test_component4_metar   r   r    test_component_decorator_assigns   s<   







r'   c                     s   G dd d} t   |   _ddtf fdd}tjd|d tds&J t }|jdddid	 |d
s8J  j|dd dS )zTest that class components can implement a from_nlp classmethod that
    gives them access to the nlp object and config via the factory.c                   @   s   e Zd Zdd ZdS )z;test_component_factories_class_func.<locals>.TestComponent5c                 S   s   |S r   r   )selfr   r   r   r   __call__5   s   zDtest_component_factories_class_func.<locals>.TestComponent5.__call__N)__name__
__module____qualname__r)   r   r   r   r   TestComponent54   s    r-   barc5fooc                    s    | |dS )Nr0   r   )r%   r0   r   mockr   r   test_componen5_factory;   s   zCtest_component_factories_class_func.<locals>.test_componen5_factory)func)configr   r1   N)r.   r/   )r   return_valuestrr   r"   r   r   assert_called_once_with)r-   r4   r%   r   r2   r   #test_component_factories_class_func0   s   r:   c                  C   sh   g d} t | s
J | D ]	}t |gsJ qtt t ddg W d    d S 1 s-w   Y  d S )N)	doc.sentszdoc.entsr   ztoken._.xyzz
span._.xyzr;   doc.xyz)r   pytestraises
ValueError)attrsattrr   r   r   "test_analysis_validate_attrs_validF   s   "rB   rA   )r   doc_entsr<   z	token.xyzz
token.tag_ztoken.tag.xyzztoken._.xyz.abcz
span.labelc                 C   s:   t t t| g W d    d S 1 sw   Y  d S r   )r=   r>   r?   r   )rA   r   r   r   $test_analysis_validate_attrs_invalidO   s   "rD   c                  C   s   t jddgddd } t jddgdd	d
 }t  }|d |d | d }|d dgks4J |d | d }tdd | D sLJ dS )z7Test that attributes are validated correctly on remove.pipe_analysis_c6r   r   c                 S   r
   r   r   r   r   r   r   r   d   r   z4test_analysis_validate_attrs_remove_pipe.<locals>.c1pipe_analysis_c7r   )r   c                 S   r
   r   r   r   r   r   r   r   h   r   z4test_analysis_validate_attrs_remove_pipe.<locals>.c2r   c                 s   s    | ]}|g kV  qd S r   r   ).0pr   r   r   	<genexpr>s   s    z;test_analysis_validate_attrs_remove_pipe.<locals>.<genexpr>N)r   r   r   r    remove_pipeallvalues)r   r   r%   r   r   r   r   (test_analysis_validate_attrs_remove_pipea   s   




rM   )r=   r3   r   spacy.languager   spacy.pipe_analysisr   r   r'   r:   rB   markparametrizerD   rM   r   r   r   r   <module>   s    (	
