3
d$                 @   sh  d dl Z d dlmZ d dlmZ d dlmZmZmZ d dl	Z	d dl
m
Z
 d dlZd dlmZ d dljZd dlZd dlmZ d dlmZmZ ejeZd	d
 ZG dd deZG dd deZG dd deZG dd deZG dd deeeeZ G dd de j!Z"G dd dee Z#edkrde j$ Z%x,e&e"D ] Z'e'j(dr2e%j)e"e' q2W e j* j+e% dS )    N)ProvDocument)RoundTripTestCase)TestStatementsBaseTestAttributesBaseTestQualifiedNamesBase)glob)examples)
graph_diff)BytesIOStringIOc                s   d}t | |\}}}t|jddj dd  }t|jddj dd  }t|t|kr`d}g g g}xtt|D ]}	ttj j	t
||	 ddd  d}
xtt|D ]}||d krqttj j	t
|| ddd y t fddtd	D }W n tk
r   d}Y nX |r|d j|	 |d j| d}
P qW |
svd}qvW tj }xRtt|D ]B}	|	|d kr|j	t
||	 dd n|j	t
||	 dd qjW tj }x:tt|D ]*}	|	|d kr|j	t
||	 dd qW ||||fS )
NTnt)format   Fr   c                s   g | ]} | j | qS  )eq).0i)g1_stmtg2_stmtr   3/tmp/pip-build-7vycvbft/prov/prov/tests/test_rdf.py
<listcomp>+   s    zfind_diff.<locals>.<listcomp>   )r	   sorted	serialize
splitlineslenrangelistrlConjunctiveGraphparser
   all	TypeErrorappend)g_rdfg0_rdfZgraphs_equalZin_bothin_first	in_secondg1Zg2Zmatching_indicesidxZmatch_foundZidx2Z	all_matchZ	in_first2Z
in_second2r   )r   r   r   	find_diff   sH    " 
r*   c               @   s   e Zd ZdZdd ZdS )TestExamplesBasezThis is the base class for testing support for all the examples provided
    in prov.tests.examples.
    It is not runnable and needs to be included in a subclass of
    RoundTripTestCase.
    c             C   sZ   d}xPt jD ]F\}}|dkr,tjd|| q|d7 }tjd|| | }| j| qW d S )Nr   	datatypesz%d. Skipping the %s exampler   z%d. Testing the %s example)r,   )r   testsloggerinfodo_tests)selfcounternamegraphgr   r   r   test_all_examplesI   s    z"TestExamplesBase.test_all_examplesN)__name__
__module____qualname____doc__r6   r   r   r   r   r+   B   s   r+   c               @   s   e Zd ZdZdd ZdS )TestJSONExamplesBasezThis is the base class for testing support for all the examples provided
    in prov.tests.examples.
    It is not runnable and needs to be included in a subclass of
    RoundTripTestCase.
    c             C   sZ   d}xPt jD ]F\}}|dkr,tjd|| q|d7 }tjd|| | }| j| qW d S )Nr   r,   z%d. Skipping the %s exampler   z%d. Testing the %s example)r,   )r   r-   r.   r/   r0   )r1   r2   r3   r4   r5   r   r   r   r6   \   s    z&TestJSONExamplesBase.test_all_examplesN)r7   r8   r9   r:   r6   r   r   r   r   r;   U   s   r;   c               @   s   e Zd Zejdd Zejdd Zejdd Zejdd Zejd	d
 Z	ejdd Z
ejdd Zejdd Zejdd Zejdd Zejdd Zejdd Zejdd Zejdd ZdS )TestStatementsBase2c             C   s   t j|  d S )N)r   test_scruffy_end_1)r1   r   r   r   r=   i   s    z&TestStatementsBase2.test_scruffy_end_1c             C   s   t j|  d S )N)r   test_scruffy_end_2)r1   r   r   r   r>   m   s    z&TestStatementsBase2.test_scruffy_end_2c             C   s   t j|  d S )N)r   test_scruffy_end_3)r1   r   r   r   r?   q   s    z&TestStatementsBase2.test_scruffy_end_3c             C   s   t j|  d S )N)r   test_scruffy_end_4)r1   r   r   r   r@   u   s    z&TestStatementsBase2.test_scruffy_end_4c             C   s   t j|  d S )N)r   test_scruffy_generation_1)r1   r   r   r   rA   y   s    z-TestStatementsBase2.test_scruffy_generation_1c             C   s   t j|  d S )N)r   test_scruffy_generation_2)r1   r   r   r   rB   }   s    z-TestStatementsBase2.test_scruffy_generation_2c             C   s   t j|  d S )N)r   test_scruffy_invalidation_1)r1   r   r   r   rC      s    z/TestStatementsBase2.test_scruffy_invalidation_1c             C   s   t j|  d S )N)r   test_scruffy_invalidation_2)r1   r   r   r   rD      s    z/TestStatementsBase2.test_scruffy_invalidation_2c             C   s   t j|  d S )N)r   test_scruffy_start_1)r1   r   r   r   rE      s    z(TestStatementsBase2.test_scruffy_start_1c             C   s   t j|  d S )N)r   test_scruffy_start_2)r1   r   r   r   rF      s    z(TestStatementsBase2.test_scruffy_start_2c             C   s   t j|  d S )N)r   test_scruffy_start_3)r1   r   r   r   rG      s    z(TestStatementsBase2.test_scruffy_start_3c             C   s   t j|  d S )N)r   test_scruffy_start_4)r1   r   r   r   rH      s    z(TestStatementsBase2.test_scruffy_start_4c             C   s   t j|  d S )N)r   test_scruffy_usage_1)r1   r   r   r   rI      s    z(TestStatementsBase2.test_scruffy_usage_1c             C   s   t j|  d S )N)r   test_scruffy_usage_2)r1   r   r   r   rJ      s    z(TestStatementsBase2.test_scruffy_usage_2N)r7   r8   r9   unittestexpectedFailurer=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   r   r   r   r   r<   h   s   r<   c               @   s6   e Zd Zejdd Zejdd Zejdd ZdS )TestAttributesBase2c             C   s   t j|  d S )N)r   #test_entity_with_multiple_attribute)r1   r   r   r   rN      s    z7TestAttributesBase2.test_entity_with_multiple_attributec             C   s   t j|  d S )N)r   )test_entity_with_multiple_value_attribute)r1   r   r   r   rO      s    z=TestAttributesBase2.test_entity_with_multiple_value_attributec             C   s   t j|  d S )N)r   %test_entity_with_one_type_attribute_8)r1   r   r   r   rP      s    z9TestAttributesBase2.test_entity_with_one_type_attribute_8N)r7   r8   r9   rK   rL   rN   rO   rP   r   r   r   r   rM      s   rM   c               @   s   e Zd ZdZdS )AllTestsBasez.This is a test to include all available tests.N)r7   r8   r9   r:   r   r   r   r   rQ      s   rQ   c               @   s   e Zd Zdd Zdd ZdS )TestRDFSerializerc             C   s@   d}d| }t j|ddd}|jdd }| j||jd d S )	Nu   ’a  
@prefix ex: <http://www.example.org/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

    ex:unicode_char a prov:Entity ;
        rdfs:label "%s"^^xsd:string .
rdfturtle)contentr   
rdf_formatzex:unicode_charr   z
prov:label)r   deserializeZ
get_recordZassertInZget_attribute)r1   Zunicode_charZrdf_contentZprov_docZe1r   r   r   test_decoding_unicode_value   s    z-TestRDFSerializer.test_decoding_unicode_valuec          #   C   s  t ttjjtjjtdd}ttdd}ddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'g#}g }xpt	|D ]b\}}tjj
|\}}tjjtjjtd(|jdd)}ytjj|}	t|	jd*krd+}
nd,}
|
d,kr|jd)d,}t|d-}tj j||
d.}W d Q R X tj jt|	jd(|
d/|
d.}||krlt||\}}}}| j| ntjd0|  ||krtjd1|  wtjj|	jd(|
d/d(|
d2}W q tk
r } z|j|||||f W Y d d }~X qX qW | j| d S )3Njsonz*.jsoni`  i|                          K   L   M   N   O   P   i  i  i  i  i  i2  i9  i;  i=  iB  iC  iD  iE  iJ  iL  iX  iZ  i~  i  i  i  rS   Zttlr   rT   Ztrigrb)r   )r   rV   zSkipping match: %szSkipping deserialization: %s)rU   r   rV   )r   r   ospathjoindirname__file__r   r   	enumeratesplitreplacepmr   rW   r   Zbundlesopenr   r   r    r   r   r*   Z
assertTruer.   r/   	Exceptionr#   ZassertFalse)r1   Z
json_filesskip
skip_matcherrorsr)   fname_Zttl_filer5   r   fpr$   r%   matchr&   r'   r(   er   r   r   test_json_to_ttl_match   s    

*z(TestRDFSerializer.test_json_to_ttl_matchN)r7   r8   r9   rX   r|   r   r   r   r   rR      s   rR   c               @   s   e Zd ZdZdS )RoundTripRDFTestsrS   N)r7   r8   r9   ZFORMATr   r   r   r   r}   $  s   r}   __main__test),rK   Z
prov.modelr   Zprov.tests.utilityr   Zprov.tests.test_modelr   r   r   ri   r   loggingZ
prov.testsr   modelrq   Zrdflibr   Zrdflib.comparer	   ior
   r   	getLoggerr7   r.   r*   objectr+   r;   r<   rM   rQ   ZTestCaserR   r}   Z	TestSuiteZsuitedirmethod
startswithZaddTestZTextTestRunnerrunr   r   r   r   <module>   s6   

*:
l
