3
_½µ_>[  ã               @   s  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mZ ddlm	Z	m
Z
mZmZ ddlmZ ddlZddlmZ ddlZG d	d
„ d
e
ƒZe	jejjd4k dƒG dd„ de
ƒƒZG dd„ de
ƒZG dd„ de
ƒZe	jejjd5k dƒG dd„ de
ƒƒZe	jejjd6k dƒG dd„ de
ƒƒZG dd„ de
ƒZG dd„ de
ƒZe	je dƒG dd„ de
ƒƒZG d d!„ d!e
ƒZG d"d#„ d#e
ƒZ G d$d%„ d%e
ƒZ!G d&d'„ d'e
ƒZ"G d(d)„ d)e
ƒZ#G d*d+„ d+e
ƒZ$G d,d-„ d-e
ƒZ%G d.d/„ d/e
ƒZ&ej'j(G d0d1„ d1e)ƒƒZ*e	jejjd7k dƒG d2d3„ d3e
ƒƒZ+dS )8z`
    File object test module.

    Tests all aspects of File objects, including their creation.
é    N)Úplatformé   )ÚutÚTestCaseÚUNICODE_FILENAMESÚclosed_tempfile)ÚFileé   )Úh5c               @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚTestFileOpenz=
        Feature: Opening files with Python-style modes.
    c          2   C   sÚ   | j ƒ }tjtƒ� t|ƒ� W dQ R X W dQ R X t|dƒ� W dQ R X tj|tjƒ z0t|ƒ�}| j	|ƒ | j
|jdƒ W dQ R X W dtj|tjƒ X t|dƒ�}|jdƒ W dQ R X | jtƒ� t|ƒ W dQ R X dS )z8 Default semantics in the presence or absence of a file NÚwÚrÚwbó    )ÚmktempÚpytestZraisesÚOSErrorr   ÚosÚchmodÚstatÚS_IREADÚ
assertTrueÚassertEqualÚmodeÚS_IWRITEÚopenÚwriteÚassertRaisesÚIOError)ÚselfÚfnameÚf© r"   ú6/tmp/pip-install-xpigntgx/h5py/h5py/tests/test_file.pyÚtest_default$   s     



zTestFileOpen.test_defaultc             C   sP   | j ƒ }t|dƒ}| j|ƒ |jdƒ |jƒ  t|dƒ}| jd|ƒ |jƒ  dS )z' Mode 'w' opens file in overwrite mode r   ÚfooN)r   r   r   Úcreate_groupÚcloseZassertNotIn)r   r    Úfidr"   r"   r#   Útest_create?   s    



zTestFileOpen.test_createc          
   C   sH   | j ƒ }t|dƒ}| j|ƒ |jƒ  | jtƒ� t|dƒ W dQ R X dS )z( Mode 'w-' opens file in exclusive mode zw-N)r   r   r   r'   r   r   )r   r    r(   r"   r"   r#   Útest_create_exclusiveJ   s    

z"TestFileOpen.test_create_exclusivec             C   s‚   | j ƒ }t|dƒ}z$| j|ƒ |jdƒ d|ks4t‚W d|jƒ  X t|dƒ}z&d|ksZt‚|jdƒ d|kspt‚W d|jƒ  X dS )zE Mode 'a' opens file in append/readwrite mode, creating if necessary Úar%   NÚbar)r   r   r   r&   ÚAssertionErrorr'   )r   r    r(   r"   r"   r#   Útest_appendS   s    





zTestFileOpen.test_appendc          	   C   sd   | j ƒ }t|dƒ}|jƒ  | j|ƒ t|dƒ}| j|ƒ | jtƒ� |jdƒ W dQ R X |jƒ  dS )z& Mode 'r' opens file in readonly mode r   r   r%   N)r   r   r'   ÚassertFalser   r   Ú
ValueErrorr&   )r   r    r(   r"   r"   r#   Útest_readonlye   s    



zTestFileOpen.test_readonlyc             C   s\   | j ƒ }t|dƒ}|jdƒ |jƒ  t|dƒ}d|ks:t‚|jdƒ d|ksPt‚|jƒ  dS )z1 Mode 'r+' opens existing file in readwrite mode r   r%   zr+r,   N)r   r   r&   r'   r-   )r   r    r(   r"   r"   r#   Útest_readwriteq   s    



zTestFileOpen.test_readwritec             C   sL   | j ƒ }| jtƒ� t|dƒ W dQ R X | jtƒ� t|dƒ W dQ R X dS )z( Modes 'r' and 'r+' do not create files r   Nzr+)r   r   r   r   )r   r    r"   r"   r#   Útest_nonexistent_file}   s
    z"TestFileOpen.test_nonexistent_filec          
   C   s(   | j tƒ� t| jƒ dƒ W dQ R X dS )z  Invalid modes raise ValueError ZmongooseN)r   r0   r   r   )r   r"   r"   r#   Útest_invalid_mode…   s    zTestFileOpen.test_invalid_modeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r)   r*   r.   r1   r2   r3   r4   r"   r"   r"   r#   r      s   	r   é
   zRequires HDF5 1.10.1 or laterc               @   s   e Zd ZdZdd„ ZdS )ÚTestSpaceStrategyzE
        Feature: Create file with specified file space strategy
    c             C   s  | j ƒ }t|ddddd�}| j|ƒ | jtƒ� t|ddd� W dQ R X | jtƒ� t| j ƒ dd	d� W dQ R X |jd
ddd�}d|d< |jdddd�}d|d< |d
= |jƒ  t|dƒ}|jjƒ }|j	ƒ }|d dksÚt
‚|d dksêt
‚|d dksút
‚|jdddd�}d|d< |jƒ  dS )z& Create file with file space strategy r   ÚpageTéd   )Úfs_strategyZ
fs_persistZfs_thresholdr+   )r=   NÚinvalidr%   Zuint8)Zdtyper   .r,   r   r	   Zfoo2)r<   )r<   )r<   )r   r   r   r   r0   Zcreate_datasetr'   ÚidZget_create_plistZget_file_space_strategyr-   )r   r    r(   ZdsetÚplistZfs_stratr"   r"   r#   Útest_create_with_space_strategy’   s.    



z1TestSpaceStrategy.test_create_with_space_strategyN)r5   r6   r7   r8   rA   r"   r"   r"   r#   r:   Š   s   r:   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú	TestModesz?
        Feature: File mode can be retrieved via file.mode
    c             C   sT   | j ƒ }t|dƒ�}| j|jdƒ W dQ R X t|dƒ�}| j|jdƒ W dQ R X dS )z/ Mode equivalent can be retrieved via property r   zr+Nr   )r   r   r   r   )r   r    r!   r"   r"   r#   Útest_mode_attr·   s
    zTestModes.test_mode_attrc             C   sª   | j ƒ }| j ƒ }t|dƒ}|jƒ  t|dƒ}z,tj|dƒ|d< |d j}| j|jdƒ W d|jƒ  |jƒ  X t|dƒ}z|d j}| j|jdƒ W d|jƒ  |jƒ  X dS )zU Mode property works for files opened via external links

        Issue 190.
        r   ú/ZExternalzr+Nr   )r   r   r'   Úh5pyZExternalLinkÚfiler   r   )r   Zfname1Zfname2Úf1Úf2Zf3r"   r"   r#   Útest_mode_external¿   s"    





zTestModes.test_mode_externalN)r5   r6   r7   r8   rC   rI   r"   r"   r"   r#   rB   ±   s   rB   c               @   st   e Zd ZdZejejdkdƒdd„ ƒZejejdkdƒdd„ ƒZ	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zd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             C   s6   t | jƒ ddd�}| j|ƒ | j|jdƒ |jƒ  dS )z$ Stdio driver is supported on posix r   Zstdio)ÚdriverN)r   r   r   r   rL   r'   )r   r(   r"   r"   r#   Ú
test_stdioã   s    
zTestDrivers.test_stdioz!Sec2 driver is supported on posixc             C   s6   t | jƒ ddd�}| j|ƒ | j|jdƒ |jƒ  dS )z# Sec2 driver is supported on posix r   Zsec2)rL   N)r   r   r   r   rL   r'   )r   r(   r"   r"   r#   Ú	test_sec2ë   s    
zTestDrivers.test_sec2c             C   sN   | j ƒ }t|dddd�}| j|ƒ | j|jdƒ |jƒ  | jtjj	|ƒƒ dS )z- Core driver is supported (no backing store) r   ÚcoreF)rL   Úbacking_storeN)
r   r   r   r   rL   r'   r/   r   ÚpathÚexists)r   r    r(   r"   r"   r#   Ú	test_coreó   s    
zTestDrivers.test_corec             C   sp   | j ƒ }t|dddd�}|jdƒ |jƒ  t|dƒ}d|ks@t‚|jƒ  | jtƒ� t|ddd� W dQ R X dS )	z3 Core driver saves to file when backing store used r   rO   T)rL   rP   r%   r   )rP   N)r   r   r&   r'   r-   r   Ú	TypeError)r   r    r(   r"   r"   r#   Útest_backingü   s    

zTestDrivers.test_backingc          	   C   st   | j ƒ }t|dƒ}|jdƒ |jƒ  t|ddd�}| j|ƒ d|ksHt‚| jtƒ� |jdƒ W dQ R X |jƒ  dS )z0 Core driver can be used to open existing files r   r%   r   rO   )rL   r,   N)r   r   r&   r'   r   r-   r   r0   )r   r    r(   r"   r"   r#   r1   	  s    


zTestDrivers.test_readonlyc             C   s0   | j ƒ }t|ddddd�}| j|ƒ |jƒ  dS )z* Core driver supports variable block size r   rO   i   F)rL   Ú
block_sizerP   N)r   r   r   r'   )r   r    r(   r"   r"   r#   Útest_blocksize  s
    

zTestDrivers.test_blocksizec             C   sX   | j ƒ }t|ddd�}|jƒ  | jtjj|d ƒƒ t|ddd�}| j|ƒ |jƒ  dS )z* Split stores metadata in a separate file r   Úsplit)rL   z-m.h5r   N)r   r   r'   r   r   rQ   rR   )r   r    r(   r"   r"   r#   Ú
test_split  s    
zTestDrivers.test_splitc             C   s^   t jƒ }t|ddd�}| j|ƒ | j|jdƒ |jƒ  | jtƒ� t|ddd� W dQ R X dS )z( Python file object driver is supported r   Úfileobj)rL   rO   N)	ÚtempfileÚTemporaryFiler   r   r   rL   r'   r   r0   )r   Útfr(   r"   r"   r#   Útest_fileobj(  s    
zTestDrivers.test_fileobjN)r5   r6   r7   r8   r   Ú
skipUnlessr   ÚnamerM   rN   rS   rU   r1   rW   rY   r^   r"   r"   r"   r#   rJ   Ü   s   	
rJ   zRequires HDF5 before 1.10.2c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú
TestLibverze
        Feature: File format compatibility bounds can be specified when
        opening a file.
    c             C   s(   t | jƒ dƒ}| j|jdƒ |jƒ  dS )z Opening with no libver arg r   ÚearliestÚlatestN)rb   rc   )r   r   r   Úlibverr'   )r   r!   r"   r"   r#   r$   @  s    zTestLibver.test_defaultc             C   s,   t | jƒ ddd�}| j|jdƒ |jƒ  dS )z  Opening with single libver arg r   rc   )rd   N)rc   rc   )r   r   r   rd   r'   )r   r!   r"   r"   r#   Útest_singleF  s    zTestLibver.test_singlec             C   s,   t | jƒ ddd�}| j|jdƒ |jƒ  dS )z Opening with two libver args r   rb   rc   )rd   N)rb   rc   )rb   rc   )r   r   r   rd   r'   )r   r!   r"   r"   r#   Útest_multipleL  s    zTestLibver.test_multiplec             C   s(   t | jƒ dƒ}| j|jdƒ |jƒ  dS )z6 Omitting libver arg results in maximum compatibility r   rb   rc   N)rb   rc   )r   r   r   rd   r'   )r   r!   r"   r"   r#   Ú	test_noneR  s    zTestLibver.test_noneN)r5   r6   r7   r8   r$   re   rf   rg   r"   r"   r"   r#   ra   7  s
   ra   zRequires HDF5 1.10.2 or laterc                   sp   e Zd ZdZe‡ fdd„ƒZdd„ Zdd„ Zdd	„ Zd
d„ Z	e
jejjdk dƒdd„ ƒZdd„ Zdd„ Z‡  ZS )ÚTestNewLibverz�
        Feature: File format compatibility bounds can be specified when
        opening a file.

        Requirement: HDF5 1.10.2 or later
    c                s,   t t| ƒjƒ  tjjdk r"d| _nd| _d S )Nr   é   é   Úv110Úv112)r   ri   rj   )Úsuperrh   Ú
setUpClassrE   ÚversionÚhdf5_version_tuplerc   )Úcls)Ú	__class__r"   r#   rn   d  s    zTestNewLibver.setUpClassc             C   s.   t | jƒ dƒ}| j|jd| jfƒ |jƒ  dS )z Opening with no libver arg r   rb   N)r   r   r   rd   rc   r'   )r   r!   r"   r"   r#   r$   n  s    zTestNewLibver.test_defaultc             C   s4   t | jƒ ddd�}| j|j| j| jfƒ |jƒ  dS )z  Opening with single libver arg r   rc   )rd   N)r   r   r   rd   rc   r'   )r   r!   r"   r"   r#   re   t  s    zTestNewLibver.test_singlec             C   s2   t | jƒ ddd�}| j|jd| jfƒ |jƒ  dS )z  Opening with "v108" libver arg r   Úv108)rd   N)r   r   r   rd   rc   r'   )r   r!   r"   r"   r#   Útest_single_v108z  s    zTestNewLibver.test_single_v108c             C   s2   t | jƒ ddd�}| j|jd| jfƒ |jƒ  dS )z  Opening with "v110" libver arg r   rk   )rd   N)r   r   r   rd   rc   r'   )r   r!   r"   r"   r#   Útest_single_v110€  s    zTestNewLibver.test_single_v110r   ri   rj   zRequires HDF5 1.11.4 or laterc             C   s2   t | jƒ ddd�}| j|jd| jfƒ |jƒ  dS )z  Opening with "v112" libver arg r   rl   )rd   N)r   r   r   rd   rc   r'   )r   r!   r"   r"   r#   Útest_single_v112†  s    zTestNewLibver.test_single_v112c             C   s,   t | jƒ ddd�}| j|jdƒ |jƒ  dS )z Opening with two libver args r   rb   rs   )rd   N)rb   rs   )rb   rs   )r   r   r   rd   r'   )r   r!   r"   r"   r#   rf   Ž  s    zTestNewLibver.test_multiplec             C   s.   t | jƒ dƒ}| j|jd| jfƒ |jƒ  dS )z6 Omitting libver arg results in maximum compatibility r   rb   N)r   r   r   rd   rc   r'   )r   r!   r"   r"   r#   rg   ”  s    zTestNewLibver.test_none)r   ri   rj   )r5   r6   r7   r8   Úclassmethodrn   r$   re   rt   ru   r   ÚskipIfrE   ro   rp   rv   rf   rg   Ú__classcell__r"   r"   )rr   r#   rh   Y  s   	
rh   c               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚTestUserblockz;
        Feature: Files can be create with user blocks
    c          $   C   s¼   t | jƒ ddd�}z| j|jdƒ W d|jƒ  X t | jƒ ddd�}z| j|jdƒ W d|jƒ  X t | jƒ ddd�}z| j|jdƒ W d|jƒ  X | jtƒ� t | jƒ ddd� W dQ R X dS )zA User blocks created with w, w-, x and properties work correctly zw-i   )Úuserblock_sizeNÚxr   Znon)r   r   r   r{   r'   r   r0   )r   r!   r"   r"   r#   Útest_create_blocksize¡  s    


z#TestUserblock.test_create_blocksizec             C   sj   | j ƒ }t|dƒ}|jƒ  | jtƒ� tj|ddd�}W dQ R X | jtƒ� tj|ddd�}W dQ R X dS )z# User block only allowed for write r   r   i   )r{   Nzr+)r   r   r'   r   r0   rE   )r   r`   r!   r"   r"   r#   Útest_write_only¹  s    
zTestUserblock.test_write_onlyc             C   sr   | j ƒ }t|ddd�}|jƒ  | jtƒ� t|ddd�}W dQ R X t|ddd�}z| j|jdƒ W d|jƒ  X dS )zA User block size must match that of file when opening for append r   i   )r{   r+   i   N)r   r   r'   r   r0   r   r{   )r   r`   r!   r"   r"   r#   Útest_match_existingÅ  s    z!TestUserblock.test_match_existingc             C   sx   | j ƒ }| jtƒ� t|ddd�}W dQ R X | jtƒ� t|ddd�}W dQ R X | jtƒ� t|ddd�}W dQ R X dS )z7 User block size must be a power of 2 and at least 512 r   é€   )r{   Ni  iÿ  )r   r   r0   r   )r   r`   r!   r"   r"   r#   Útest_power_of_twoÔ  s    zTestUserblock.test_power_of_twoc             C   s¬   | j ƒ }t|ddd�}|jdƒ |jƒ  t|dƒ}z|jdd ƒ W d|jƒ  X tj|dƒ}zd|ksjt‚W d|jƒ  X t|d	ƒ}z| j|j	dƒdd ƒ W d|jƒ  X dS )
z= Test that writing to a user block does not destroy the file r   i   )r{   ZFoobarzr+bó   XNr   Úrb)
r   r   r&   r'   r   r   rE   r-   r   Úread)r   r`   r!   Zpyfiler"   r"   r#   Útest_write_blocká  s     




zTestUserblock.test_write_blockN)	r5   r6   r7   r8   r}   r~   r   r�   r…   r"   r"   r"   r#   rz   ›  s   rz   c               @   s   e Zd ZdZdd„ ZdS )ÚTestContextManagerzC
        Feature: File objects can be used as context managers
    c          	   C   s4   t | jƒ dƒ�}| j|ƒ W dQ R X | j| ƒ dS )z- File objects can be used in with statements r   N)r   r   r   )r   r(   r"   r"   r#   Útest_context_manager  s    z'TestContextManager.test_context_managerN)r5   r6   r7   r8   r‡   r"   r"   r"   r#   r†   ü  s   r†   z#Filesystem unicode support requiredc               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚTestUnicodez6
        Feature: Unicode filenames are supported
    c          
   C   sJ   | j tdƒd�}t|dƒ}z | j|j|ƒ | j|jtƒ W d|jƒ  X dS )zM Unicode filenames can be used, and retrieved properly via .filename
        i   )Úprefixr   N)r   Úchrr   r   ÚfilenameÚassertIsInstanceÚstrr'   )r   r    r(   r"   r"   r#   Útest_unicode  s    
zTestUnicode.test_unicodec          
   C   s<   | j tdƒd�}t|dƒ�}| jtjj|ƒƒ W dQ R X dS )zG Unicode filenames can be used, and seen correctly from python
        i   )r‰   r   N)r   rŠ   r   r   r   rQ   rR   )r   r    r!   r"   r"   r#   Ú#test_unicode_hdf5_python_consistent  s    z/TestUnicode.test_unicode_hdf5_python_consistentc             C   sT   | j tdƒd�}| jtƒ� t|dƒ W dQ R X | jtƒ� t|dƒ W dQ R X dS )zV
        Modes 'r' and 'r+' do not create files even when given unicode names
        i   )r‰   r   Nzr+)r   rŠ   r   r   r   )r   r    r"   r"   r#   Útest_nonexistent_file_unicode"  s
    z)TestUnicode.test_nonexistent_file_unicodeN)r5   r6   r7   r8   rŽ   r�   r�   r"   r"   r"   r#   rˆ   	  s   rˆ   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚTestFilePropertyzk
        Feature: A File object can be retrieved from any child object,
        via the .file property
    c          
   C   s<   | j ƒ }t|dƒ}z|d j}| j||ƒ W d|jƒ  X dS )z, File object can be retrieved from subgroup r   rD   N)r   r   rF   r   r'   )r   r    ÚhfileÚhfile2r"   r"   r#   Útest_property4  s    

zTestFileProperty.test_propertyc             C   sV   | j ƒ }t|dƒ}|jdƒ}|j}|d j}|jƒ  | j|ƒ | j|ƒ | j|ƒ dS )z8 All retrieved File objects are closed at the same time r   r%   rD   N)r   r   r&   rF   r'   r/   )r   r    r’   Úgrpr“   Zhfile3r"   r"   r#   Ú
test_close>  s    




zTestFileProperty.test_closec          
   C   s>   t | jƒ dƒ}z |jdƒ}| j|jj|jƒ W d|jƒ  X dS )z9 Retrieved File objects have a meaningful mode attribute r   r%   N)r   r   r&   r   rF   r   r'   )r   r’   r•   r"   r"   r#   Ú	test_modeJ  s
    
zTestFileProperty.test_modeN)r5   r6   r7   r8   r”   r–   r—   r"   r"   r"   r#   r‘   -  s   
r‘   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú	TestClosez*
        Feature: Files can be closed
    c             C   s.   t | jƒ dƒ}| j|ƒ |jƒ  | j|ƒ dS )z Close file via .close method r   N)r   r   r   r'   r/   )r   r(   r"   r"   r#   r–   Z  s    
zTestClose.test_closec          	   C   s:   t | jƒ dƒ}|jƒ  | jtƒ� |jdƒ W dQ R X dS )z0 Trying to modify closed file raises ValueError r   r%   N)r   r   r'   r   r0   r&   )r   r(   r"   r"   r#   Útest_closed_filea  s    zTestClose.test_closed_filec             C   s2   | j ƒ }tj|dƒ}|jdƒ |jƒ  |jƒ  d S )Nr   Útest)r   rE   r   r&   r'   )r   r    r!   r"   r"   r#   Ú"test_close_multiple_default_driverh  s
    
z,TestClose.test_close_multiple_default_driverN)r5   r6   r7   r8   r–   r™   r›   r"   r"   r"   r#   r˜   T  s   r˜   c               @   s   e Zd ZdZdd„ ZdS )Ú	TestFlushz+
        Feature: Files can be flushed
    c             C   s"   t | jƒ dƒ}|jƒ  |jƒ  dS )z Flush via .flush method r   N)r   r   Úflushr'   )r   r(   r"   r"   r#   Ú
test_flushu  s    zTestFlush.test_flushN)r5   r6   r7   r8   rž   r"   r"   r"   r#   rœ   o  s   rœ   c               @   s   e Zd ZdZdd„ ZdS )ÚTestReprzE
        Feature: File objects provide a helpful __repr__ string
    c             C   s:   t | jƒ dƒ}| jt|ƒtƒ |jƒ  | jt|ƒtƒ dS )z8 __repr__ behaves itself when files are open and closed r   N)r   r   rŒ   Úreprr�   r'   )r   r(   r"   r"   r#   Ú	test_repr‚  s    zTestRepr.test_reprN)r5   r6   r7   r8   r¡   r"   r"   r"   r#   rŸ   |  s   rŸ   c               @   s   e Zd ZdZdd„ ZdS )ÚTestFilenamezO
        Feature: The name of a File object can be retrieved via .filename
    c          
   C   sB   | j ƒ }t|dƒ}z | j|j|ƒ | j|jtƒ W d|jƒ  X dS )z, .filename behaves properly for string data r   N)r   r   r   r‹   rŒ   r�   r'   )r   r    r(   r"   r"   r#   Útest_filename�  s    
zTestFilename.test_filenameN)r5   r6   r7   r8   r£   r"   r"   r"   r#   r¢   Š  s   r¢   c               @   s   e Zd ZdZdd„ ZdS )Ú!TestCloseInvalidatesOpenObjectIDszO
        Ensure that closing a file invalidates object IDs, as appropriate
    c             C   sÔ   t | jƒ dƒ�X}|jdƒ}| jt|jƒƒ | jt|jƒƒ |jƒ  | jt|jƒƒ | jt|jƒƒ W dQ R X t | jƒ dƒ�P}|jdƒ}| jt|jƒƒ | jt|jƒƒ | jt|jƒƒ | jt|jƒƒ W dQ R X 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   rG   Zg1rH   Zg2r"   r"   r#   r–   ¡  s    

z,TestCloseInvalidatesOpenObjectIDs.test_closeN)r5   r6   r7   r8   r–   r"   r"   r"   r#   r¤   ›  s   r¤   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestPathlibSupportz6
        Check that h5py doesn't break on pathlib
    c             C   s@   t ƒ �0}tj|ƒ}t|dƒ�}| jdƒ W dQ R X W dQ R X dS )z- Check that pathlib is accepted by h5py.File r   TN)r   ÚpathlibÚPathr   r   )r   r!   rQ   rH   r"   r"   r#   Útest_pathlib_accepted_file·  s    
z-TestPathlibSupport.test_pathlib_accepted_filec             C   sd   t ƒ �T}tj|ƒ}t|dƒ�}|j}W dQ R X t|dƒ�}|j}W dQ R X | j||ƒ W dQ R X dS )z1 Check that using pathlib does not affect naming r   N)r   r§   r¨   r   r‹   r   )r   r!   rQ   Zh5f1Zpathlib_nameZh5f2Znormal_namer"   r"   r#   Útest_pathlib_name_match¾  s    
z*TestPathlibSupport.test_pathlib_name_matchN)r5   r6   r7   r8   r©   rª   r"   r"   r"   r#   r¦   ²  s   r¦   c               @   s   e Zd ZdZdd„ ZdS )Ú
TestPicklez%Check that h5py.File can't be pickledc             C   s>   t | jƒ dƒ�&}| jtƒ� tj|ƒ W d Q R X W d Q R X d S )Nr   )r   r   r   rT   ÚpickleÚdumps)r   rG   r"   r"   r#   Útest_dump_errorË  s    zTestPickle.test_dump_errorN)r5   r6   r7   r8   r®   r"   r"   r"   r#   r«   É  s   r«   c               @   s<   e Zd Zdd„ Zejjejj	dk dd�dd	„ ƒZ
d
d„ ZdS )ÚTestMPIc          	   C   sD   ddl m} t|dd|jd��}|s(t‚|jdks6t‚W dQ R X dS )z MPIO driver and options r   )ÚMPIr   Úmpio)rL   ÚcommN)Úmpi4pyr°   r   Ú
COMM_WORLDr-   rL   )r   Úmpi_file_namer°   r!   r"   r"   r#   Ú	test_mpioÕ  s    zTestMPI.test_mpior   é   é	   z5mpio atomic file operations were added in HDF5 1.8.9+)Úreasonc          	   C   sJ   ddl m} t|dd|jd��"}|j s,t‚d|_|js<t‚W dQ R X dS )z$ Enable atomic mode for MPIO driver r   )r°   r   r±   )rL   r²   TN)r³   r°   r   r´   Zatomicr-   )r   rµ   r°   r!   r"   r"   r#   Útest_mpi_atomicÝ  s
    zTestMPI.test_mpi_atomicc             C   s<   ddl m} t|dd|jd�}|jdƒ |jƒ  |jƒ  dS )z MPIO driver and options r   )r°   r   r±   )rL   r²   rš   N)r³   r°   r   r´   r&   r'   )r   rµ   r°   r!   r"   r"   r#   Útest_close_multiple_mpio_driverè  s
    
z'TestMPI.test_close_multiple_mpio_driverN)r   r·   r¸   )r5   r6   r7   r¶   r   ÚmarkZskipifrE   ro   rp   rº   r»   r"   r"   r"   r#   r¯   Ó  s   
r¯   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestSWMRModez=
        Feature: Create file that switches on SWMR mode
    c             C   sv   | j ƒ }t|ddd�}|jdƒ}|j|jj  ko8dkn  sBt‚d|_|j|jj  ko`dkn  sjt‚|jƒ  d S )Nr   rc   )rd   r%   zr+T)r   r   r&   r   rF   r-   Ú	swmr_moder'   )r   r    r(   Úgr"   r"   r#   Útest_file_mode_generalizesú  s    
""z'TestSWMRMode.test_file_mode_generalizesc             C   sv   | j ƒ }t|ddd�}|jdƒ}|j|jj  ko8dkn  sBt‚d|_|j|jj  ko`dkn  sjt‚|jƒ  d S )Nr   rc   )rd   r%   FT)r   r   r&   r¾   rF   r-   r'   )r   r    r(   r¿   r"   r"   r#   Útest_swmr_mode_consistency  s    
""z'TestSWMRMode.test_swmr_mode_consistencyN)r5   r6   r7   r8   rÀ   rÁ   r"   r"   r"   r#   r½   ò  s   r½   )r   r9   r   )r   r9   r	   )r   r9   r	   )r   r9   r   ),r8   r   r   r   r¬   r[   Úsysr   Úcommonr   r   r   r   rE   r   Ú r
   r§   r   rx   ro   rp   r:   rB   rJ   r_   ra   rh   rz   r†   rˆ   r‘   r˜   rœ   rŸ   r¢   r¤   r¦   r«   r¼   ZmpiÚobjectr¯   r½   r"   r"   r"   r#   Ú<module>   sP   l%+[ @a#'
