
    d|                        d Z 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Zddlm	Z	m
Z
mZmZ ddlmZ ddlmZ ddlZddlmZ ddlZ G d	 d
e
          Z e	j        ej        j        dk     d           G d de
                      Z e	j        ej        j        dk     d          ej        j         G d de
                                  Z G d de
          Z G d de
          Z e	j        ej        j        dk     d           G d de
                      Z e	j        ej        j        dk     d           G d de
                      Z  G d de
          Z! G d de
          Z" e	j        e d            G d! d"e
                      Z# G d# d$e
          Z$ G d% d&e
          Z% G d' d(e
          Z& G d) d*e
          Z' G d+ d,e
          Z( G d- d.e
          Z) G d/ d0e
          Z* G d1 d2e
          Z+ej        j,         G d3 d4                      Z- e	j        ej        j        dk     d           G d5 d6e
                      Z.ej        /                    ej        j        d7k     o-ej        j        dd         d8k    pej        j        d         d9k     d:;          ej        /                    d<ej0        v d=;           G d> d?                                  Z1d@ Z2dS )Az`
    File object test module.

    Tests all aspects of File objects, including their creation.
    N   )utTestCaseUNICODE_FILENAMESclosed_tempfile)
direct_vfd)File   )h5c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )TestFileOpenz=
        Feature: Opening files with Python-style modes.
    c                    |                                  }t          j        t                    5  t	          |          5  	 ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t	          |d          5  	 ddd           n# 1 swxY w Y   t          j        |t          j                   	 t	          |          5 }| 	                    |           | 
                    |j        d           ddd           n# 1 swxY w Y   t          j        |t          j                   n$# t          j        |t          j                   w xY wt          |d          5 }|                    d           ddd           n# 1 swxY w Y   |                     t                     5  t	          |           ddd           dS # 1 swxY w Y   dS )z8 Default semantics in the presence or absence of a file Nwrwb    )mktemppytestraisesFileNotFoundErrorr	   oschmodstatS_IREAD
assertTrueassertEqualmodeS_IWRITEopenwriteassertRaisesOSErrorselffnamefs      4lib/python3.11/site-packages/h5py/tests/test_file.pytest_defaultzTestFileOpen.test_default&   s    ],-- 	 	e                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 % 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	
%%%	+e ."""  ---. . . . . . . . . . . . . . . HUDM****BHUDM**** % 	!GGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	w'' 	 	KKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A#A A#A	A#A	A##A'*A'>BBB7D. 1D7D. DD. 
DD. .!E"FFF)GG
G
c                 >   |                                  }t          |d          }|                     |           |                    d           |                                 t          |d          }|                     d|           |                                 dS )z' Mode 'w' opens file in overwrite mode r   fooN)r   r	   r   create_groupcloseassertNotInr$   r%   fids      r'   test_createzTestFileOpen.test_create@   s    5#		5#$$$		    c                 &   |                                  }t          |d          }|                     |           |                                 |                     t
                    5  t          |d           ddd           dS # 1 swxY w Y   dS )z( Mode 'w-' opens file in exclusive mode w-N)r   r	   r   r,   r!   FileExistsErrorr.   s      r'   test_create_exclusivez"TestFileOpen.test_create_exclusiveK   s    5$		// 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   (BB
B
c                 L   |                                  }t          |d          }	 |                     |           |                    d           d|v sJ 	 |                                 n# |                                 w xY wt          |d          }	 d|v sJ |                    d           d|v sJ 	 |                                 n# |                                 w xY wt          j        |t          j                   	 t          j
        t                    5  t          |d           ddd           n# 1 swxY w Y   t          j        |t          j        t          j        z             dS # t          j        |t          j        t          j        z             w xY w)zE Mode 'a' opens file in append/readwrite mode, creating if necessary ar*   barN)r   r	   r   r+   r,   r   r   r   r   r   r   PermissionErrorr   r.   s      r'   test_appendzTestFileOpen.test_appendT   s   5#	OOC   U###C<<<<<IIKKKKCIIKKKK5#	C<<<<U###C<<<<<IIKKKKCIIKKKK
%%%	:// ! !UC   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! HUDL4=899999BHUDL4=89999sG   0A, ,B!C C#E5 D<0E5 <E  E5 E E5 5.F#c                    |                                  }t          |d          }|                                 |                     |           t          |d          }|                     |           |                     t                    5  |                    d           ddd           n# 1 swxY w Y   |                                 dS )z& Mode 'r' opens file in readonly mode r   r   r*   N)r   r	   r,   assertFalser   r!   
ValueErrorr+   r.   s      r'   test_readonlyzTestFileOpen.test_readonlyn   s    5#		5#z** 	$ 	$U###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$		s   B//B36B3c                 *   |                                  }t          |d          }|                    d           |                                 t          |d          }d|v sJ |                    d           d|v sJ |                                 dS )z1 Mode 'r+' opens existing file in readwrite mode r   r*   r+r8   N)r   r	   r+   r,   r.   s      r'   test_readwritezTestFileOpen.test_readwritez   s    5#		5$||||||||		r1   c                 8   |                                  }|                     t                    5  t          |d           ddd           n# 1 swxY w Y   |                     t                    5  t          |d           ddd           dS # 1 swxY w Y   dS )z( Modes 'r' and 'r+' do not create files r   Nr@   )r   r!   r   r	   r$   r%   s     r'   test_nonexistent_filez"TestFileOpen.test_nonexistent_file   s   011 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	011 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s#   AAA1BBBc                     |                      t                    5  t          |                                 d           ddd           dS # 1 swxY w Y   dS )z  Invalid modes raise ValueError mongooseN)r!   r=   r	   r   )r$   s    r'   test_invalid_modezTestFileOpen.test_invalid_mode   s    z** 	, 	,
+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   #AAAN)__name__
__module____qualname____doc__r(   r0   r5   r:   r>   rA   rD   rG    r1   r'   r   r       s           4	 	 	  : : :4
 
 

 
 
  , , , , ,r1   r   )r   
   r   zRequires HDF5 1.10.1 or laterc                       e Zd ZdZd ZdS )TestSpaceStrategyzE
        Feature: Create file with specified file space strategy
    c                    |                                  }t          |dddd          }|                     |           |                     t                    5  t          |dd           ddd           n# 1 swxY w Y   |                     t                    5  t          |                                  dd	           ddd           n# 1 swxY w Y   |                    d
dd          }d|d<   |                    ddd          }d|d<   |d
= |                                 t          |d          }|j                                        }|	                                }|d         dk    sJ |d         dk    sJ |d         dk    sJ |                    ddd          }d|d<   |                                 dS )z& Create file with file space strategy r   pageTd   )fs_strategy
fs_persistfs_thresholdr7   )rS   Ninvalidr*   )rR   uint8)dtyper   .r8   r   r
   foo2)
r   r	   r   r!   r=   create_datasetr,   idget_create_plistget_file_space_strategy)r$   r%   r/   dsetplistfs_strats         r'   test_create_with_space_strategyz1TestSpaceStrategy.test_create_with_space_strategy   sH   5#6"6 6 6z** 	1 	10000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 z** 	< 	<;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< !!%w!??S	!!%w!??S	J		5#''))0022{a{d""""{c!!!!!!&&!@@S			s$   A77A;>A;%CCCN)rH   rI   rJ   rK   ra   rL   r1   r'   rO   rO      s-             r1   rO   c                   *    e Zd ZdZd Zd Zd Zd ZdS )TestPageBufferingz)
        Feature: Use page buffering
    c                 $   |                                  }t          |ddd          5  	 ddd           n# 1 swxY w Y   |                     t                    5  t          |dd           ddd           n# 1 swxY w Y   |                     t                    5  t          |ddd           ddd           n# 1 swxY w Y   |                     t                    5  t          |ddd           ddd           dS # 1 swxY w Y   dS )	z;Allow page buffering only with fs_strategy="page".
        r   rQ    @  )r   rS   page_buf_sizeNr   rf   fsm	aggregater   r	   r!   r"   rC   s     r'   test_only_with_page_strategyz.TestPageBuffering.test_only_with_page_strategy   s2    %cvWMMM 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	w'' 	9 	9S8888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9w'' 	L 	LSe7KKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	Lw'' 	R 	RSkQQQQ	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	RsB   6::A::A>A>B??CC$DD	D	c                    |                                  }d}d}d}t          |dd|||          5 }|j                                        }|                     |                                |||f           ddd           dS # 1 swxY w Y   dS )zHVerify set page buffer size, and minimum meta and raw eviction criteria.re      C   r   rQ   )r   rS   rf   min_meta_keepmin_raw_keepNr   r	   r[   get_access_plistr   get_page_buffer_size)r$   r%   pbsmmmrr&   fapls          r'   test_check_page_buf_sizez*TestPageBuffering.test_check_page_buf_size   s    %cv #2BH H H 	IKL4((**DT66883B-HHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	Is   ABB	Bc                    |                                  }d}t          |dd|          5  	 ddd           n# 1 swxY w Y   |                     t                    5  t          |d|dz
             ddd           dS # 1 swxY w Y   dS )	z;Page buffer size must be greater than file space page size.re   r   rQ   r   rS   fs_page_sizeNr   r   rg   rj   )r$   r%   fsps      r'   test_too_small_pbsz$TestPageBuffering.test_too_small_pbs   s   %cvCHHH 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	w'' 	7 	7SA6666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   8<<B  BBc                 ~   |                                  }d}d|z  }t          |dd|          5  	 ddd           n# 1 swxY w Y   t          |d|dz
  	          5 }|j                                        }|                     |                                d
         |           ddd           dS # 1 swxY w Y   dS )zVerify actual page buffer size.re   r
   r   rQ   rz   Nr   r   rg   r   rq   )r$   r%   r|   rt   r&   rw   s         r'   test_actual_pbsz!TestPageBuffering.test_actual_pbs   sS   #g%cvCHHH 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	%cQ777 	B14((**DT6688;SAAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	Bs"   =AAAB22B69B6N)rH   rI   rJ   rK   rk   rx   r}   r   rL   r1   r'   rc   rc      se         R R R	I 	I 	I7 7 7	B 	B 	B 	B 	Br1   rc   c                       e Zd ZdZd Zd ZdS )	TestModesz?
        Feature: File mode can be retrieved via file.mode
    c                 <   |                                  }t          |d          5 }|                     |j        d           ddd           n# 1 swxY w Y   t          |d          5 }|                     |j        d           ddd           dS # 1 swxY w Y   dS )z/ Mode equivalent can be retrieved via property r   r@   Nr   )r   r	   r   r   r#   s      r'   test_mode_attrzTestModes.test_mode_attr   s   % 	+QVT***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+% 	*QVS)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s#   AAA(BBBc                    |                                  }|                                  }t          |d          }|                                 t          |d          }	 t          j        |d          |d<   |d         j        }|                     |j        d           |                                 |                                 n-# |                                 |                                 w xY wt          |d          }	 |d         j        }|                     |j        d           |                                 |                                 dS # |                                 |                                 w xY w)zU Mode property works for files opened via external links

        Issue 190.
        r   /Externalr@   r   N)r   r	   r,   h5pyExternalLinkfiler   r   )r$   fname1fname2f1f2f3s         r'   test_mode_externalzTestModes.test_mode_external   s>   
 &#



&#	!.vs;;BzNJ$BRWd+++HHJJJHHJJJJ HHJJJHHJJJJ&#	J$BRWc***HHJJJHHJJJJJ HHJJJHHJJJJs   A C *C1(E *FN)rH   rI   rJ   rK   r   r   rL   r1   r'   r   r      s<         * * *    r1   r   c                       e Zd ZdZ ej        ej        dk    d          d             Z ej        e	d          d             Z
 ej        ej        dk    d          d             Zd	 Zd
 Zd Zd Zd Zd ZdS )TestDriverszz
        Feature: Files can be opened with low-level HDF5 drivers. Does not
        include MPI drivers (see bottom).
    posixz"Stdio driver is supported on posixc                    t          |                                 dd          }|                     |           |                     |j        d           |                                 t          |                                 dd          }|                     |           |                     |j        d           |                                 dS )z$ Stdio driver is supported on posix r   stdiodriverr7   Nr	   r   r   r   r   r,   r$   r/   s     r'   
test_stdiozTestDrivers.test_stdio#  s     4;;==#g666W---		 4;;==#g666W---		r1   zODIRECT driver is supported on Linux if hdf5 is built with the appriorate flags.c           	         t          |                                 dd          }|                     |           |                     |j        d           |j                                                                        }|                                 t          |                                 dd          }|                     |           |                     |j        d           |                                 ||d         |d         d|d         z  f|d         dz  |d         d|d         z  f|d         d|d         z  d	|d         z  ffD ]\  }}}t          |                                 dd|||
          5 }|j                                                                        }|d         }|d         }|d         }	||k    sJ ||k    sJ |	|	k    sJ 	 ddd           n# 1 swxY w Y   dS )z$ DIRECT driver is supported on Linuxr   directr   r7   r   r      r
      )r   	alignment
block_size	cbuf_sizeN)	r	   r   r   r   r   r[   rr   get_fapl_directr,   )
r$   r/   default_faplr   r   r   actual_faplactual_alignmentactual_block_sizeactual_cbuf_sizes
             r'   test_directzTestDrivers.test_direct1  sE   
 4;;==#h777X...v..00@@BB		 4;;==#h777X...		$ a,q/1|A3FGa1$l1oq<?7JKa!l1o"5q<?7JK	1 	< 	<,Iz9 dkkmmS )!+ )+ + + 
< /2!f5577GGII#.q> $/N!#.q> '94444(J6666'+;;;;;;
< 
< 
< 
< 
< 
< 
< 
< 
< 
< 
< 
< 
< 
< 
<	< 	<s   =AG&&G*	-G*	z!Sec2 driver is supported on posixc                    t          |                                 dd          }|                     |           |                     |j        d           |                                 t          |                                 dd          }|                     |           |                     |j        d           |                                 dS )z# Sec2 driver is supported on posix r   sec2r   r7   Nr   r   s     r'   	test_sec2zTestDrivers.test_sec2c  s     4;;==#f555V,,,		 4;;==#f555V,,,		r1   c                    |                                  }t          |ddd          }|                     |           |                     |j        d           |                                 |                     t          j        	                    |                     t          |                                  dd          }|                     |           |                     |j        d           |                                 dS )z- Core driver is supported (no backing store) r   coreFr   backing_storer7   r   N)
r   r	   r   r   r   r,   r<   r   pathexistsr.   s      r'   	test_corezTestDrivers.test_coreq  s    5#fEBBBV,,,		../// 4;;==#f555V,,,		r1   c                    |                                  }t          |ddd          }|                    d           |                                 t          |d          }d|v sJ |                                 |                     t
                    5  t          |dd           ddd           dS # 1 swxY w Y   dS )	z3 Core driver saves to file when backing store used r   r   Tr   r*   r   )r   N)r   r	   r+   r,   r!   	TypeErrorr.   s      r'   test_backingzTestDrivers.test_backing  s    5#fDAAA		5#||||		y)) 	1 	140000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   B55B9<B9c                    |                                  }t          |d          }|                    d           |                                 t          |dd          }|                     |           d|v sJ |                     t                    5  |                    d           ddd           n# 1 swxY w Y   |                                 dS )z0 Core driver can be used to open existing files r   r*   r   r   r   r8   N)r   r	   r+   r,   r   r!   r=   r.   s      r'   r>   zTestDrivers.test_readonly  s    5#		5#f---||||z** 	$ 	$U###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$		s   B77B;>B;c                     |                                  }t          |dddd          }|                     |           |                                 dS )z* Core driver supports variable block size r   r      F)r   r   r   N)r   r	   r   r,   r.   s      r'   test_blocksizezTestDrivers.test_blocksize  sQ    5#f!&( ( (		r1   c                 Z   |                                  }t          |dd          }|                                 |                     t          j                            |dz                        t          |dd          }|                     |           |                                 dS )z* Split stores metadata in a separate file r   splitr   z-m.h5r   N)r   r	   r,   r   r   r   r   r.   s      r'   
test_splitzTestDrivers.test_split  s    5#g...		uw778885#g...		r1   c                 b   t          j                    }t          |dd          }|                     |           |                     |j        d           |                                 |                     t                    5  t          |dd           ddd           dS # 1 swxY w Y   dS )z( Python file object driver is supported r   fileobjr   r   N)	tempfileTemporaryFiler	   r   r   r   r,   r!   r=   )r$   tfr/   s      r'   test_fileobjzTestDrivers.test_fileobj  s    #%%2s9---Y///		z** 	) 	)S((((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   B$$B(+B(N)rH   rI   rJ   rK   r   
skipUnlessr   namer   r   r   r   r   r   r>   r   r   r   rL   r1   r'   r   r     s        
 R]27g%'KLL  ML R]:67 7-< -<7 7-<^ R]27g%'JKK  LK  1 1 1      	) 	) 	) 	) 	)r1   r   )r   rM   r
   zRequires HDF5 before 1.10.2c                   *    e Zd ZdZd Zd Zd Zd ZdS )
TestLibverze
        Feature: File format compatibility bounds can be specified when
        opening a file.
    c                     t          |                                 d          }|                     |j        d           |                                 dS ) Opening with no libver arg r   earliestlatestNr	   r   r   libverr,   r$   r&   s     r'   r(   zTestLibver.test_default  C    $$#9:::						r1   c                     t          |                                 dd          }|                     |j        d           |                                 dS )  Opening with single libver arg r   r   r   )r   r   Nr   r   s     r'   test_singlezTestLibver.test_single  sH    H555#7888						r1   c                     t          |                                 dd          }|                     |j        d           |                                 dS ) Opening with two libver args r   r   r   Nr   r   s     r'   test_multiplezTestLibver.test_multiple  sI    ,BCCC#9:::						r1   c                     t          |                                 d          }|                     |j        d           |                                 dS )6 Omitting libver arg results in maximum compatibility r   r   Nr   r   s     r'   	test_nonezTestLibver.test_none  r   r1   N)rH   rI   rJ   rK   r(   r   r   r   rL   r1   r'   r   r     sZ         
          r1   r   zRequires HDF5 1.10.2 or laterc                        e Zd ZdZe fd            Zd Zd Zd Zd Z	 e
j        ej        j        dk     d          d	             Zd
 Zd Z xZS )TestNewLibverz
        Feature: File format compatibility bounds can be specified when
        opening a file.

        Requirement: HDF5 1.10.2 or later
    c                     t                                                       t          j        j        dk     r	d| _        d S t          j        j        dk     r	d| _        d S d| _        d S )Nr         v110)r      r   v112v114)super
setUpClassr   versionhdf5_version_tupler   )cls	__class__s    r'   r   zTestNewLibver.setUpClass  s\     <*Z77CJJJ\,z99CJJJCJJJr1   c                     t          |                                 d          }|                     |j        d| j        f           |                                 dS )r   r   r   Nr	   r   r   r   r   r,   r   s     r'   r(   zTestNewLibver.test_default  I    $$J#<===						r1   c                     t          |                                 dd          }|                     |j        | j        | j        f           |                                 dS )r   r   r   r   Nr   r   s     r'   r   zTestNewLibver.test_single  sP    H555DK#=>>>						r1   c                     t          |                                 dd          }|                     |j        d| j        f           |                                 dS )z  Opening with "v108" libver arg r   v108r   Nr   r   s     r'   test_single_v108zTestNewLibver.test_single_v108  N    F333FDK#8999						r1   c                     t          |                                 dd          }|                     |j        d| j        f           |                                 dS )z  Opening with "v110" libver arg r   r   r   Nr   r   s     r'   test_single_v110zTestNewLibver.test_single_v110  r   r1   r   zRequires HDF5 1.11.4 or laterc                     t          |                                 dd          }|                     |j        d| j        f           |                                 dS )z  Opening with "v112" libver arg r   r   r   Nr   r   s     r'   test_single_v112zTestNewLibver.test_single_v112  sP     F333FDK#8999						r1   c                     t          |                                 dd          }|                     |j        d           |                                 dS )r   r   )r   r   r   Nr   r   s     r'   r   zTestNewLibver.test_multiple  sI    ,@AAA#7888						r1   c                     t          |                                 d          }|                     |j        d| j        f           |                                 dS )r   r   r   Nr   r   s     r'   r   zTestNewLibver.test_none  r   r1   )rH   rI   rJ   rK   classmethodr   r(   r   r   r   r   skipIfr   r   r   r   r   r   __classcell__)r   s   @r'   r   r     s          	  	  	  	  [	          RYt|.;.0 0 0 0        r1   r   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )TestUserblockz;
        Feature: Files can be create with user blocks
    c                 H   t          |                                 dd          }	 |                     |j        d           |                                 n# |                                 w xY wt          |                                 dd          }	 |                     |j        d           |                                 n# |                                 w xY wt          |                                 dd          }	 |                     |j        d           |                                 n# |                                 w xY w|                     t                    5  t          |                                 dd           ddd           dS # 1 swxY w Y   dS )zA User blocks created with w, w-, x and properties work correctly r3      userblock_sizexr   nonN)r	   r   r   r   r,   r!   r=   r   s     r'   test_create_blocksizez#TestUserblock.test_create_blocksize&  s   S999	Q-s333GGIIIIAGGIIIIC888	Q-s333GGIIIIAGGIIIIC888	Q-s333GGIIIIAGGIIIIz** 	; 	;E::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s5   A A,C CD2 2E%%FFFc                    |                                  }t          |d          }|                                 |                     t                    5  t          j        |dd          }ddd           n# 1 swxY w Y   |                     t                    5  t          j        |dd          }ddd           dS # 1 swxY w Y   dS )z# User block only allowed for write r   r   r   r   Nr@   )r   r	   r,   r!   r=   r   r$   r   r&   s      r'   test_write_onlyzTestUserblock.test_write_only=  s8   {{}}sOO				z** 	9 	9	$C888A	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 z** 	: 	:	$S999A	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s$   A77A;>A;CCCc                    |                                  }t          |dd          }|                                 |                     t                    5  t          |dd          }ddd           n# 1 swxY w Y   t          |dd          }	 |                     |j        d           |                                 dS # |                                 w xY w)zA User block size must match that of file when opening for append r   r   r   r7   r   N)r   r	   r,   r!   r=   r   r   r  s      r'   test_match_existingz!TestUserblock.test_match_existingI  s   {{}}s3///				z** 	5 	5T3t444A	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 s3///	Q-s333GGIIIIIAGGIIIIs   A44A8;A8C Cc                    |                                  }|                     t                    5  t          |dd          }ddd           n# 1 swxY w Y   |                     t                    5  t          |dd          }ddd           n# 1 swxY w Y   |                     t                    5  t          |dd          }ddd           dS # 1 swxY w Y   dS )z7 User block size must be a power of 2 and at least 512 r      r   Ni  i  )r   r!   r=   r	   r  s      r'   test_power_of_twozTestUserblock.test_power_of_twoX  s   {{}}z** 	4 	4T3s333A	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 z** 	4 	4T3s333A	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 z** 	5 	5T3t444A	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s5   AAA3BBB7CCCc                    |                                  }t          |dd          }|                    d           |                                 t	          |d          }	 |                    d           |                                 n# |                                 w xY wt          j        |d          }	 d|v sJ 	 |                                 n# |                                 w xY wt	          |d          }	 |                     |                    d          d           |                                 d	S # |                                 w xY w)
z= Test that writing to a user block does not destroy the file r   r   r   Foobarzr+bs   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXr   rbN)	r   r	   r+   r,   r   r    r   r   read)r$   r   r&   pyfiles       r'   test_write_blockzTestUserblock.test_write_blocke  s(   {{}}s3///	x   				dE""	LL$$$LLNNNNFLLNNNNIdC  	q=====GGIIIIAGGIIIIdD!!	V[[--z:::LLNNNNNFLLNNNNs$   !B B!:C C, )D? ?EN)	rH   rI   rJ   rK   r  r  r  r
  r  rL   r1   r'   r   r      si         ; ; ;.
: 
: 
:  5 5 5    r1   r   c                       e Zd ZdZd ZdS )TestContextManagerzC
        Feature: File objects can be used as context managers
    c                     t          |                                 d          5 }|                     |           ddd           n# 1 swxY w Y   |                     |            dS )z- File objects can be used in with statements r   N)r	   r   r   r   s     r'   test_context_managerz'TestContextManager.test_context_manager  s    $++--%% 	!OOC   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!C     s   AA	A	N)rH   rI   rJ   rK   r  rL   r1   r'   r  r    s-         ! ! ! ! !r1   r  z#Filesystem unicode support requiredc                   $    e Zd ZdZd Zd Zd ZdS )TestUnicodez6
        Feature: Unicode filenames are supported
    c                 >   |                      t          d                    }t          |d          }	 |                     |j        |           |                     |j        t                     |                                 dS # |                                 w xY w)zM Unicode filenames can be used, and retrieved properly via .filename
           prefixr   N)r   chrr	   r   filenameassertIsInstancestrr,   r.   s      r'   test_unicodezTestUnicode.test_unicode  s     3v;;//5#	S\5111!!#,444IIKKKKKCIIKKKKs   ;B Bc                    |                      t          d                    }t          |d          5 }|                     t          j                            |                     ddd           dS # 1 swxY w Y   dS )zG Unicode filenames can be used, and seen correctly from python
        r  r  r   N)r   r  r	   r   r   r   r   r#   s      r'   #test_unicode_hdf5_python_consistentz/TestUnicode.test_unicode_hdf5_python_consistent  s     3v;;//% 	3OOBGNN511222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s   3A44A8;A8c                 V   |                      t          d                    }|                     t                    5  t	          |d           ddd           n# 1 swxY w Y   |                     t                    5  t	          |d           ddd           dS # 1 swxY w Y   dS )zV
        Modes 'r' and 'r+' do not create files even when given unicode names
        r  r  r   Nr@   )r   r  r!   IOErrorr	   rC   s     r'   test_nonexistent_file_unicodez)TestUnicode.test_nonexistent_file_unicode  s    3v;;//w'' 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	w'' 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s#   AA"A BB"%B"N)rH   rI   rJ   rK   r  r!  r$  rL   r1   r'   r  r    sK         	 	 	3 3 3    r1   r  c                   $    e Zd ZdZd Zd Zd ZdS )TestFilePropertyzk
        Feature: A File object can be retrieved from any child object,
        via the .file property
    c                     |                                  }t          |d          }	 |d         j        }|                     ||           |                                 dS # |                                 w xY w)z, File object can be retrieved from subgroup r   r   N)r   r	   r   r   r,   )r$   r%   hfilehfile2s       r'   test_propertyzTestFileProperty.test_property  sg    UC  	3Z_FUF+++KKMMMMMEKKMMMMs   #A A5c                 F   |                                  }t          |d          }|                    d          }|j        }|d         j        }|                                 |                     |           |                     |           |                     |           dS )z8 All retrieved File objects are closed at the same time r   r*   r   N)r   r	   r+   r   r,   r<   )r$   r%   r(  grpr)  hfile3s         r'   
test_closezTestFileProperty.test_close  s    UC    ''s        r1   c                    t          |                                 d          }	 |                    d          }|                     |j        j        |j                   |                                 dS # |                                 w xY w)z9 Retrieved File objects have a meaningful mode attribute r   r*   N)r	   r   r+   r   r   r   r,   )r$   r(  r,  s      r'   	test_modezTestFileProperty.test_mode  sp    T[[]]C((	$$U++CSX]EJ777KKMMMMMEKKMMMMs   :A4 4B
N)rH   rI   rJ   rK   r*  r.  r0  rL   r1   r'   r&  r&    sK         
  
! 
! 
!    r1   r&  c                   $    e Zd ZdZd Zd Zd ZdS )	TestClosez*
        Feature: Files can be closed
    c                     t          |                                 d          }|                     |           |                                 |                     |           dS )z Close file via .close method r   N)r	   r   r   r,   r<   r   s     r'   r.  zTestClose.test_close  sR    4;;==#&&		r1   c                    t          |                                 d          }|                                 |                     t                    5  |                    d           ddd           dS # 1 swxY w Y   dS )z0 Trying to modify closed file raises ValueError r   r*   N)r	   r   r,   r!   r=   r+   r   s     r'   test_closed_filezTestClose.test_closed_file  s    4;;==#&&		z** 	$ 	$U###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   A44A8;A8c                     |                                  }t          j        |d          }|                    d           |                                 |                                 d S )Nr   test)r   r   r	   r+   r,   r#   s      r'   "test_close_multiple_default_driverz,TestClose.test_close_multiple_default_driver  sP    IeS!!	v										r1   N)rH   rI   rJ   rK   r.  r5  r8  rL   r1   r'   r2  r2    sK           $ $ $    r1   r2  c                       e Zd ZdZd ZdS )	TestFlushz+
        Feature: Files can be flushed
    c                     t          |                                 d          }|                                 |                                 dS )z Flush via .flush method r   N)r	   r   flushr,   r   s     r'   
test_flushzTestFlush.test_flush  s7    4;;==#&&				r1   N)rH   rI   rJ   rK   r=  rL   r1   r'   r:  r:    s-             r1   r:  c                       e Zd ZdZd ZdS )TestReprzE
        Feature: File objects provide a helpful __repr__ string
    c                    t          |                                 d          }|                     t          |          t                     |                                 |                     t          |          t                     dS )z8 __repr__ behaves itself when files are open and closed r   N)r	   r   r  reprr  r,   r   s     r'   	test_reprzTestRepr.test_repr  sd    4;;==#&&d3ii---		d3ii-----r1   N)rH   rI   rJ   rK   rB  rL   r1   r'   r?  r?    s-         . . . . .r1   r?  c                       e Zd ZdZd ZdS )TestFilenamezO
        Feature: The name of a File object can be retrieved via .filename
    c                     |                                  }t          |d          }	 |                     |j        |           |                     |j        t
                     |                                 dS # |                                 w xY w)z, .filename behaves properly for string data r   N)r   r	   r   r  r  r  r,   r.   s      r'   test_filenamezTestFilename.test_filename  sv    5#	S\5111!!#,444IIKKKKKCIIKKKKs   ;A7 7BN)rH   rI   rJ   rK   rF  rL   r1   r'   rD  rD    s-             r1   rD  c                       e Zd ZdZd Zd ZdS )!TestCloseInvalidatesOpenObjectIDszO
        Ensure that closing a file invalidates object IDs, as appropriate
    c                    t          |                                 d          5 }|                    d          }|                     t	          |j                             |                     t	          |j                             |                                 |                     t	          |j                             |                     t	          |j                             ddd           n# 1 swxY w Y   t          |                                 d          5 }|                    d          }|                     t	          |j                             |                     t	          |j                             |                     t	          |j                             |                     t	          |j                             ddd           dS # 1 swxY w Y   dS )z; Closing a file invalidates any of the file's open objects r   r*   N)r	   r   r+   r   boolr[   r,   r<   )r$   r   g1r   g2s        r'   r.  z,TestCloseInvalidatesOpenObjectIDs.test_close&  s   $++--%% 	*''BOODKK(((OODKK(((HHJJJT"%[[)))T"%[[)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* $++--%% 	*''BOODKK(((OODKK(((T"%[[)))T"%[[)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s%   CC55C9<C9"B2G!!G%(G%c                    |                                  }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   t          |          }t          |          }|d         }|d         }|j        j        sJ |j        j        sJ |                                 |j        j        rJ |j        j        sJ |j        j        sJ |                                 |j        j        rJ |j        j        rJ d S )Nr   r*   )r   r	   r+   r[   validr,   )r$   r%   r&   r   r   rK  rL  s          r'   test_close_one_handlez7TestCloseInvalidatesOpenObjectIDs.test_close_one_handle6  s=   % 	"NN5!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" %[[%[[YYu{u{



5;u{u{



5;5;s   AAAN)rH   rI   rJ   rK   r.  rO  rL   r1   r'   rH  rH     s<         * * *     r1   rH  c                       e Zd ZdZd Zd ZdS )TestPathlibSupportz6
        Check that h5py doesn't break on pathlib
    c                     t                      5 }t          j        |          }t          |d          5 }|                     d           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z- Check that pathlib is accepted by h5py.File r   TN)r   pathlibPathr	   r   )r$   r&   r   r   s       r'   test_pathlib_accepted_filez-TestPathlibSupport.test_pathlib_accepted_fileQ  s     	&!<??DdC &B%%%& & & & & & & & & & & & & & &	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s4   %A.A
A.A	A.A	A..A25A2c                 d   t                      5 }t          j        |          }t          |d          5 }|j        }ddd           n# 1 swxY w Y   t          |d          5 }|j        }ddd           n# 1 swxY w Y   |                     ||           ddd           dS # 1 swxY w Y   dS )z1 Check that using pathlib does not affect naming r   N)r   rS  rT  r	   r  r   )r$   r&   r   h5f1pathlib_nameh5f2normal_names          r'   test_pathlib_name_matchz*TestPathlibSupport.test_pathlib_name_matchX  s`    	8!<??DdC -D#}- - - - - - - - - - - - - - -a ,"m, , , , , , , , , , , , , , ,\;777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8sW   %B%AB%A	B%A	B%#A7+B%7A;	;B%>A;	?B%%B),B)N)rH   rI   rJ   rK   rU  r[  rL   r1   r'   rQ  rQ  L  s<         & & &8 8 8 8 8r1   rQ  c                       e Zd ZdZd ZdS )
TestPicklez%Check that h5py.File can't be pickledc                    t          |                                 d          5 }|                     t                    5  t	          j        |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   )r	   r   r!   r   pickledumps)r$   r   s     r'   test_dump_errorzTestPickle.test_dump_errore  s    $++--%% 	!""9-- ! !R   ! ! ! ! ! ! ! ! ! ! ! ! ! ! !	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s4   A7AA7A#	#A7&A#	'A77A;>A;N)rH   rI   rJ   rK   ra  rL   r1   r'   r]  r]  c  s)        //! ! ! ! !r1   r]  c                       e Zd Zd Zd Zej                            ej	        j
        dk     d          d             Zd ZdS )	TestMPIc                     ddl m} t          |dd|j                  5 }|sJ |j        dk    sJ 	 ddd           dS # 1 swxY w Y   dS ) MPIO driver and options r   MPIr   mpior   commNmpi4pyrg  r	   
COMM_WORLDr   r$   mpi_file_namerg  r&   s       r'   	test_mpiozTestMPI.test_mpioo      -V#.III 	&QHHH8v%%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&   ?AAc                     ddl m} t          |dd|j                  5 }|sJ |j        dk    sJ 	 ddd           dS # 1 swxY w Y   dS )z& Testing creation of file with append r   rf  r7   rh  ri  Nrk  rn  s       r'   test_mpio_appendzTestMPI.test_mpio_appendw  rq  rr  )r      	   z5mpio atomic file operations were added in HDF5 1.8.9+reasonc                     ddl m} t          |dd|j                  5 }|j        rJ d|_        |j        sJ 	 ddd           dS # 1 swxY w Y   dS )z$ Enable atomic mode for MPIO driver r   rf  r   rh  ri  TN)rl  rg  r	   rm  atomicrn  s       r'   test_mpi_atomiczTestMPI.test_mpi_atomic  s     	-V#.III 	QxAH8OOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                     ddl m} t          |dd|j                  }|                    d           |                                 |                                 dS )re  r   rf  r   rh  ri  r7  N)rl  rg  r	   rm  r+   r,   rn  s       r'   test_close_multiple_mpio_driverz'TestMPI.test_close_multiple_mpio_driver  s\    FHHH	v										r1   N)rH   rI   rJ   rp  rt  r   markskipifr   r   r   r{  r}  rL   r1   r'   rc  rc  m  s        & & && & & [7)CV  X X X X    r1   rc  c                       e Zd ZdZd Zd ZdS )TestSWMRModez=
        Feature: Create file that switches on SWMR mode
    c                 2   |                                  }t          |dd          }|                    d          }|j        |j        j        cxk    rdk    sn J d|_        |j        |j        j        cxk    rdk    sn J |                                 d S )Nr   r   r   r*   r@   T)r   r	   r+   r   r   	swmr_moder,   r$   r%   r/   gs       r'   test_file_mode_generalizesz'TestSWMRMode.test_file_mode_generalizes  s    5#h///U##x16;....$...... x16;....$......		r1   c                 2   |                                  }t          |dd          }|                    d          }|j        |j        j        cxk    rdk    sn J d|_        |j        |j        j        cxk    rdk    sn J |                                 d S )Nr   r   r   r*   FT)r   r	   r+   r  r   r,   r  s       r'   test_swmr_mode_consistencyz'TestSWMRMode.test_swmr_mode_consistency  s    5#h///U##} 09999E999999} 08888D888888		r1   N)rH   rI   rJ   rK   r  r  rL   r1   r'   r  r    s<         
 
 
    r1   r  )r      r   )r   rM      z+Requires HDF5 >= 1.12.1 or 1.10.x >= 1.10.7rw  HDF5_USE_FILE_LOCKINGz&HDF5_USE_FILE_LOCKING env. var. is setc                   $    e Zd ZdZd Zd Zd ZdS )TestFileLockingz"Test h5py.File file locking optionc                    |dz  }t          j        |dd          5 }|                                 t          j        t
                    5  t          j        |dd          5 }	 ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          j        |dd          5 }	 ddd           n# 1 swxY w Y   t          j        |dd          5 }	 ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )	z2Test file locking when opening twice the same filetest.h5r   Tr   lockingr   FNzbest-effort)r   r	   r<  r   r   r"   )r$   tmp_pathr%   r&   h5f_reads        r'   test_reopenzTestFileLocking.test_reopen  s@   9$Yu3555 	GGIII w''  Yu3>>> (                             5sD999 X               5sMBBB h              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   .D B#A1%B1A55B8A59B<D B	D B	D *B8,D 8B<	<D ?B<	 D C(D (C,	,D /C,	0D  DDc                     |dz  }t          j        t                    5  t          j        |dd          5 }	 ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z&Test with erroneous file locking valuer  r   zunsupported-valuer  N)r   r   r=   r   r	   )r$   r  r%   r  s       r'   test_unsupported_lockingz(TestFileLocking.test_unsupported_locking  s    9$]:&& 	 	5s4GHHH H              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s3   AAAA			AA		AA!$A!c                     |dz  }d }t          j        |dd          5 }d|d<   ddd           n# 1 swxY w Y   t          j        |d	d
          5 } ||dd          sJ 	 ddd           dS # 1 swxY w Y   dS )z<Test file locking option from different concurrent processesr  c                    t          t          j        t          j                  j        j                  }t          j        t          j	        dd|dt          |           d|d| d	gd          }|j
        d	k    o|j         S )
z9Open HDF5 file in a subprocess and return True on successz-cz
import sys
sys.path.insert(0, z)
import h5py
f = h5py.File(z, mode=z
, locking=z)
                    T)capture_outputr   )r  rS  rT  r   __file__parent
subprocessrunsys
executable
returncodestderr)r  r   r  h5py_import_dirprocesss        r'   open_in_subprocessz=TestFileLocking.test_multiprocess.<locals>.open_in_subprocess  s    !',t}"="="D"KLLO nN#  8}}	  (,	  :A	  	  $% % %G %*A7>/AAr1   r   Tr  r   dataNr   F)r   r	   )r$   r  r%   r  r&   s        r'   test_multiprocessz!TestFileLocking.test_multiprocess  s@   9$	B 	B 	B& Yu3555 	AfI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 Yu3666 	E!%%e#tDDDDDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es   266A33A7:A7N)rH   rI   rJ   rK   r  r  r  rL   r1   r'   r  r    sN         -,  $  E E E E Er1   r  c                 j   t          d          D ]}g | t          |          <   | j        }|                                  t          d          D ]c}t	          j        |d          5 }d |                                D             }|                    |           ~d d d            n# 1 swxY w Y   dd S )NrR   rM   r   c                     g | ]	}|j         
S rL   )r[   ).0ds     r'   
<listcomp>z!test_close_gc.<locals>.<listcomp>  s    ---QAD---r1   )ranger  r  r,   r   r	   valuesappend)writable_fileir  r&   refss        r'   test_close_gcr    s    3ZZ # # "c!ff%H
 2YY  Yx%% 	--!((**---DKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   &5B''B+	.B+	)3rK   r   r   r   r_  r   r  r  commonr   r   r   r   h5py._hl.filesr   r   r	    r   rS  r   r   r   r   rO   r~  mpi_skiprc   r   r   r   r   r   r   r  r  r&  r2  r:  r?  rD  rH  rQ  r]  mpirc  r  r  environr  r  rL   r1   r'   <module>r     s7     				        



 D D D D D D D D D D D D % % % % % %              q, q, q, q, q,8 q, q, q,h 4<*Z7*, ,# # # # # # #, ,#L 4<*Z7*, ,/B /B /B /B /B /B /B , ,/Bd( ( ( ( ( ( ( (VY) Y) Y) Y) Y)( Y) Y) Y)| t|.;,. .      . .@ 4<*Z7*, ,? ? ? ? ?H ? ?, ,?D] ] ] ] ]H ] ] ]@
! 
! 
! 
! 
! 
! 
! 
!   "GHH         (     IH F$ $ $ $ $x $ $ $N       8
 
 
 
 
 
 
 
. . . . .x . . .    8   ") ) ) ) ) ) ) )X8 8 8 8 8 8 8 8.! ! ! ! ! ! ! ! # # # # # # # #L 4<*Z7*, ,    8  , ,: L#j0 ^L#BQB'72\dl6UVW6X[\6\8  : : +rz9C  E E8E 8E 8E 8E 8E 8E 8EE E	: :8Ev    r1   