B
    .(b                 @   s   d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	 ddl
mZ e dd	 Zd
d Zdd Zdd Zdd Zdd ZdS )    )unicode_literalsN)TRAINING_SCHEMA)get_json_validatorvalidate_json)Doc   )get_docc          	   C   sN   dddg}dddg}dddg}dd	d
g}dddg}dg}t | ||||||dS )NcdeVERBZNOUNVBPZNNr   ROOTZdobj)   r   ORG)wordspostagsheadsdepsents)r   )Zen_vocabr   r   r   r   r   r    r   K/home/dcms/DCMS/lib/python3.7/site-packages/spacy/tests/doc/test_to_json.pydoc   s    




r   c             C   s   |   }|d dkstt|d dks,t|d d d dksDt|d d d d	ks\t|d d d
 dksttt|d dkst|d d d dkst|d d d dkst|d d d dkstd S )Ntextzc d e tokens   r   r   r   tagr   depr   r   r   startr   endlabelr   )to_jsonAssertionErrorlen)r   json_docr   r   r   test_doc_to_json   s    r(   c             C   s   t jddd t jddd d| j_dddg| j_| jddgd	}d
|ksNt|d
 d dksbt|d
 d dddgks|td S )N
json_test1F)default
json_test2zhello worldr   r   r   )
underscore_)r   set_extensionr-   r)   r+   r$   r%   )r   r'   r   r   r   test_doc_to_json_underscore%   s    r/   c          	   C   s(   t t | jdgd W dQ R X dS )z`Test that Doc.to_json() raises an error if a custom attribute doesn't
    exist in the ._ space.Z
json_test3)r,   N)pytestraises
ValueErrorr$   )r   r   r   r   &test_doc_to_json_underscore_error_attr0   s    r3   c          	   C   s:   t jddd d tt | jdgd W dQ R X dS )z`Test that Doc.to_json() raises an error if a custom attribute value
    isn't JSON-serializable.Z
json_test4c             S   s   | j S )N)r   )r   r   r   r   <lambda>:       z=test_doc_to_json_underscore_error_serialize.<locals>.<lambda>)method)r,   N)r   r.   r0   r1   r2   r$   )r   r   r   r   +test_doc_to_json_underscore_error_serialize7   s    r7   c             C   s(   |   }tt}t|g|}|r$td S )N)r$   r   r   r   r%   )r   r'   Z	validatorerrorsr   r   r   test_doc_to_json_valid_training?   s    r9   )
__future__r   r0   Zspacy.cli._schemasr   Z
spacy.utilr   r   Zspacy.tokensr   utilr   Zfixturer   r(   r/   r3   r7   r9   r   r   r   r   <module>   s   