o
    i                     @   s   d dl Z d dlZd dlmZ d dlZd dlmZ d dlmZ ee	j
d Zd dl Z d dlmZ ejZdd Zee_ejd	d
 Zdd ZdS )    N)Path)Language)registryzfactory_registrations.json)utilc                 C   s0   zt | |W S  ty   t| t|k Y S w )N)original_is_same_func	TypeErrorstr)func1func2 r   Z/home/ubuntu/.local/lib/python3.10/site-packages/spacy/tests/test_factory_registrations.pypatched_is_same_func   s
   r   c                  C   sR   t  stdt  d t d} t| W  d   S 1 s"w   Y  dS )z3Load reference factory registrations from JSON filezReference file z6 not found. Run export_factory_registrations.py first.rN)REFERENCE_FILEexistspytestfailopenjsonload)fr   r   r   reference_factory_registrations!   s   
$r   c           	   
   C   s0  t   t j }i }| D ]P\}}z|j}W n ttfy0   t|	 d 	dd }Y nw z|j
}W n  ttfyV   t|drG|jnt|	 d 	dd }Y nw |||d||< qt|  t|  }|rzJ ddt| t| t|   }|rtd	dt|  d
S d
S )zNTest that all factory registrations from the reference file are still present.   .r   __name__)namemodulefunctionzMissing factory registrations: z, z!New factory registrations found: N)r   ensure_populated	factoriesget_allitems
__module__AttributeErrorr   r   split__qualname__hasattrr   setkeysjoinsortedprint)	r   all_factoriescurrent_registrationsr   funcmodule_name	func_namemissing_registrationsnew_registrationsr   r   r   $test_factory_registrations_preserved-   sH   


	r4   )inspectr   pathlibr   r   spacy.languager   
spacy.utilr   __file__parentr   spacyr   is_same_funcr   r   fixturer   r4   r   r   r   r   <module>   s    	
