σ
\c           @@  sή   d  d l  m Z d  d l Z d  d l Z d d l m Z m Z e j e j	 j
 d k  d  d	 e f d
     Y Z e j e j	 j
 d k d  d e f d     Y Z e j e j	 j
 d k d  d e f d     Y Z d S(   i    (   t   absolute_importNi   (   t   utt   TestCasei   i	   i²   s6   SWMR is available. Skipping backwards compatible testst   TestSwmrNotAvailablec           B@  s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   sέ    Test backwards compatibility behaviour when using SWMR functions with
    an older version of HDF5 which does not have this feature available.
    Skip this test if SWMR features *are* available in the HDF5 library.
    c         C@  sV   t  j |   t j d  j d  |  _ |  j j d d d d d d |  j |  _	 d  S(   Ni   t   ft   datat   chunkst   maxshape(   i   (   N(
   R   t   setUpt   npt   aranget   astypeR   R   t   create_datasett   Nonet   dset(   t   self(    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyR      s    c      	   C@  sN   |  j  j } |  j  j   |  j t    t j | d d t |  _  Wd  QXd  S(   Nt   rt   swmr(   R   t   filenamet   closet   assertRaisest
   ValueErrort   h5pyt   Filet   True(   R   t   fname(    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_open_swmr_raises   s    c         C@  s'   |  j  t   |  j j   Wd QXd S(   sd    If the SWMR feature is not available then Dataset.refresh() should throw an AttributeError
        N(   R   t   AttributeErrorR   t   refresh(   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_refresh_raises   s    c         C@  s'   |  j  t   |  j j   Wd QXd S(   si    If the SWMR feature is not available the Dataset.flush() should
        throw an AttributeError
        N(   R   R   R   t   flush(   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_flush_raises"   s    c         C@  s$   |  j  t   |  j j Wd  QXd  S(   N(   R   R   R   t	   swmr_mode(   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_swmr_mode_raises)   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R!   (    (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyR   	   s   				s   SWMR requires HDF5 >= 1.9.178t   TestDatasetSwmrReadc           B@  sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s|    Testing SWMR functions when reading a dataset.
    Skip this test if the HDF5 library does not have the SWMR features.
    c         C@  s   t  j |   t j d  j d  |  _ |  j j d d d d d	 d |  j |  _	 |  j j
 } |  j j   t j | d d t |  _ |  j d |  _	 d  S(
   Ni   R   R   R   R   R   R   (   i   (   N(   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   (   R   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyR   3   s    *c         C@  s   |  j  |  j j  d S(   s/    Verify that the file is initially in SWMR modeN(   t
   assertTrueR   R    (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_initial_swmr_mode_on=   s    c         C@  s   |  j  |  j |  j  d  S(   N(   t   assertArrayEqualR   R   (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_read_dataA   s    c         C@  s   |  j  j   d  S(   N(   R   R   (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_refreshD   s    c         C@  s9   |  j  t   t |  j _ Wd QX|  j |  j j  d S(   s    Verify when reading a file cannot be forcibly switched to swmr mode.
        When reading with SWMR the file must be opened with swmr=True.N(   R   R   R   R   R    R&   (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_force_swmr_mode_on_raisesG   s    c         C@  s9   |  j  t   t |  j _ Wd QX|  j |  j j  d S(   s    Switching SWMR write mode off is only possible by closing the file.
        Attempts to forcibly switch off the SWMR mode should raise a ValueError.
        N(   R   R   t   FalseR   R    R&   (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_force_swmr_mode_off_raisesN   s    (	   R"   R#   R$   R   R'   R)   R*   R+   R-   (    (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyR%   -   s   	
				t   TestDatasetSwmrWritec           B@  sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s|    Testing SWMR functions when reading a dataset.
    Skip this test if the HDF5 library does not have the SWMR features.
    c      
   C@  ss   t  j |  j   d d d |  _ t j d  j d  |  _ |  j j d d d d	 |  j j	 d
 d d d |  _ d S(   sa    First setup a file with a small chunked and empty dataset.
        No data written yet.
        t   wt   libvert   latesti   R   R   t   shapei    t   dtypeR   i   R   N(   i    (   i   (   N(   R   R   t   mktempR   R	   R
   R   R   R   R3   R   R   (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyR   \   s    !c         C@  s   |  j  |  j j  d S(   s3    Verify that the file is not initially in SWMR modeN(   t   assertFalseR   R    (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_initial_swmr_mode_offi   s    c         C@  s#   t  |  j _ |  j |  j j  d S(   s     Switch to SWMR mode and verify N(   R   R   R    R&   (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_switch_swmr_mode_onm   s    c         C@  sX   t  |  j _ |  j |  j j  |  j t   t |  j _ Wd QX|  j |  j j  d S(   s    Switching SWMR write mode off is only possible by closing the file.
        Attempts to forcibly switch off the SWMR mode should raise a ValueError.
        N(   R   R   R    R&   R   R   R,   (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt    test_switch_swmr_mode_off_raisesr   s
    c         C@  sv   t  |  j _ |  j |  j j  |  j j |  j j  |  j |  j (|  j j   |  j j	   |  j
 |  j |  j  d S(   s)    Extend and flush a SWMR dataset
        N(   R   R   R    R&   R   t   resizeR   R2   R   R   R(   (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_extend_dset|   s    c         C@  sη   t  |  j _ |  j |  j j  |  j j d  |  j |  j d )|  j j   |  j j   |  j	 |  j |  j  |  j j d  |  j |  j d )|  j j   |  j j   |  j	 |  j d d !|  j  |  j	 |  j d d !|  j  d  S(   Ni   i    i   (   i   (   i   (
   R   R   R    R&   R   R9   R   R   R   R(   (   R   (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   test_extend_dset_multiple   s    (	   R"   R#   R$   R   R6   R7   R8   R:   R;   (    (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyR.   V   s   				
	(   i   i	   i²   (   i   i	   i²   (   i   i	   i²   (   t
   __future__R    t   numpyR	   R   t   commonR   R   t
   skipUnlesst   versiont   hdf5_version_tupleR   R%   R.   (    (    (    s>   lib/python2.7/site-packages/h5py/tests/hl/test_dataset_swmr.pyt   <module>   s   #(