o
    tBh|d                     @   s  d dl Z d dlZd dlZd dlZ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mZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z  d dl!m"Z" d dl#m$Z$ d	d
 Z%dd Z&dd Z'dd Z(dd Z)G dd dej*Z+dd Z,dd Z-dd Z.dd Z/dd Z0dd  Z1G d!d" d"Z2G d#d$ d$Z3G d%d& d&Z4G d'd( d(Z5e	j67d)e	j68d*e4e3 d+e5e3 d+gd,d- Z9G d.d/ d/Z:dSd1d2Z;d3d4 Z<e	j68d5d6d7gd8d9 Z=e	j68d:ej>ej?ej@ejAgd;d< ZBe	j68d=d>eCfd?eDfd@ejEfdAejFfdBejFfdCejGfdDdEdF fdGdHdF fdIdJdF fdKeHfg
e	j68dLej@ejIfejAejIfej>ejJfej?ejJfgdMdN ZKdOdP ZLdQdR ZMdS )T    N)sparse)
deprecated)available_ifif_delegate_has_method)	_test_sum)assert_raisesassert_warnsassert_no_warningsset_random_stateassert_raise_messageignore_warningscheck_docstring_parametersassert_allclose_dense_sparseassert_raises_regex
TempMemmapcreate_memmap_backed_data_delete_folder_convert_containerraisesassert_allclose)DecisionTreeClassifier)LinearDiscriminantAnalysisc                  C   s2   t  } t }t| d t|d |jdksJ d S )N   )r   r   r
   random_state)ldatree r   w/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/utils/tests/test_testing.pytest_set_random_state&   s
   

r   c               	   C   s  t ddd} d}t| }| |fD ]%}tjt|d t||d  W d    n1 s/w   Y  t|| qtjt	dd t| | W d    n1 sQw   Y  tj
t ddd	 }tt d
}tjtdd t|| W d    d S 1 sw   Y  d S )N	   r   zNot equal to tolerance match   zCan only compare two sparse   r   )offsets)   r#   zArrays are not equal)nparangereshaper   
csc_matrixpytestr   AssertionErrorr   
ValueErrordiagsonestocsr
csr_matrix)xmsgyXABr   r   r   !test_assert_allclose_dense_sparse/   s    
"r7   c                	   C   sl   t td' ttdd W d    n1 sw   Y  W d    d S W d    d S 1 s/w   Y  d S )NzHello world)r2   )r   r+   r   r,   r   r   r   r   test_assert_raises_msgB   s   "r8   c                  C   sj   dd } dd }t td| d ttt td| d ttt td| d ttt td| ttt ttfd| d S )Nc                 S   s   t | N)r,   )messager   r   r   _raise_ValueErrorI   s   z4test_assert_raise_message.<locals>._raise_ValueErrorc                   S      d S r9   r   r   r   r   r   	_no_raiseL      z,test_assert_raise_message.<locals>._no_raisetestzsomething else)r   r,   r   r+   	TypeErrorAttributeError)r;   r=   r   r   r   test_assert_raise_messageH   s6   		rB   c                     s  dd dd  t t t ttd tt ttd  W d    n1 s-w   Y  tt t td  W d    n1 sIw   Y  tt t td  W d    n1 sew   Y  t tttfd t fdd} tttfd fdd	}ttdfd
d}ttdfdd}ttd fdd}ttd fdd}t |  t | t | tt |  W d    n1 sw   Y  tt |  W d    n1 sw   Y  tt |  W d    n	1 sw   Y  fdd} fdd}fdd}fdd}	 fdd}
 fdd}t | t | t | tt |	  W d    n	1 sOw   Y  tt |
  W d    n	1 shw   Y  tt |  W d    n	1 sw   Y  t}d}tjt|d t|}|  W d    n	1 sw   Y  tjt|d t|d d! }W d    d S 1 sw   Y  d S )"Nc                   S      t dt d S Nzdeprecation warningwarningswarnDeprecationWarningr   r   r   r   _warning_functionr      z.test_ignore_warning.<locals>._warning_functionc                   S   s   t dt t d d S rD   rE   r   r   r   r   _multiple_warning_functionu   s   z7test_ignore_warning.<locals>._multiple_warning_functioncategoryc                      s        d S r9   r   r   rK   rI   r   r   decorator_no_warning   s   
z1test_ignore_warning.<locals>.decorator_no_warningc                      
      d S r9   r   r   rK   r   r   decorator_no_warning_multiple      
z:test_ignore_warning.<locals>.decorator_no_warning_multiplec                      rP   r9   r   r   rI   r   r    decorator_no_deprecation_warning   rS   z=test_ignore_warning.<locals>.decorator_no_deprecation_warningc                      rP   r9   r   r   rT   r   r   decorator_no_user_warning   rS   z6test_ignore_warning.<locals>.decorator_no_user_warningc                      rP   r9   r   r   rQ   r   r   )decorator_no_deprecation_multiple_warning   rS   zFtest_ignore_warning.<locals>.decorator_no_deprecation_multiple_warningc                      rP   r9   r   r   rQ   r   r   "decorator_no_user_multiple_warning   rS   z?test_ignore_warning.<locals>.decorator_no_user_multiple_warningc                      s2   t      W d    d S 1 sw   Y  d S r9   )r   r   rT   r   r   context_manager_no_warning   s   "z7test_ignore_warning.<locals>.context_manager_no_warningc                      s:   t ttfd    W d    d S 1 sw   Y  d S NrL   )r   rH   UserWarningr   rQ   r   r   #context_manager_no_warning_multiple   s   "z@test_ignore_warning.<locals>.context_manager_no_warning_multiplec                      6   t td    W d    d S 1 sw   Y  d S rZ   r   rH   r   rT   r   r   &context_manager_no_deprecation_warning      "zCtest_ignore_warning.<locals>.context_manager_no_deprecation_warningc                      r]   rZ   r   r[   r   rT   r   r   context_manager_no_user_warning   r`   z<test_ignore_warning.<locals>.context_manager_no_user_warningc                      r]   rZ   r^   r   rQ   r   r   /context_manager_no_deprecation_multiple_warning   r`   zLtest_ignore_warning.<locals>.context_manager_no_deprecation_multiple_warningc                      r]   rZ   ra   r   rQ   r   r   (context_manager_no_user_multiple_warning   r`   zEtest_ignore_warning.<locals>.context_manager_no_user_multiple_warningzA'obj' should be a callable.+you should use 'category=UserWarning'r    c                   S   r<   r9   r   r   r   r   r   r?      s   z!test_ignore_warning.<locals>.test)	r	   r   rH   r*   warnsr[   FutureWarningr   r,   )rO   rR   rU   rV   rW   rX   rY   r\   r_   rb   rc   rd   warning_classr!   silence_warnings_funcr?   r   rN   r   test_ignore_warningo   s   $ri   c                   @   s&   e Zd Zdd Zeeddd ZdS )	TestWarnsc              	   C   s   dd }t  : t dt t jd d  }tt tt|dks%J W d    n1 s/w   Y  t j|ks;J W d    n1 sEw   Y  t	t
 t| W d    n1 s^w   Y  tdd ddksnJ d S )Nc                   S   s   t d dS )Nyor   )rF   rG   r   r   r   r   f   s   
zTestWarns.test_warn.<locals>.fignorer   c                 S   s   | S r9   r   )r1   r   r   r   <lambda>       z%TestWarns.test_warn.<locals>.<lambda>r%   )rF   catch_warningssimplefilterr[   filtersr*   re   rf   r   r   r+   r	   )selfrl   filters_origr   r   r   	test_warn   s   

zTestWarns.test_warnrL   c              	   C   sv   dd }d}t jd jd d  }zz	tt| d}W n	 ty#   Y nw W |t jd _n|t jd _w |r9tdd S )Nc                   S   rC   )Nrk   )rF   rG   rf   r   r   r   r   rl      rJ   z,TestWarns.test_warn_wrong_warning.<locals>.fFrF   Tz#wrong warning caught by assert_warn)sysmodulesrr   r   r[   r+   )rs   rl   failedrr   r   r   r   test_warn_wrong_warning   s   
z!TestWarns.test_warn_wrong_warningN)__name__
__module____qualname__ru   r   rf   ry   r   r   r   r   rj      s    rj   c                 C      | | }|S zFunction f

    Parameters
    ----------
    a : int
        Parameter a
    b : float
        Parameter b

    Returns
    -------
    c : list
        Parameter c
    r   abcr   r   r   f_ok     r   c                 C   r}   )zFunction f

    Parameters
    ----------
    a : int
        Parameter a
    b : float
        Parameter b

    Results
    -------
    c : list
        Parameter c
    r   r   r   r   r   f_bad_sections   r   r   c                 C   s   ||  }|S r~   r   )r   r   r   r   r   r   f_bad_order3  r   r   c                 C   r}   )zFunction f

    Parameters
    ----------
    a : int
        Parameter a
    b : int
        Parameter b
    c : int
        Parameter c

    Returns
    -------
    d : list
        Parameter c
    r   )r   r   dr   r   r   f_too_many_param_docstringF  s   r   c                 C   r}   )zFunction f

    Parameters
    ----------
    a : int
        Parameter a

    Returns
    -------
    c : list
        Parameter c
    r   r   r   r   r   	f_missing[  s   r   c                 C   s   | | | | S )zFunction f

    Parameters
    ----------
    a: int
        Parameter a
    b:
        Parameter b
    c :
        This is parsed correctly in numpydoc 1.2
    d:int
        Parameter d
    e
        No typespec is allowed without colon
    r   )r   r   r   r   er   r   r   f_check_param_definitionl  s   r   c                   @      e Zd Zdd Zdd ZdS )Klassc                 C   r<   r9   r   rs   r4   r3   r   r   r   r     r>   zKlass.f_missingc                 C      dS )zFunction f

        Parameter
        ---------
        a : int
            Parameter a
        b : float
            Parameter b

        Results
        -------
        c : list
            Parameter c
        Nr   r   r   r   r   r     s   zKlass.f_bad_sectionsN)rz   r{   r|   r   r   r   r   r   r   r         r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )MockEstc                 C   r   )MockEstimatorNr   rs   r   r   r   __init__  ro   zMockEst.__init__c                 C      |S r9   r   r   r   r   r   fit  r>   zMockEst.fitc                 C   r   r9   r   rs   r4   r   r   r   predict  r>   zMockEst.predictc                 C   r   r9   r   r   r   r   r   predict_proba  r>   zMockEst.predict_probac                 C   r   )N      ?r   r   r   r   r   score  r>   zMockEst.scoreN)rz   r{   r|   r   r   r   r   r   r   r   r   r   r     s    r   c                   @   sh   e Zd Zdd Zedd dd Zedd edd	d
 Zedd dd Zeddd Z	dS )MockMetaEstimatorc                 C   
   || _ dS zMetaEstimator to check if doctest on delegated methods work.

        Parameters
        ---------
        delegate : estimator
            Delegated estimator.
        Ndelegaters   r   r   r   r   r        
zMockMetaEstimator.__init__c                 C      t | jdS )Nr   hasattrr   r   r   r   r   rn         zMockMetaEstimator.<lambda>c                 C      | j |S zThis is available only if delegate has predict.

        Parameters
        ----------
        y : ndarray
            Parameter y
        r   r   r   r   r   r   r        	zMockMetaEstimator.predictc                 C   r   )Nr   r   r   r   r   r   rn     r   %Testing a deprecated delegated methodc                 C   r   zThis is available only if delegate has score.

        Parameters
        ---------
        y : ndarray
            Parameter y
        Nr   r   r   r   r   r     ro   zMockMetaEstimator.scorec                 C   r   )Nr   r   r   r   r   r   rn     r   c                 C   r   zThis is available only if delegate has predict_proba.

        Parameters
        ---------
        X : ndarray
            Parameter X
        r   r   r   r   r   r        	zMockMetaEstimator.predict_proba-Testing deprecated function with wrong paramsc                 C   r   z,Incorrect docstring but should not be testedNr   r   r   r   r   r     ro   zMockMetaEstimator.fitN)
rz   r{   r|   r   r   r   r   r   r   r   r   r   r   r   r     s    





	

r   c                   @   sb   e Zd Zdd Zedddd Zeddeddd	 Zeddd
d Zeddd Z	dS )%MockMetaEstimatorDeprecatedDelegationc                 C   r   r   r   r   r   r   r   r     r   z.MockMetaEstimatorDeprecatedDelegation.__init__r   r   c                 C   r   r   r   r   r   r   r   r     r   z-MockMetaEstimatorDeprecatedDelegation.predictr   c                 C   r   r   r   r   r   r   r   r     ro   z+MockMetaEstimatorDeprecatedDelegation.scorec                 C   r   r   r   r   r   r   r   r     r   z3MockMetaEstimatorDeprecatedDelegation.predict_probar   c                 C   r   r   r   r   r   r   r   r     ro   z)MockMetaEstimatorDeprecatedDelegation.fitN)
rz   r{   r|   r   r   r   r   r   r   r   r   r   r   r   r     s    


	

r   z,ignore:if_delegate_has_method was deprecated	mock_metar   c                 C   s  t jdddd tt}|g ksJ ttdgd}|g ksJ ttdgd}|g ks,J t jtdd tt W d    n1 sBw   Y  t jtd	d ttj W d    n1 s^w   Y  tt	}| j
j}|g d
kssJ g dg dg dg ddd| d ddddddgdd| d d dddgdd| d dddgdd| d dddd gg}t|ttttj| j| j| j| jgD ]\}}t|}||ksJ d!||f qd S )"Nnumpydocz+numpydoc is required to test the docstringsz1.2.0)reason
minversionr   )rm   zUnknown section Resultsr    zUnknown section Parameter)zxsklearn.utils.tests.test_testing.f_check_param_definition There was no space between the param name and colon ('a: int')ztsklearn.utils.tests.test_testing.f_check_param_definition There was no space between the param name and colon ('b:')zwsklearn.utils.tests.test_testing.f_check_param_definition There was no space between the param name and colon ('d:int'))z9In function: sklearn.utils.tests.test_testing.f_bad_orderznThere's a parameter name mismatch in function docstring w.r.t. function signature, at index 0 diff: 'b' != 'a'
Full diff:z- ['b', 'a']z+ ['a', 'b'])zHIn function: sklearn.utils.tests.test_testing.f_too_many_param_docstringz_Parameters in function docstring have more items w.r.t. function signature, first extra item: cr   - ['a', 'b']z+ ['a', 'b', 'c']z?          +++++)z7In function: sklearn.utils.tests.test_testing.f_missingzaParameters in function docstring have less items w.r.t. function signature, first missing item: br   r   z+ ['a'])z=In function: sklearn.utils.tests.test_testing.Klass.f_missingaParameters in function docstring have less items w.r.t. function signature, first missing item: Xr   - ['X', 'y']+ []zIn function: z!sklearn.utils.tests.test_testing.z.predictznThere's a parameter name mismatch in function docstring w.r.t. function signature, at index 0 diff: 'X' != 'y'r   z- ['X']z?   ^z+ ['y'].r   z&potentially wrong underline length... zParameters z--------- in z.scorez.fitr   r   r   z
"%s"
 not in 
"%s")r*   importorskipr   r   r   r   RuntimeErrorr   r   r   	__class__rz   zipr   r   r   r   r   r   )r   	incorrectmock_meta_namemessagesr2   rl   r   r   r   test_check_docstring_parameters  s   	


	

	
Gr   c                   @   r   )RegistrationCounterc                 C   s
   d| _ d S )Nr   )nb_callsr   r   r   r   r     s   
zRegistrationCounter.__init__c                 C   s    |  j d7  _ |jtu sJ d S )Nr%   )r   funcr   )rs   to_register_funcr   r   r   __call__  s   zRegistrationCounter.__call__N)rz   r{   r|   r   r   r   r   r   r   r     r   r   rc                 C   s:   t |tjsJ |dk}|jj|u sJ tj| | d S )Nr   )
isinstancer&   memmapflags	writeabletestingassert_array_equal)input_array	mmap_data	mmap_moder   r   r   r   check_memmap  s   r   c                 C   s   t  }| td| td}t|}t|| tj	|j
}W d    n1 s*w   Y  tjdkr<tj|r<J |jdksCJ d}t||d}t|||d tj	|j
}W d    n1 sdw   Y  tjdkrvtj|rvJ |jdks}J d S )Nregisterr   ntr%   r+)r   r"   )r   setattratexitr&   r.   r   r   ospathdirnamefilenamenameexistsr   )monkeypatchregistration_counterr   datatemp_folderr   r   r   r   test_tempmemmap  s$   




r   alignedFTc           	      C   s@  t  }| td| td}t||d}t|| |jdks!J t|d|d\}}t|| |tj	
|jks:J |jdksAJ d}t|||d	}t||| |jdksWJ ||d |d g}|rtjtd
d t|dd W d    d S 1 s{w   Y  d S t|dd}t||D ]	\}}t|| q|jdksJ d S )Nr   r   )r   r%   T)return_folderr   r"   r   r   r   z4If aligned=True, input must be a single numpy array.r    F   )r   r   r   r&   r.   r   r   r   r   r   r   r   r*   r   r,   r   )	r   r   r   r   r   folderr   
input_listmmap_data_listr   r   r   test_create_memmap_backed_data  s6   



"r   dtypec                 C   sd   t d| }|jd sJ |jd sJ t|}t|ddd}t|}|tj|ddks0J d	S )
z2Test memory mapped array on contiguous memoryview.
   C_CONTIGUOUSALIGNEDr   Tr   gdy=)relN)r&   r'   astyper   r   r   r*   approx)r   r1   
sum_originx_mmapsum_mmapr   r   r   test_memmap_on_contiguous_data  s   r   z constructor_name, container_typelisttuplearrayr   
sparse_csr
sparse_csc	dataframec                   C      t djS Npandas)r*   r   	DataFramer   r   r   r   rn     r   rn   seriesc                   C   r   r   )r*   r   Seriesr   r   r   r   rn     r   indexc                   C   r   r   )r*   r   Indexr   r   r   r   rn     r   slicezdtype, superdtypec                 C   s   | dv r| }ddg}t || |d}t||sJ | dv r+tt|d |s)J dS t|dr9|j|ks7J dS t|drG|jd |ksIJ dS dS )	z\Check that we convert the container to the right type of array with the
    right data type.)r   r  r  r   r%   r   )r   r   r  r   dtypesN)r   r   r&   
issubdtypetyper   r   r  )constructor_namecontainer_typer   
superdtype	containercontainer_convertedr   r   r   test_convert_container  s"    

r  c               	   C   s  t t t 1 sw   Y  t tdd} td1 sw   Y  | js(J t tddgd} td1 s8w   Y  | jsBJ tj tdd t t} td1 sVw   Y  W d    n1 sew   Y  | jroJ tj tdd t tdd} t 1 sw   Y  W d    n1 sw   Y  | jrJ tj tdd t tdd} td1 sw   Y  W d    n1 sw   Y  | jrJ tj td	d t td
d} td1 sw   Y  W d    n1 sw   Y  | jrJ tj tdd t td
dd} td1 sw   Y  W d    n	1 s#w   Y  | jr.J tj tdd t t} W d    n	1 sFw   Y  W d    n	1 sVw   Y  | jraJ t td
dd} W d    n	1 stw   Y  | jrJ t ttf t 1 sw   Y  t ttf t 1 sw   Y  t t( t ttf W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nzhow are your    zhello how are youznot this onezthis will be raisedzthe failure message)err_msgzthis is ignoredz,should contain one of the following patternshellozBad message)r!   r  zDid not raiseT)r!   may_pass)r   r@   raised_and_matchedr*   r,   r+   )cmr   r   r   test_raises  s   








 $r  c                   C   s  t tjdgtjdd tt t tjdgtjdd W d    n1 s(w   Y  t tjdgtjdd tt t tjdgtjdd W d    n1 sUw   Y  tt t tjdgtjdd W d    n1 svw   Y  t tjdgtjddd	d
 d S )Ng㈵ ?r  r   gX ?gc^  ?g55  ?gh㈵>g        gh㈵>)atol)r   r&   r   float32r*   r   r+   float64r   r   r   r   "test_float32_aware_assert_allclose]  s    r  )r   )NrF   unittestrv   r   r   numpyr&   scipyr   r*   sklearn.utils.deprecationr   sklearn.utils.metaestimatorsr   r   %sklearn.utils._readonly_array_wrapperr   sklearn.utils._testingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   sklearn.treer   sklearn.discriminant_analysisr   r   r7   r8   rB   ri   TestCaserj   r   r   r   r   r   r   r   r   r   r   markfilterwarningsparametrizer   r   r   r   r   r  r  int32int64r   r   r   ndarrayr0   r)   r  integerfloatingr  r  r  r   r   r   r   <module>   s    D	'm11
1

u
	
"







	F