B
    0°zfëB  ã               @   st  d Z ddlZddlZddlZddlmZ ddlZyddlmZ W n e	k
rX   dZY nX dZ
dZdZd	Zd
ZddddgZe
eeeegZdZdZdZG dd„ dƒZeeeej d¡dd… ƒƒdk räddlZdZe eejf ¡ n„dd„ Zdd„ Zdd„ Zdd„ Z ej!d d!d"d#„ ƒZ"d$d%„ Z#ej!d d!d&d'„ ƒZ$d(d)„ Z%d*d+„ Z&dd,l'm(Z( d-d.„ Z)e(j*j+Z,e)e(j*_+d/d0„ Z-dS )1a¤  
The pytest plugin for Hypothesis.

We move this from the old location at `hypothesis.extra.pytestplugin` so that it
can be loaded by Pytest without importing Hypothesis.  In turn, this means that
Hypothesis will not load our own third-party plugins (with associated side-effects)
unless and until the user explicitly runs `import hypothesis`.

See https://github.com/HypothesisWorks/hypothesis/issues/3140 for details.
é    N)Ú	signature)Úxml_keyZ_xmlz--hypothesis-profilez--hypothesis-verbosityz--hypothesis-show-statisticsz--hypothesis-seedz--hypothesis-explainÚquietÚnormalÚverboseÚdebugaq  Function-scoped fixture {0!r} used by {1!r}

Function-scoped fixtures are not reset between examples generated by
`@given(...)`, which is often surprising and can cause subtle test bugs.

If you were expecting the fixture to run separately for each generated example,
then unfortunately you will need to find a different way to achieve your goal
(e.g. using a similar context manager instead of a fixture).

If you are confident that your test will work correctly even though the
fixture is not reset between generated examples, you can suppress this health
check to assure Hypothesis that you understand what you are doing.
Z_hypothesis_statsZ_hypothesis_failing_examplesc               @   s   e Zd Zdd„ Zdd„ ZdS )ÚStoringReporterc             C   s0   dt jkst‚ddlm} || _|| _g | _d S )NÚ
hypothesisr   )Údefault)ÚsysÚmodulesÚAssertionErrorÚhypothesis.reportingr
   ÚreportÚconfigÚresults)Úselfr   r
   © r   ú[/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/_hypothesis_pytestplugin.pyÚ__init__C   s
    zStoringReporter.__init__c             C   s>   | j  dd¡dkr|  |¡ t|tƒs.t|ƒ}| j |¡ d S )NÚcaptureÚfdÚno)r   Ú	getoptionr   Ú
isinstanceÚstrÚreprr   Úappend)r   Úmsgr   r   r   Ú__call__K   s
    

zStoringReporter.__call__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   B   s   r   Ú.é   )é   é   a  
        You are using pytest version %s. Hypothesis tests work with any test
        runner, but our pytest plugin requires pytest 4.6 or newer.
        Note that the pytest developers no longer support your version either!
        Disabling the Hypothesis pytest plugin...
    c             C   sf   |   dd¡}|jtddd |jtdtdd |jtdd	d
d |jtddd |jtddd
d d S )Nr	   Ú
HypothesisÚstorez0Load in a registered hypothesis.settings profile)ÚactionÚhelpz1Override profile with verbosity setting specified)r)   Úchoicesr*   Ú
store_truez%Configure when statistics are printedF)r)   r*   r
   z*Set a seed to use for all Hypothesis testsz7Enable the `explain` phase for failing Hypothesis tests)ZgetgroupZ	addoptionÚLOAD_PROFILE_OPTIONÚVERBOSITY_OPTIONÚ_VERBOSITY_NAMESÚPRINT_STATISTICS_OPTIONÚSEED_OPTIONÚEXPLAIN_OPTION)ÚparserÚgroupr   r   r   Úpytest_addoptionb   s0    r5   c                s   t t‡ fdd„tD ƒƒƒS )Nc             3   s   | ]}ˆ   |¡V  qd S )N)r   )Ú.0Úopt)r   r   r   ú	<genexpr>‚   s    z)_any_hypothesis_option.<locals>.<genexpr>)ÚboolÚanyÚ_ALL_OPTIONS)r   r   )r   r   Ú_any_hypothesis_option   s    r<   c             C   s|   | j jdks"dtjks"t| ƒs"d S ddlm}m} | j jdk rP|jj	|jk rPd S |j 
¡ }|dkrld|› }d|j›|› S )Né   r	   r   )Ú	VerbosityÚsettingsÚ z -> zhypothesis profile )Úoptionr   r   r   r<   r	   r>   r?   r
   Ú	verbosityZshow_changedÚ_current_profile)r   r>   r?   Zsettings_strr   r   r   Úpytest_report_header„   s    


rD   c             C   s$  |   dd¡ t| ƒsd S ddlm}m}m}m} |  t¡}|rH| 	|¡ |  t
¡}|r–||jjjkr–|| }|j› d|› d}|j||d | 	|¡ |  t¡râ|j|jjkrâ|j› d}|jj|jf }	|j||	d	 | 	|¡ |  t¡}
|
d k	r yt|
ƒ}
W n tk
r   Y nX |
|_d S )
NÚmarkersz'hypothesis: Tests which use hypothesis.r   )ÚPhaser>   Úcorer?   z-with-z
-verbosity)rB   z-with-explain-phase)Úphases)Zaddinivalue_liner<   r	   rF   r>   rG   r?   r   r-   Zload_profiler.   r
   rB   ÚnamerC   Zregister_profiler2   ÚexplainrH   r1   ÚintÚ
ValueErrorZglobal_force_seed)r   rF   r>   rG   r?   ZprofileZverbosity_nameZverbosity_valuerI   rH   Úseedr   r   r   Úpytest_configure•   s4    







rN   T)Zhookwrapperc             #   sv  d}t ˆdƒrdtjks"d V  d S ddlm} ddlm} ˆj dd¡d	k|_	d|_
|ˆjƒsÚ‡ fd
d„}tˆjddƒr”ddlm‰  |ˆj› dƒ d}x6dD ].\}}t ˆj|ƒržddlm‰  |||f ƒ qžW d V  n˜ddlm}m}	 ddlm}
 ddlm} ddlm} ddlm}m‰ tˆjdd ƒ}	|	d k	rÚ|j|	jkrÚd }xˆjjjˆˆj d dj! "¡ D ]p}|d kr„t#t$ˆj ƒj%ƒ}xN|D ]F}|j&|krŠˆj '|j&¡}|j(dkrŠ||	t) *|j&ˆj¡|jƒ qŠW qfW ˆ +d¡d k	r ˆj ,¡ }|ˆjjj-_.t/ˆjƒ}‡‡fdd„}| 0|¡6 ||ƒ" |
 0ˆ¡ d V  W d Q R X W d Q R X W d Q R X |j1rrt2|j1ƒˆ_3d S )NTÚobjr	   r   )rG   )Úis_hypothesis_testZtbstyleÚautoÚnativec                s   ˆ | ƒ‚d S )Nr   )r   )ÚInvalidArgumentr   r   Úraise_hypothesis_usage_errorÌ   s    z9pytest_runtest_call.<locals>.raise_hypothesis_usage_errorZis_hypothesis_strategy_functionF)rS   zÞ is a function that returns a Hypothesis strategy, but pytest has collected it as a test function.  This is useless as the function body will never be executed.  To define a test function, use @given instead of @composite.z?Using `@%s` on a test without `@given` is completely pointless.))ÚexampleZhypothesis_explicit_examples)rM   Z_hypothesis_internal_use_seed)r?   Z%_hypothesis_internal_settings_applied)Zreproduce_exampleZ*_hypothesis_internal_use_reproduce_failure)ÚHealthCheckr?   )Úcurrent_pytest_item)Úfail_health_check)Úwith_reporter)Ú	collectorÚdescribe_statisticsZ!_hypothesis_internal_use_settings)ÚnodeÚfuncÚclsÚfunctionZparametrizec                s   ˆj | d< ˆ | ƒˆ_d S )NÚnodeid)r`   Úhypothesis_statistics)Ústats)r[   Úitemr   r   Únote_statistics  s    
z,pytest_runtest_call.<locals>.note_statistics)4Úhasattrr   r   r	   rG   Úhypothesis.internal.detectionrP   r   r   Zpytest_shows_exceptiongroupsZrunning_under_pytestrO   ÚgetattrZhypothesis.errorsrS   r`   rV   r?   Zhypothesis.internal.escalationrW   Zhypothesis.internal.healthcheckrX   r   rY   Zhypothesis.statisticsrZ   r[   Zfunction_scoped_fixtureZsuppress_health_checkÚ_requestZ_fixturemanagerZgetfixtureinfor_   Zname2fixturedefsÚvaluesÚ	frozensetr   Ú
parametersÚargnameZ_get_active_fixturedefÚscopeÚ_FIXTURE_MSGÚformatZget_closest_markerÚencodeZ
inner_testZ_hypothesis_internal_add_digestr   Z
with_valuer   ÚlistÚhypothesis_report_information)rc   Z__tracebackhide__rG   rP   rT   ÚmessagerI   Ú	attributerV   r?   rW   rX   rY   rZ   ÚargnamesZfx_defsZfxZ	active_fxÚkeyr(   rd   r   )rS   r[   rc   r   Úpytest_runtest_call·   sl    









$rw   c             C   s@   t | dƒr| j ||¡S t | dƒr0| j ||¡S t| ||ƒS d S )NÚstashÚ_store)re   rx   Úgetry   rg   )r   rv   r
   r   r   r   Ú
_stash_get   s
    

r{   c             #   sZ  d V   ¡ }t| dƒr,|j dd | j¡f¡ |jdkr:d S | jj 	d¡}t| dƒrÚ| j
}t | ¡ ¡ ¡ }d| j }t| jtd ƒ}|r’| ||¡ |d k	r¤||jt< | jj 	d¡}|d k	rÚt|d	g ƒ|jj|d
dg |_t| td ƒ}	|	rV|d k	rVyddlm‰ m}
 W n tk
r    d S X |
| j‡ fdd„|	D ƒƒ}|d k	rVt  |¡|jt< d S )Nrr   r'   Ú
ZteardownÚterminalreporterra   zhypothesis-statistics-ÚhtmlÚextrazHypothesis stats)rI   r   )ÚFAIL_MSGÚget_patch_forc                s   g | ]}|ˆ f‘qS r   r   )r6   Úx)r€   r   r   ú
<listcomp>Z  s    z-pytest_runtest_makereport.<locals>.<listcomp>)!Z
get_resultre   Úsectionsr   Újoinrr   Úwhenr   ZpluginmanagerZ	getpluginra   Úbase64Ú	b64encoderp   Údecoder`   r{   r   Zadd_global_propertyÚ__dict__Ú	STATS_KEYrg   ÚextrasÚtextr   ÚFAILING_EXAMPLES_KEYÚhypothesis.extra._patchingr€   r   ÚImportErrorrO   ÚjsonÚdumps)rc   Úcallr   r}   rb   Zstats_base64rI   ÚxmlZpytest_htmlÚfailing_examplesr   Ztripler   )r€   r   Úpytest_runtest_makereport*  s:    







r–   c             C   sê   g }| j  t¡}|r|  d¡ xb| j ¡ D ]T}xN|D ]F}|j t¡}|rZ|rZ|  	|d ¡ |j t
¡}|r4| t |¡¡ q4W q*W |ræddlm}m}m}	 ||ƒ}
y|ƒ  |	|
ƒ}W n tk
rÈ   d S X |  d¡ |  	d|› d¡ d S )NzHypothesis Statisticsz

r   )Ú
gc_patchesÚ
make_patchÚ
save_patchr'   z`git apply z'` to add failing examples to your code.)r   r   r0   Úsectionrb   ri   rŠ   rz   r‹   Z
write_linerŽ   r   r‘   Úloadsr   r—   r˜   r™   Ú	Exception)r}   r•   Zprint_statsZreportsr   rb   Zfexr—   r˜   r™   ÚpatchÚfnamer   r   r   Úpytest_terminal_summary^  s.    


rŸ   c             C   sL   dt jkrd S ddlm} x,| D ]$}t|tjƒr ||jƒr | d¡ q W d S )Nr	   r   )rP   )	r   r   rf   rP   r   ÚpytestÚFunctionrO   Z
add_marker)ÚitemsrP   rc   r   r   r   Úpytest_collection_modifyitems|  s    

r£   )Úfixturesc             C   s:   dt jkr0ddlm} ||ƒr0td|j› dƒ‚t| |ƒS )Nr	   r   )rP   z!Can't apply @pytest.fixture() to z9 because it is already decorated with @hypothesis.given())r   r   rf   rP   ÚRuntimeErrorr    Ú
_orig_call)r   r_   rP   r   r   r   Ú_ban_given_callŒ  s    
r§   c               C   s   dS )zCRequired for `pluggy` to load a plugin from setuptools entrypoints.Nr   r   r   r   r   Úload›  s    r¨   ).Ú__doc__r‡   r‘   r   Úinspectr   r    Z_pytest.junitxmlr   r   r-   r.   r0   r1   r2   r/   r;   rn   r‹   rŽ   r   ÚtupleÚmaprK   Ú__version__ÚsplitÚwarningsZPYTEST_TOO_OLD_MESSAGEÚwarnr5   r<   rD   rN   Zhookimplrw   r{   r–   rŸ   r£   Z_pytestr¤   r§   ZFixtureFunctionMarkerr   r¦   r¨   r   r   r   r   Ú<module>   sT   
""i
4