o
    QDiG#                     @   sV  d dl Z d dlZd dlmZ d dlZd dlmZmZmZm	Z	m
Z
 dZdd Zejjdd Zd	d
 Zejjejje jdk dddd Zdd Zdd Zdd Zejdddgdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Z d+d, Z!d-d. Z"ejj#d/d0 Z$d1d2 Z%ejjd3d4 Z&ejje
j'd5kd6dd7d8 Z(dS )9    N)import_module)DetectorFrictionlessExceptionPackageResourceplatformzLhttps://raw.githubusercontent.com/frictionlessdata/frictionless-py/master/%sc                  C   s\   t t} td W d    n1 sw   Y  | jj}|jdks$J |jds,J d S Nzdata/bad.resource.jsonresource-errorzbad.resource.json)	pytestraisesr   r   valueerrortypenotecountexcinfor    r   d/var/www/Datamplify/venv/lib/python3.10/site-packages/frictionless/resource/__spec__/test_general.py&test_resource_from_path_error_bad_path   s   
r   c                  C   s`   t t} ttd  W d    n1 sw   Y  | jj}|jdks&J |j	ds.J d S r   )
r
   r   r   r   BASEURLr   r   r   r   r   r   r   r   r   -test_resource_from_path_remote_error_bad_path   s   r   c                  C   s   d} t | g}|j| ksJ |jd u sJ |jdksJ |jd u s#J |jdu s*J |jdu s1J |j| ks8J tjdks]|	 dksEJ |j
jdksMJ |j
jdksUJ |j
jdkseJ W d    d S W d    d S 1 spw   Y  d S 	Nzdata/text.txttextFwindowss   text
 e1cbb0c3879af8347246f12c559a86b5@b9e68e1bea3e5b19ca6b2f98b73a54b73daafaa250484902e09982e07a12e733   )r   pathdatar   basepathmemory	multipartnormpathr   
read_bytesstatsmd5sha256bytesr   resourcer   r   r    test_resource_source_non_tabular    s(   

"r+   )   
   zpytest-vcr bug in Python3.8/9)reasonc                  C   s   t d } t| g}|j| ksJ |jd u sJ |jdksJ |jdu s%J |jdu s,J |jd u s3J |j| ks:J t	jdks_|
 dksGJ |jjdksOJ |jjdksWJ |jjdksgJ W d    d S W d    d S 1 srw   Y  d S r   )r   r   r   r   r   r!   r"   r    r#   r   r$   r%   r&   r'   r(   r)   r   r   r   'test_resource_source_non_tabular_remote4   s(   

"r/   c                  C   sd   t d} tt}|   W d    n1 sw   Y  |jj}|jdks(J |j	ds0J d S )Nzdata/bad.txtscheme-error)
r   r
   r   r   r$   r   r   r   r   r   r*   r   r   r   r   r   /test_resource_source_non_tabular_error_bad_pathJ   s   
r2   c                  C   s   t t} tddi W d    n1 sw   Y  | jj}| jj}|jdks+J |j	dks2J |d jdks;J |d j	dksDJ d S )Nnamer	   descriptor is not validr   z2one of the properties "path" or "data" is required)
r
   r   r   r   from_descriptorr   r   reasonsr   r   )r   r   r6   r   r   r   (test_resource_source_no_path_and_no_dataS   s   r7   c                  C   s   ddgddgddgg} t t}td| dd W d    n1 s#w   Y  |jj}|jj}|jd	ks7J |jd
ks>J |d jd	ksGJ |d jdksPJ d S )Nidr3   1english2u	   中国人r   )r3   r   r   r	   r4   r   z2properties "path" and "data" is mutually exclusive)	r
   r   r   r   r   r   r6   r   r   )r   r   r   r6   r   r   r   'test_resource_source_both_path_and_data^   s   r<   create_descriptor)F)Tc              	   C   s   t d}tddddg g g d}| stdi |n	t|jdi |}|jdks)J |jdks0J |jdks7J |jdks>J |jd u sEJ |j	g ksLJ |j
g ksSJ d S )Nzfrictionless.helpersr   r3   titledescription)r   r3   r>   r?   profileslicensessourcesr   )r   dictr   r=   r   r3   r>   r?   profilerA   rB   )r=   helpersoptionsr*   r   r   r   'test_resource_standard_specs_propertiesj   s*   rG   c                  C   s>   t ddddd} |  }|d dksJ |d dksJ d S )Nr3   r   hash   r3   r   rH   r(   r(   r   to_descriptorr*   
descriptorr   r   r   &test_resource_official_hash_bytes_rows   s   rO   c                  C   s>   t ddddd} |  }|d dksJ |d dksJ d S )Nr3   r   zsha256:hashrI   rJ   rH   r(   rK   rM   r   r   r   =test_resource_official_hash_bytes_rows_with_hashing_algorithm   s   rP   c                  C   *   t dd} | jdksJ | jdksJ d S )Nz**test**r?   z<p><strong>test</strong></p>r   r?   description_htmlr*   r   r   r   test_resource_description_html      
rV   c                  C   rQ   )N**test**

linerR   z'<p><strong>test</strong></p><p>line</p>rS   rU   r   r   r   (test_resource_description_html_multiline   rW   rY   c                  C   s&   t  } | jd u s
J | jdksJ d S )N rS   rU   r   r   r   &test_resource_description_html_not_set   s   r[   c                  C   rQ   )NrX   rR   z	test liner   r?   description_textrU   r   r   r   test_resource_description_text   rW   r^   c                  C   s*   t dd} | jdksJ | jdksJ d S )Nz(It's just a plain text. Another sentencerR   r\   rU   r   r   r   $test_resource_description_text_plain   rW   r_   c                  C   s0   t dd} | jdksJ d| _| jdksJ d S )Nz/data)r    z	/data/csv)r   r    rU   r   r   r   test_resource_set_base_path   s   
r`   c                  C   sH   t dgd} td| d}|j| ksJ t dd}||_|j|ks"J d S )Nna)field_missing_valuesdata/table.csv)detectorr,   )sample_size)r   r   rd   )detector_set_initr*   detector_setr   r   r   test_resource_set_detector   s   
rh   c                  C   s<   t  } t| d}|j| ksJ t  }||_|j|ksJ d S )N)package)r   r   ri   )test_package_1r*   test_package_2r   r   r   test_resource_set_package   s   
rl   c                  C   s2   t ddddd} d}t| t| ksJ d S )Nr*   zMy ResourcezMy Resource for the Guiderc   )r3   r>   r?   r   z
    {'name': 'resource',
     'title': 'My Resource',
     'description': 'My Resource for the Guide',
     'path': 'data/table.csv'}
    )r   reprtextwrapdedentstrip)r*   expectedr   r   r   test_resource_pprint   s   rr   c                  C   sp   t d} tt}|   W d    n1 sw   Y  |jj}|jdks(J |j	dr4|j	ds6J d S )Nbadr0   z	[Errno 2])
r   r
   r   r   openr   r   r   r   r   r1   r   r   r   >test_resource_not_existent_local_file_with_no_format_issue_287   s   
 ru   c                  C   sb   t d} tt}|   W d    n1 sw   Y  |jj}|jdks(J |jdks/J d S )Nzhttp://example.com/badr0   z;404 Client Error: Not Found for url: http://example.com/bad)	r   r
   r   r   rt   r   r   r   r   r1   r   r   r   ?test_resource_not_existent_remote_file_with_no_format_issue_287   s   
rv   r   zFix on Windowsc                  C   s^   t dddd} | jdd |  dddddd	d
dddddddddddgidks-J d S )Nr3   zdata/table.csvformatcsv)r3   r   formatT)r%   tablefilezutf-8ztext/csvzGsha256:350e813ea15d84c697a7b03446a8fa9d7fca9883167ad70986a173c29f8253fd:      r,   fieldscitystring)r3   r   
populationinteger)r3   r   r   rx   schemeencoding	mediatyperH   r(   r}   rowsschema)r   inferrL   rU   r   r   r   @test_resource_preserve_format_from_descriptor_on_infer_issue_188   s(   r   ))sysrn   	importlibr   r
   frictionlessr   r   r   r   r   r   r   markvcrr   r+   skipifversion_infor/   r2   r7   r<   parametrizerG   rO   rP   rV   rY   r[   r^   r_   r`   rh   rl   skiprr   ru   rv   r   r   r   r   r   r   <module>   sF    
	
			
	
	