
    1VhX                        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m	Z	 d dl
Zd dlmZ d dlZd dlZ	  ej"                   ed            \  ZZdZ ej,                  e        ej.                  e       [[ G d d	ej2                        Z eej6                  j9                  d
      d d D  cg c]
  }  e|        c}       Zedd       Zd Z d Z!y# e$ r dZY fw xY wc c} w )    N)contextmanagerwraps)repack_fieldsi  TFc                   b    e Zd ZdZed        Zed        ZddZddZd Z	d Z
d	 Zdd
ZddZy)TestCasez(
        Base class for unit tests.
    c                 :    t        j                  d      | _        y )Nz
h5py-test_)prefix)tempfilemkdtemptempdirclss    A/home/dcms/DCMS/lib/python3.12/site-packages/h5py/tests/common.py
setUpClasszTestCase.setUpClass0   s    &&l;    c                 B    t        j                  | j                         y N)shutilrmtreer   r   s    r   tearDownClasszTestCase.tearDownClass4   s    ckk"r   Nc                 N    || j                   }t        j                  |||      S )N)dir)r   r   mktemp)selfsuffixr
   r   s       r   r   zTestCase.mktemp8   s#    ;,,Cvv377r   c                     |ddl m} |j                  }d }|j                         dk(  r| j	                  |||      }|j                  |d      }|S )Nr   )MPI)mpi4pyr   
COMM_WORLDGet_rankr   bcast)r   commr   r
   r   r   fnames          r   
mktemp_mpizTestCase.mktemp_mpi=   sM    <">>D==?aKK4E

5!$r   c                 V    t        j                  | j                         d      | _        y )Nw)h5pyFiler   fr   s    r   setUpzTestCase.setUpG   s    4;;=#.r   c                 b    	 | j                   r| j                   j                          y y #  Y y xY wr   )r*   closer+   s    r   tearDownzTestCase.tearDownJ   s*    	vv 	s   &* .c                     |D ]#  }d}|D ]
  }||k(  s	d} |rt        d|z         |D ]#  }d}|D ]
  }||k(  s	d} |rt        d|z         y )NFTz Item '%s' appears in a but not bz Item '%s' appears in b but not a)AssertionError)r   abxmatchys         r   assertSameElementszTestCase.assertSameElementsQ   s     	MAE !6 E! $%G!%KLL	M  	MAE !6 E! $%G!%KLL	Mr   c                    |d}|d}nd|z  }t        j                  |      st        j                  |      rdt        j                  |      rt        j                  |      sJ d|d|d|       t        j                  |      }t        j                  |      }|j                  |j                  k(  s$J d|j                  d	|j                  d
|       |j                  |j                  k7  r|r|j                  }|j                  }n*t        |j                        }t        |j                        }||k(  sJ d|d	|d
|       |sZ||j                  k7  rt        t        j                  |            }||j                  k7  rt        t        j                  |            }|j                  j                  @|j                  j                  D ]&  }d|d|}| j                  ||   ||   |||       ( y|j                  j                  dv rAt        j                  t        j                  |d   |d   z
        |k        sJ d||fz         y|j                  j                  dk(  r?t        |j                  |j                        D ]  \  }	}
| j                  |	|
|||        yt        j                  |d   |d   k(        s!J d|j                  j                  d|       y)z Make sure dset and arr have the same shape, dtype and contents, to
            within the given precision, optionally ignoring differences in dtype alignment.

            Note that dset may be a NumPy array or an HDF5 dataset.
        Ngh㈵> z (%s)zScalar/array mismatch ("z" vs "z")zShape mismatch (z vs )zDtype mismatch (z[FIELD z] )message	precisioncheck_alignment)ir*   .z!Arrays differ by more than %.3f%sOzArrays are not equal (dtype z) )npisscalarasarrayshapedtyper   namesassertArrayEqualkindallabszipflatstr)r   dsetarrr;   r<   r=   normalized_dset_dtypenormalized_arr_dtypenv1v2s              r   rF   zTestCase.assertArrayEqualb   s    I?G'G;;tC 0;;t$S)9 P<@#wOP9::d#D**S/CzzSYY& 	M-1ZZGL	M&::"(,

%'*yy$(5djj(A%'4SYY'?$(,@@ g1FH\^efg@ #(DJJ6(D)9:D'3994'

38C99??&YY__ ~-.8%%d1gs1vwR[m|%}~ YY^^z)66"&&cSX!56BC K3y'6JJKCYY^^s"dii2 uB%%b"gds%tu 66$s)s3x/0 P8;		wOP0r   c                    d}	 ||   }t        |t              r|n|f}|D| j	                  ||          |s,| j	                  |j
                  j                  |      |       yy| j                  |      5  ||    ddd       |s6| j                  |      5  |j
                  j                  |       ddd       yy# t         $ r}t        |      }Y d}~d}~ww xY w# 1 sw Y   cxY w# 1 sw Y   yxY w)a   Apply slicing arguments "s" to both dset and arr.

        Succeeds if the results of the slicing are identical, or the
        exception raised is of the same type for both.

        "arr" must be a Numpy array; "dset" may be a NumPy array or dataset.
        N)	Exceptiontype
isinstancetuplerF   _fast_readerreadassertRaises)	r   rM   rN   sskip_fast_readerexc
arr_resultes_fasts	            r   assertNumpyBehaviorzTestCase.assertNumpyBehavior   s     	QJ !E*;!!$q':6#%%%%**62 $ ""3' Q $&&s+ 3%%**623 3 $#  	q'C	 3 3s/   B< 5CC)<	CCCC&)C2).hdf5r9   N)Nrc   r9   N)NNT)F)__name__
__module____qualname____doc__classmethodr   r   r   r%   r,   r/   r7   rF   rb    r   r   r   r   *   sU     < < # #8
/M"2Ph3r   r   .   c              #      K   t        j                  d| d      5 }|j                  }|!|j                  |       |j	                          ddd        t        j                  |d       y# 1 sw Y   %xY ww)z
    Context manager which yields the path to a closed temporary file with the
    suffix `suffix`. The file will be deleted on exiting the context. An
    additional argument `text` can be provided to have the file contain `text`.
    w+tF)r   deleteNT)ignore_errors)r   NamedTemporaryFilenamewriteflushr   r   )r   text	test_file	file_names       r   closed_tempfilerw      sn      
	$	$fU
 	NN	OOD!OO O
MM)40 s   A;0A/$A;/A84A;c                 .     t                fd       }|S )z!Runs a test in its own subprocessc                    t        j                        dz   | j                  j                  z   }d|z   }dD ]  }|j	                  |d      } t
        j                  j                  |d       }|r | g|i |S dt
        j                  |<   t
        j                  j                         }d||<   |j                  t        di              t               5 }t        |d      5 }	t        j                  t        j                   dd	|g|	|	|
      }
d d d        t        |d      5 }	|	j#                         }d d d        d d d        
dk(  s
J dz          y # 1 sw Y   FxY w# 1 sw Y   -xY w# 1 sw Y   1xY w)Nz::IN_SUBPROCESS_z/\,:._1subproc_envrm   z-mpytest)stdoutstderrenvrtr   
)inspectgetsourcefilenoderq   replaceosenvirongetcopyupdategetattrrw   open
subprocesscallsys
executablerZ   )requestargskwargs	curr_testinsubcdefinedr   r   fhrtnoutr*   s               r   wrapperzinsubprocess.<locals>.wrapper   sd   ))!,t3gll6G6GG	 9, 	*AMM!S)E	***..-W.t.v.. #BJJu**//#CCJJJwq-45 " $f&%( IB$//3>>49*U13BCICI &$' $2'')C$	$ !8'TCZ'8I I$ $	$ $s<   E/&,EE/&E#7E/E 	E/#E,	(E//E8r   )r*   r   s   ` r   insubprocessr      s     
1X( (0 Nr   c                       fd}|S )z9Set environment variables for the @insubprocess decoratorc                     | _         | S r   )r}   )r*   ds    r   	decoratorzsubproc_env.<locals>.decorator   s    r   ri   )r   r   s   ` r   r}   r}      s     r   )r9   N)"r   r   r   r   r   r   
contextlibr   	functoolsr   numpyr@   numpy.lib.recfunctionsr   r(   unittestutmkstempchrtestfiler$   UNICODE_FILENAMESr.   unlinkUnicodeErrorr   rX   __version__splitintNUMPY_RELEASE_VERSIONrw   r   r}   )r>   s   0r   <module>r      s     	     %   0  	&h&&s6{3OHe BHHXBIIeJ3r{{ J3X r~~/C/CC/H1/MN!s1vNO 1 1"<Q  l Os   C 2C%C"!C"